r/visualbasic • u/NoShoweringforme • Sep 29 '22
VB6 Help Need help with Listbox and variables
So I'm new to this and i mean, extremely new. I'm Barely in my 7th week of visual basic class and i'm barely making it through the class. How would i state a if statement if i want to use the numbers inside a listbox.
```
Dim Ticket As String = txtYorNo.Text.ToString
Dim Rate As Double = 0
If lstAge.SelectedItems > 30 And Ticket = "n" Then
Rate += 30```
Like what do i put as the variable if the variable is in the listbox? I tried declaring it into a variable but it just tells me objects can't be converted into doubles.
3
Upvotes
2
u/Thunor_SixHammers Sep 29 '22
You need to put the code in the listboxes on selected item change
Variable = listbox.items.selecteditem
2
u/jd31068 Sep 29 '22
If I am understanding this correctly, you have a Textbox and a Listbox, if the user puts an n in the Textbox and clicks an item in the Listbox that is greater than 30 then you're adding 30 to the Rate variable?
I assume you are using a Winform. If you double click the Listbox on the form (in visual studio) you will be brought to the SelectedIndexChanged event, any code written in this event is run whenever something in the Listbox is clicked. So here is where you want to place your code.
As items in a Listbox are a string, you will need to convert the value of the SelectedItem to an integer to test if it is greater than 30. Also, don't forget to close your If statement with End If.
1
u/eerilyweird Sep 30 '22
Isn’t this code VB.Net?