• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

VB.NET Array Question

PornFlake

Limp Gawd
Joined
Feb 24, 2005
Messages
270
I have two arrays name() and age(). I am using a DO WHILE loop to populate the two arrays. After the arrays are populated I am using a combo box to select name() and need to pass the () on to the age variable but I am not sure how to do that.

When I select an item in the combo box I know the value selected is correct as I can pass the variable name into a message box and it displays the correct selection. If I select an item in the fifth position I need to select the corresponding age() of the same position.

The array is being populated by reading a .txt file that contains the name, age in sequential order.

Anyone?

-Funk
 
SelectedIndex returns the selected index in the collection, SelectedItem returns the selected object in the collection. You obviously can't safely cast an Object to a numerical type in your situation.
 
How do I pass SelectedIndex to the second array? That is what I am confused about.

-Funk
 
Same way you're passing the value of the currently selected item to a MessageBox? Have any sample code?
 
Dim objReader As IO.StreamReader
Dim count As Integer
'Dim intFirstYearPopulation As Integer

If IO.File.Exists("c:\cities\cities.txt") = True Then
objReader = IO.File.OpenText("c:\cities\cities.txt")

Do While objReader.Peek <> -1
strCityName(count) = objReader.ReadLine()
decPopulation(count) = objReader.ReadLine()
cboCity.Items.Add(strCityName(count))
count += 1
Loop
Else

MsgBox("The file is not available. Restart the program when the file is available", , "Error")
Me.Close()

End If

End Sub

Private Sub btnComputeGrowth_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnComputeGrowth.Click
strSelectedItem = cboCity.SelectedItem
MsgBox(strSelectedItem)

These are declared as global:

Dim strCityName(9), strSelectedItem As String
Dim decPopulation(9) As Decimal
 
Back
Top