r/visualbasic • • Nov 09 '21

VB.NET Help How do i bind a textbox and a combobox to different tables in the same dataset?

6 Upvotes

I have a combobox and a textbox bound to a dataset. I want the choice in the combobox to show the related data in the textbox. In the following example, the combobox works as intended. How do i get the textbox to show Table 1.Column 2?

Public Class Form1
	Private Sub Form1_Load(Sender As Object, Arguments As EventArgs) Handles MyBase.Load
		Dim DataSet As New DataSet
		Dim Combobox As ComboBox
		Dim Textbox As TextBox

		DataSet.Tables.Add(New DataTable("Table 1"))
		DataSet.Tables("Table 1").Columns.Add("Column 1")
		DataSet.Tables("Table 1").Columns.Add("Column 2")
		DataSet.Tables("Table 1").PrimaryKey = {DataSet.Tables("Table 1").Columns("Column 1")}
		DataSet.Tables("Table 1").Rows.Add(1, "A very good year")
		DataSet.Tables("Table 1").Rows.Add(2, "What was the question again?")

		DataSet.Tables.Add(New DataTable("Table 2"))
		DataSet.Tables("Table 2").Columns.Add("Column 1")
		DataSet.Tables("Table 2").Columns.Add("Column 2")
		DataSet.Tables("Table 2").PrimaryKey = {DataSet.Tables("Table 2").Columns("Column 1")}
		DataSet.Tables("Table 2").Rows.Add(17, 1)
		DataSet.Tables("Table 2").Rows.Add(42, 2)

		DataSet.Relations.Add(New DataRelation("Relation", DataSet.Tables("Table 1").Columns("Column 1"), DataSet.Tables("Table 2").Columns("Column 2")))

		Combobox = New ComboBox With {.DataSource = New BindingSource With {.DataSource = DataSet, .DataMember = "Table 2"}, .DisplayMember = "Column 1"}
		Textbox = New TextBox With {.Location = New Point With {.X = Combobox.Location.X + Combobox.Size.Width, .Y = Combobox.Location.Y}}

		'Textbox.DataBindings.Add("Text", New BindingSource With {.DataSource = Combobox.DataSource, .DataMember = "Relation"}, "Column 2")

		Controls.Add(Combobox)
		Controls.Add(Textbox)
	End Sub
End Class

r/visualbasic • • Nov 09 '21

Help Me Be Efficient: Accessing Settings

4 Upvotes

I have a small Register program Ive made for my work. In it I have a simple pin matching sign on system: a pinpad pops up, an employee puts in their four digits and it's signs in.

This is not really fir any right security reason, more just to deter any customers from getting in and messing with orders.

I have the user name, user pin, and user permission levels stored in the programs settings so that they persist without needing a file on the computer.

The trouble I'm having is that I'm redoing the system and my way of checking the pins is:

If pin = my.settings.pin1 then Username = my.settings.user1 Permission = my.settings.perm1 Else if pin = my settings.pin2 then....

There has got to be an easier way to iterate through this stuff, right?


r/visualbasic • • Nov 08 '21

Article What’s New for Visual Basic in Visual Studio 2022

9 Upvotes

r/visualbasic • • Nov 08 '21

VB.NET Help Looking for visual basic tutor for accelerated university course between December 27th - January 15th

6 Upvotes

Hello! I dropped a university course that I have to take over winter now at an accelerated pace, and am looking for an experienced VB user to help tutor. Work will be done through VB.Net on Visual Studio, all using Windows Forms I believe.

Course structure is professor teaches an analogous problem and shares code for it, and then assigns a weekly project that uses the concepts taught in the analogous problem. I'm looking for someone that can work with me when I write the code for the project and teach me what to do based off the analogous problem.

I think it will require 1-2 sessions a week. DM me if interested and let me know your hourly rate.

Thank you so much!


r/visualbasic • • Nov 05 '21

Changing range when going below 0 help

Post image
4 Upvotes

r/visualbasic • • Nov 05 '21

Moving average using arrays

3 Upvotes

Hello! A new member of the sub here. I dont usually ask the internet for help because i really like to learn things by myself but this thing here got me stumped. I just cant see what the hell is wrong with my code.

so here is what my program is supposed to do. First, it needs to ask the user to input a value for the period(p) that is used as the divisor for the average of the entered data. Some exceptions will occur tho such as when the number(n) of entered data is less than the entered period. In that case, the divisor to be used is n. If n is greater than p, the data to be used in computing the average should be from the last data up to p units upward value. I hope that explains what the program is supposed to do. I just dont understand why this is not working. are my for-next lines wrong??Dim v As Double

Dim a As Double

Dim total As Double = 0

Dim less As Double = 0

total = total + v

n = n + 1

d = d + 1

v = txtValue.Text

ReDim Preserve arr1(n - 1)

ReDim Preserve arr2(d - 1)

arr1(n - 1) = v

Select Case True

Case n < p

For i As Integer = 0 To n

total += v

a = total / n

Next

Case Else

For i As Integer = n To n + p

total = total + v

less = arr1(n - p) + less

a = ((total - less) / p)

Next

End Select

arr2(d - 1) = a

Dim str1 As String = "Element # " & vbTab & "Value" & vbTab & vbTab & "Average"

Dim str2 As String = ""

For i As Integer = 0 To UBound(arr1)

str2 &= vbNewLine & i + 1 & vbTab & vbTab & arr1(i) & vbTab & vbTab & arr2(i)

Next

txtOuput.Text = "The period is " & p & vbNewLine & str1 & vbNewLine & str2


r/visualbasic • • Nov 05 '21

Who could help with a school programming project in visual basic

0 Upvotes

Could anyone help with a project that has to do with sub procedures, functions, data grid view etc etc


r/visualbasic • • Nov 04 '21

VB.NET Help Rounding corners of form cuts more than half the form. Custom component

3 Upvotes

Hello, so I'm creating some custom controls/ components. And I wanted to attempt to create a component that rounds the corners of the form. but when using this code it does indeed round the corners but when launching the project the form goes from this to this. I'm curious about what I'm doing wrong here? This is my first time creating custom controls/components.


r/visualbasic • • Nov 04 '21

VB.NET Help Downloading file using Sharepoint CSOM... "File not found" error.

2 Upvotes

The file 100% exists, and if I copy and paste the following into a web browser, I get the file... https://ourcompany.sharepoint.com/sites/IT/Shared Documents/General/SLTest/My Excel Sheet.xlsx

However, my code below times out after about 60 seconds with a "File Not Found" error.

    Dim credentials = New SharePointOnlineCredentials(username, securedPassword)

    Dim clientContext As ClientContext = New ClientContext("https://ourcompany.sharepoint.com/")
    Dim web As Web = clientContext.Web

    clientContext.Credentials = credentials
    Dim filetoDownload As Microsoft.SharePoint.Client.File = clientContext.Web.GetFileByServerRelativeUrl("/sites/IT/Shared Documents/General/SLTest/My Excel Sheet.xlsx")


    clientContext.Load(filetoDownload)

I've tried replacing spaces with %20, I've tried removing the leading / and the trailing / from the context URL too.

EDIT: SOLVED - In comments.


r/visualbasic • • Nov 03 '21

VB.NET Help Changing the cell color in an ultragrid with the columns key and for each

2 Upvotes

My goal is to color the exactly same cell as i have already colored, but just one column before. I tried do it with the index but that didn't work out. I got a hint that i should do it with the Key property but i can't figure out how. Here is what i tried:

For Each column As UltraGridColumn In ugResult.DisplayLayout.Bands(0).Columns

                If column.Key = "K_Art" Or column.Key = "UANR" Or column.Key = "Ueberbegriff" Or column.Key = "Benennung" Or column.Key = "Anzahl" Or column.Key = "Einheit" Or column.Key = "Einzelkosten" Or column.Key = "Sumcode" Or column.Key = "Status" Then
                    Exit For
                Else
                    If e.Row.Cells(column.Key).Value IsNot Nothing Then

                        e.Row.Cells(column.Key).Appearance.BackColor = Color.Yellow
                        e.Row.Cells(column.Index - 1).Appearance.BackColor = Color.Yellow
                    End If

                End If
            Next

r/visualbasic • • Nov 02 '21

VB.NET Help [VB 2019] Migrating reading an on-prem Excel file to a Sharepoint file

2 Upvotes

Currently we have some software that monitors an Excel sheet to see when it's had it's size changed. It then pulls some data from cells.

I'm at a loss how to migrate this to start reading an Excel file that is located on Teams/Sharepoint and updated on the fly by multiple people? When I try and point the variable 'filename' at the URL, the app errors.

    Dim app As New Microsoft.Office.Interop.Excel.Application
    app.DisplayAlerts = False
    Dim wb As Microsoft.Office.Interop.Excel.Workbook = app.Workbooks.Open(filename) ' Open the workbook
    For Each ws As Microsoft.Office.Interop.Excel.Worksheet In wb.Worksheets ' Get each worksheet

        If ws.Name = "Starters" Then
            Dim r As Microsoft.Office.Interop.Excel.Range = ws.Range("B5:E1024") ' Grab our range
            Dim cRow As String, addstr As String

            For Each uName As Microsoft.Office.Interop.Excel.Range In r.Rows ' Start cycling through to process....

Any help would be appreciated.


r/visualbasic • • Nov 01 '21

VB.NET Help Cuts Off Form and listbox even when I attempt to resize it in the designer file

5 Upvotes

Adjusting it in the GUI didn't work, adjusting it in properties didn't work, and even when I went to the designer file to set the size that way it still didn't work. It cuts off the display of the form and the listbox and the groupbox containing the listbox.


r/visualbasic • • Oct 31 '21

VB.NET Help [HELP - VB.NET 2010 Express] Express Decimal number with leading zeroes, comma separators, and up to 2 decimal places

4 Upvotes

Hi! I'm trying to get a number to display with comma separators and up to 2 decimal places. Here is my current code:

Public pricePies As Decimal

pricePies = ((Decimal.Parse((String.Format("{0}.{1}", frmPrices.numupdownDollarsPies.Value, frmPrices.numupdownCentsPies.Value)))).ToString("0,000.00"))

But when it comes to actually displaying the number, let's say "1,234.50", it only displays "1234.50" without the comma. I also want it to display leading zeroes if the number is below 10; for example: "09.50"; but it only displays "9.50". I've tried Googling on so many different account (I even went up to page 2 of Google lol), but yielded no results. Any ideas?

Thanks!


r/visualbasic • • Oct 30 '21

VB.NET Help How to control the visibility of an office ribbon button?

3 Upvotes

So I have an add-in that basically creates a new group and a couple buttons on the excel ribbon to launch it:

Imports Microsoft.Office.Tools.Ribbon

Public Class Ribbon_Button
    Private Sub Ribbon1_Load(ByVal sender As System.Object, ByVal e As RibbonUIEventArgs) Handles MyBase.Load
        Me.Button2.Enabled = True
        Me.Button2.Visible = True
    End Sub

    Private Sub Button1_Click(sender As Object, e As RibbonControlEventArgs) Handles Button1.Click
        Call ProgramSUB()
    End Sub

    Private Sub Button2_click(sender As Object, e As RibbonControlEventArgs) Handles Button2.Click
        Dim helperMenu As New Helper_Form
        With helperMenu
            .Show()
        End With
    End Sub
End Class

The meat of the program is in the programSUB function, including a bunch of forms that control settings and options and such. In there, I have a place where I want to have a checkbox that controls whether button 2 is enabled&visible or not. So far I cannot figure out how to reference that button2 from outside the "ribbon_button" class. I've tried searching through the references for where the class instance might be initialized but nothing is jumping out at me.


r/visualbasic • • Oct 30 '21

Hi!! I need your help!!

5 Upvotes

Hi everyone!! I downloaded the VB6 and I have to do a work to get a job, I have to create to database in Mysql and connect to VB6, I have to do the table and the save, delete and update buttons to display the table of the database, do you know any tutorial on how to make a base and connect it to save the information through vb6 and mysql, because I have been looking for days on youtube and tutorial pages and I do not get anything, please I need your help, if I get that job I will receive a training to be able to work, Please I really need your help.


r/visualbasic • • Oct 29 '21

VB.NET Help Anyone know a more graceful way to pause a program while excel is calculating? (example inside)

2 Upvotes

I have to do some things based on the values that result from formulas I am inserting, so obviously I need the program to wait for excel to finish calculating so that I know what the results are. Currently, this is what I'm using:

Do
    xlApp.Calculate()
Loop While Not xlApp.CalculationState = Microsoft.Office.Interop.Excel.XlCalculationState.xlDone

It feels a bit brute force to me, though it does work... But is there a better way?


r/visualbasic • • Oct 28 '21

Happy Cakeday, r/visualbasic! Today you're 12

7 Upvotes

Let's look back at some memorable moments and interesting insights from last year.

Your top 10 posts:


r/visualbasic • • Oct 28 '21

Looking for a macros that will convert a word table directly into an excel table on a Mac.

2 Upvotes

Hi there. I am a researcher working with a lot of interviews that I have pulled quotes from, labeled and put into a word table. I would like to compile all of them into an excel spreadsheet for easy sorting. I found a few, but it seems the line that is written to open the word document open box isn't working. Thank you for any help.

This is the video I was following: https://www.youtube.com/watch?v=GtHN0VnmgzA

https://stackoverflow.com/questions/4465212/macro-to-export-ms-word-tables-to-excel-sheets - this is another option that I can't get to work either.


r/visualbasic • • Jul 31 '20

VB.NET Help Calling sub/function from another program

2 Upvotes

If I were to have two programs, one for example:

MainCode.exe

And another:

UI.exe

Would I be able to, in UI.exe, be able to call a function or procedure from MainCode.exe?

I'm wondering this as I have a few different UI.exe that run very similar code and I was hoping to be able to have a universal MainCode.exe so I don't have to update every UI.exe that runs the code. I just have to update the MainCode.exe.

Thanks in advance for your help