Displaying array items on vb.net listbox

I’m currently having a crash course on vb.net. I thought that it would be useful to know the basics of vb.net because we will be converting an existing system which was made through vb.net programming language.
In this short tutorial, I’m going to show you how you can loop through an array and place all the items inside a listbox or a combo box. The final output would look like this:


If you’re asking what are those names. I didn’t made them up, they are actually name of the characters from Patapon 3.

Declaring the array
First let’s declare the array. Let’s just declare it globally so that all the methods can access its value:

Dim names() As String = {"taterazay", "pyokorider",

"guardira", "piekron", "myamsar"}

Loop through the array
Then we iterate through the array contents using for loop. We did subtract 1 from the original array length because the call to the names.Length function will actually yield you 5. Which isn’t right because the count starts at 0 and ends with 4. Which totals to 5.

For d = 0 To names.Length - 1
   //populating combo box and list box code will go here

 Next d

Populating combo box and listbox
As you have seen from the screenshot above, the event that will populate the listbox and combo box will only happen if the button has been clicked:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        For d = 0 To names.Length - 1

        Next d
 End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s