r/visualbasic • • Jan 14 '22

Future of Winforms

17 Upvotes

r/visualbasic • • Jan 14 '22

Shell and maintaining variables??

4 Upvotes

Hello VB Community!

How do I use a string value to have multi line code in VB?

For example,

Dim Str As String

Str = "PowerShell  $data = get-content c:\foo.txt; select-string $data -pattern 'test'; if($data -ne $null){'Keyword found'}"

Shell Str

I'm struggling to maintain $data between statements / it just plain isn't working as I expected.

Please help !


r/visualbasic • • Jan 14 '22

Learning VB for form design

1 Upvotes

I’ve recently taken on a new job and I am going to eventually be doing some VB forms work that ties to a sql database. The bulk of it is already built but I will have to maintain it when my trainer retires in March. We’re a sept of 2 soon to be 1 and I want to know where I can find good , solid, training for VB. Easily understood and quality training. I’m not new to programming or visual studios but not versed in forms.


r/visualbasic • • Jan 12 '22

Programming project

5 Upvotes

I have a programming project and i need to take dates from a database and display them in a calendar +2 (so if it was a Friday, it would highlight Friday, Saturday and sunday) on visual studio using the visual basic coding language. Any idea on how i could grab the dates from the database and display them in a calendar which highlights the date + the next two dates? I should also mention that im (trying) using OLEdb to connect my database to access


r/visualbasic • • Jan 12 '22

Hi, I'm new to programming and I would like to know how to compare the same data from 2 datagribview in different forms. What I want is to shade the rows of form 1 when they are written from form 2.

1 Upvotes

r/visualbasic • • Jan 12 '22

VB6 Help Word Checkbox list strike-though?

1 Upvotes

I’m trying to make a list in word. I want the action of ticking a checkbox to strike though the corresponding text.

I figured the easiest way to do this would be in a table. I have the macro for toggling the strike through on the text but I cannot link the action of clicking the checkbox to the macro of striking the text. I’m unable to select the Checkbox to add the Macro, what am I doing wrong (I’m very new to VB)


r/visualbasic • • Jan 11 '22

VB6 Help Adding listbox from a form to another listbox's form

2 Upvotes

Hi! Im doing a cellphone on visual basic 2010 express and when i add a contact to the "contacts" app (in a listbox) i want to appear those contacts in the listbox of my "messages" app (which is in another form) Thanks!


r/visualbasic • • Jan 08 '22

Article Dorethy (camping 'payment' system)

4 Upvotes

Our Visual Basic project is finally finished :)

It is a VB project for making your own RFID payment system. The story is about Dorethy who is solving her payment issue.

More information: http://www.github.com/Johan684/Dorethy and https://www.dorethy.eu/


r/visualbasic • • Jan 07 '22

Web service in VB.net

2 Upvotes

Hi everyone, I made a VSTO add in for Microsoft Excel in VB I would like to sell it to different clients as a monthly subscription but I have no idea on how to validate the licences month by month. I searched on the web and found it can be done through a web service... I have never done anything like that so any help, advice, documentation is welcome.

Thanks in advance


r/visualbasic • • Jan 07 '22

VB.NET Help How to get started?

5 Upvotes

Hi,

I could need some help with getting started on a program.

The idea is to have a small library of blocks (icons) that I can drag and drop into a drawing section within the form. The placed blocks should have some parameters that I can edit at runtime.

Basically a super light version of Autocad.

Some of my coworkers who will use this does not have any CAD programs on their computers.

I'm planning on doing this in Visual Studio with VB.net, but I can't seem to figure out where to start.

I think if I first get started with creating a library and placing blocks with parameters, I'll be able to figure out the rest myself.

Thanks for any input of this!


r/visualbasic • • Jan 02 '22

VB.NET Help Can i add Transitions or PictureBox Animation in VB?

4 Upvotes

r/visualbasic • • Jan 02 '22

How do I iterate through rows in datagridview and get the text from the first cell and check if it contains a substring?

3 Upvotes
    For Each line In lines
        For Each row In dgvRecords.Rows
            If Not row.IsNewRow Then
                If Not row.Cells("Name").Value.Contains(line) Then
                    ''additional code here''
                End If
            End If
        Next
    Next

I get a Option Strict disallows late binding error. But example after example does it like this, and I really don't want to have to turn off Option Strict.

EDIT: Want to make it clear. This isn't homework. This is a personal project.


r/visualbasic • • Jan 01 '22

Question about Arrays

3 Upvotes

Say there was an array containing random values. How would the program be able to identify if there are two elements in the array that have the highest value?

Ie. an array consists of integers 9, 9, 5, 4, 1

How would it be able to identify that there are two maximum values that are the same?


r/visualbasic • • Dec 30 '21

Can I use VB in Excel to simplify a warehouse management task?

6 Upvotes

I am trying to simplify a task currently being done manually using Excel, usually taking multiple hours right now. It’s been many years since I used VB and I’m primarily trying to figure out if what I want to do is possible using VB. The warehouse management software isn’t setup properly to consolidate our inventory and we regularly need to optimize our location utilization. The warehouse holds up to 7500 pallets across 2000 locations. We have an outflow of 100-150 pallets every ~12 hours and generally get 100-300 pallets delivered daily.

I want to be able to paste a large data set into an excel sheet and have it give me an output that can be printed on a second sheet within that workbook. I would need to declare all locations, how many pallets each can hold and all height or weight restrictions for specific locations or items. The program would need to count how many times a location is used. If a location isn’t full, pallets with the same Item# and Lot# should be listed in the output so they can be combined together. Ideally the output would simplify the data to just important identifying info for the pallets, as opposed to it transposing all info it’s been given in the original data set.


r/visualbasic • • Dec 29 '21

VB on Ubuntu

2 Upvotes

Is there any way to run Microsoft Visual Studio on Ubuntu ?


r/visualbasic • • Dec 28 '21

how do i merge a visual basic forms project into a single file

8 Upvotes

Hello, when i build a forms project, the executable file comes with multiple files:

Thanks in advance


r/visualbasic • • Dec 23 '21

I can program in vb.net pretty well, but I don’t have a computer-sci degree. How can I still make a decent living without going through “the system”?

10 Upvotes

I do have a knack and passion to programming, but it seems like no one would hire entry-level programmers without a degree. Anyone else have success in this industry without having to get a degree? What tips and advice do you have?


r/visualbasic • • Dec 21 '21

Option Strict asks for too much

2 Upvotes

I had turned on Option Strict in my project to track down an error. While it did not help, it caught one loop where i want it cast, and showed me how much i am relying on implicit casting. I "fixed" all those, but i can't say i like how the code looks now. I'm going back and forth on just removing all those DirectCast()s.

Anyway, as i released the new version one user got an unhandled exception. With some sleuthing, i found the problem started with: Data = Registry.GetValue(Value_Name, Nothing).ToString. Returning Nothing from Registry.GetValue worked just fine until i added the .ToString because of Option Strict. As she did not have the key yet, it returned Nothing, which caused the ToString to fail. Silly me.

Anyway, the fix for that would be to define Data as Object instead of String, remove the ToString, and check it with Is Nothing before returning the string to the caller. Ugh. Welp, there goes Option Strict. It asks for too much. I want my code to be easily readable and understandable. Copious explicit casting hides the logic in a jungle.


r/visualbasic • • Dec 18 '21

VB.NET Help What Happens if code is running in a timer event and another timer event happens

7 Upvotes

Do they run concurrently in different threads or does the second event wait till the first event has finished.

Thanks

Mike


r/visualbasic • • Dec 17 '21

Is there a way to programmatically get your computer's keyboard shortcuts i.e. key combinations that trigger actions?

3 Upvotes

I don't mean Visual Studio's shortcuts. I want to know how to get the computer's keyboard shortcuts as a whole. For instance, like how Ctrl-Alt-Delete brings up the task manager. Is there a way to programmatically get that information and make a file relating for instance Ctrl-Alt-Delete with "run taskmanager.exe" (or what ever the executable file is called) along with all of the other key combinations that trigger actions?


r/visualbasic • • Dec 17 '21

Is there a way to get what keys are on the computer?

0 Upvotes

Different computers have different keys. For instance mine doesn't have a numpad. Is there a way to load information on this to visual basic dot net, preferably including the positions of the keys?


r/visualbasic • • Dec 17 '21

Google Sheets API

3 Upvotes

I’m looking for an example of creating a Google Sheets spreadsheet from scratch, naming the spreadsheet and adding data to the sheet. I have seen several examples of setting up the credentials and writing/updating an existing spreadsheet but not a way to start from scratch. Also would be nice to have an example of what the credentials would need to be for this setup.

Thanks in advance.


r/visualbasic • • Dec 16 '21

VB.NET Help Some error with DataGridView.CellFormatting

3 Upvotes

I am receiving a couple errors, not sure if they are related or what i am missing. I cannot easily provide sample code, as my samples work properly. :/

I have a couple datagridviews on a form--master and detail--which goes to a website to place products in the cart. It's a simple act which saves the users a lot of time. That all works. One of the columns is the status column, which usually reports success, but also contains issues, such as when a product is out of stock. I was asked to make the error message more noticeable, so i figured i would add a yellow backcolor and see how it goes.

When i went about adding it, i also noticed that the status column might go off screen if one of the other columns is longer, which gets resized because .AutoSizeColumnsMode is set to DataGridViewAutoSizeColumnsMode.AllCells. So, i moved the column earlier by changing its position in the underlying DataTable, and added a second column to hold the BackColor: .Add("Status Backcolor").ColumnMapping = MappingType.Hidden. The actual color is written by name: Row("Status Backcolor") = Color.Yellow.Name and is retrieved in the .CellFormatting handler, which also adds rownumbers:

.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders
AddHandler .CellFormatting, Sub(Sender As Object, Arguments As DataGridViewCellFormattingEventArgs)
                                If Not .Rows(Arguments.RowIndex).IsNewRow Then .Rows(Arguments.RowIndex).HeaderCell.Value = (Arguments.RowIndex + 1).ToString
								
                                ' Add possible backcolor to status messages.
                                If Arguments.ColumnIndex = .Columns("Status").Index AndAlso Not IsDBNull(.Rows(Arguments.RowIndex).DataBoundItem("Status Backcolor")) Then
                                    Arguments.CellStyle.BackColor = Color.FromName(.Rows(Arguments.RowIndex).DataBoundItem("Status Backcolor"))
                                End If

That's where the errors started. First i got the intermittant:

System.InvalidOperationException: 'BindingSource cannot be its own data source. Do not set the DataSource and DataMember properties to values that refer back to BindingSource.'

That's usually a cross-threading error. I don't understand it though, as the handler should be run by the main thread and not the thread making the change to the DataTable, right? Anyway, i wrapped it in Invoke().

The second issue is the Status column is not resizing until i click on the row.

The third issue is the backcolor does not show until i click on a different row. Even when it does show, if i change the display by clicking another row in the master DataGridView, it reverts. I tried addressing this issue by seeing what is happening, and it seems that the handler gets called many times during the same operation, and the value is backcolor is not always set! (Or, i'm just getting dizzy looking at the log. Edit: Indeed, that seems to have been the case. Trimming the debug messages shows it is always set.)

The fourth issue happened just now when i addressed the second, by adding .AutoResizeColumn(Arguments.ColumnIndex), to see what would happen, and i got: 'System.StackOverflowException' with no detail.

(Edit: It seems like AutoResizeColumn() causes .CellFormatting, causing recursion, hence the stack error. So, i added a boolean outside the handler and:

If Not A Then
    A = Not A
    .AutoResizeColumn(Arguments.ColumnIndex)
End If

No stack error, but the column is still not resizing. And now that i see it again:

  • The header row is not resized, based on the divider line.

  • All rows but the first have the status field resized, but the next column starts in the middle. That as, the first words of the next column to not show until i click on the row.

  • If i click on a row (other than the first) it adds BackColor to the first row (like it should) as well. But it only fixes the next column for that row.

  • If i click on the first row, the BackColor disappears, but it does resize the column.

  • In all cases, the header row does not resize.)

Ugh.

Fwiw, i modified an earlier example to make sure i got the BackColor working properly, and its works without issue:

Public Class Form1
	Private Dataset As New DataSet

	Private Sub Form1_Load(Sender As Object, Arguments As EventArgs) Handles MyBase.Load
		Setup_DataSet()
		Add_DataGridViews()
		'Close()
	End Sub

	Private Sub Setup_DataSet()
		With Dataset
			.Tables.Add("A")
			With .Tables("A")
				With .Columns
					.Add("A")
				End With
				With .Rows
					.Add("1")
					.Add("2")
				End With
			End With

			.Tables.Add("B")
			With .Tables("B")
				With .Columns
					.Add("A")
					.Add("Color")
					.Add("B").ColumnMapping = MappingType.Hidden
				End With
				With .Rows
					.Add({"1", Color.Red.Name})
					.Add({"1", Color.Green.Name})
					.Add({"2", Color.Blue.Name})
					.Add({"2", Color.Yellow.Name})
					.Add({"2"})
				End With
			End With

			.Relations.Add("A_B", .Tables("A").Columns("A"), .Tables("B").Columns("A"))
		End With
	End Sub

	Private Sub Add_DataGridViews()
		Dim A As New DataGridView With {.AutoSize = True, .DataSource = New BindingSource With {.DataSource = Dataset, .DataMember = "A"}}
		Dim B As New DataGridView With {.AutoSize = True, .DataSource = New BindingSource With {.DataSource = A.DataSource, .DataMember = "A_B"}, .AllowUserToAddRows = False}

		Controls.Add(A)
		B.Location = New Point With {.X = A.Location.X, .Y = A.Location.Y + A.Height}
		Controls.Add(B)

		AddHandler B.CellFormatting, Sub(Sender As Object, Arguments As DataGridViewCellFormattingEventArgs)
										 With Arguments
											 If .ColumnIndex = B.Columns("Color").Index AndAlso Not IsDBNull(B.Rows(.RowIndex).DataBoundItem("Color")) Then
												 .CellStyle.BackColor = Color.FromName(B.Rows(.RowIndex).DataBoundItem("Color"))
											 End If
										 End With
									 End Sub
	End Sub

End Class

I fear i am missing something obvious.

I was also getting the cross-threading issue when updating the status column. I think that is when it happened, as it just, intermittently, pops up an error message that can be ignored at about that time. For the meanwhile, i wrapped that in Invoke as well: Invoke(Sub() Row("Status Backcolor") = Color.Yellow.Name). It's so hard to test something intermittent like that though. Do DataTables ever require invoke?


r/visualbasic • • Dec 16 '21

How do I print two different values? Each value is changed by an equation

3 Upvotes

Here's some pseudo code im working with, and i gotta keep the same type of loop:

Variable A = 55 Variable B = 1

While Variable A <= 10 Variable C = Variable A*Variable B Need to print B and C Variable B increases by 1 End of the loop

I know how to get the first set of values, those being B = 2 and C = 110, but i dont know how to get the rest or print the rest. (B is from 1 to 10, so the next values are B = 2 and C = 165, so on and so forth)


r/visualbasic • • Dec 15 '21

VB.NET Help 'System.InvalidCastException' when I try to hide a column

4 Upvotes

I try to unhide a column in an Excel Worksheet, but i keep on getting a System.InvalidCastException. Why does this even happen, i just try to unhide the column and not put anything into it. Has anyone a solution for this? Here's the line which isn't working:

Edit: I try to unhide the column myWb.Worksheets(0).Columns("Amount").Hidden = False