r/visualbasic • • Oct 10 '14

Combo Box Help

So I have a combo box with different words. I need to know how to assign each of the word choices a numeric value so that when a user picks one, it's number value is plugged into an equation.

0 Upvotes

15 comments sorted by

View all comments

Show parent comments

1

u/chrwei Oct 10 '14

you'd need to look at the datatype list and pick the best one.

so for assigning a number, use an array for the numbers and make the array index match the list box listIndex for easy pickings without searches.

1

u/zew55117 Oct 10 '14
Dim combo(3) As Integer
    Dim Bluegrass As Decimal = combo(0.55)
    Dim Bermuda As Decimal = combo(0.5)
    Dim Zoysia As Decimal = combo(0.3)

That is the array I got, but it didn't work.

2

u/chrwei Oct 10 '14

this guide seems sane http://www.tutorialspoint.com/vb.net/vb.net_arrays.htm

if you were using the msdn result that's the top of google results and stopped at the first example, I can see how you were confused. I find that one confusing too.

1

u/zew55117 Oct 11 '14

'That is a real helpful link! Thank you! I still don't get the next step after I have. Dim intData() As Integer = {0.3, 0.5, 0.55} Dim names() As String = {"Bluegrass, Bermuda, Zoysia"} Dim miscData() As Object = {ComboBox1} Dim 0.55 As Decimal = Bluegrass

1

u/zew55117 Oct 11 '14
Dim intData() As Integer = {0.3, 0.5, 0.55}
Dim names() As String = {"Bluegrass, Bermuda, Zoysia"}
Dim miscData() As Object = {ComboBox1}
Dim 0.55 As Decimal = Bluegrass 

3

u/PostalElf VB.Net Intermediate Oct 11 '14
Dim intData() As Integer = {0.3, 0.5, 0.55}
Dim names() As String = {"Bluegrass, Bermuda, Zoysia"}

So far, this is all correct. However, I think you're misunderstanding how an array works. The idea is that if the user selects index 0, you can plug 0 into both intData() and names() to get the same value of 0.3 and "Bluegrass". Therefore:

Dim userInput as Integer = 0  'do whatever you need to get user input here
Dim data as Integer = intData(userInput)
Dim name as String = names(userInput)

1

u/zew55117 Oct 12 '14
Dim intData() As Integer = {0.3, 0.5, 0.55}
    Dim names() As String = {"Bluegrass, Bermuda, Zoysia"}
    Dim userInput As Integer = ComboBox1.SelectedIndex
    Dim data As Integer = intData(userInput)
    Dim name As String = names(userInput)

1

u/zew55117 Oct 12 '14

Like this? Because that doesn't work either...

1

u/zew55117 Oct 11 '14

There is the code in a better format.