Click here to Skip to main content
15,894,330 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello

I'm working on a code for an assignment and I can't figure out how to use my list boxes in equation

like how to use the variables in the list boxes already. I need to add both variables together and present them on a label which I can not figure out how to do.

To clarify I'm working in visual Basics

What I have tried:

I've tried using If then, for next, and many others. I've been trying to figure this out for more than a week now.
Posted
Updated 13-Dec-18 4:29am

1 solution

We can't really help you specifically based on that little - we can't see what you have in your list boxes!
But at a guess, the list boxes contains strings, and you can't add them together directly.
Instead, convert the strings to numbers first:
VB
Dim valueFromListBox1 As String = "666"
Dim valueFromListBox2 As String = "333"
Dim value1 As Integer
Dim value2 As Integer

If Integer.TryParse(valueFromListBox1, value1) AndAlso Integer.TryParse(valueFromListBox2, value2) Then
    Dim result As Integer = value1 + value2
    Console.WriteLine(result)
End If
 
Share this answer
 
Comments
idkwhatimdoing 14-Dec-18 9:47am    
So what should I do if I have multiple variables to add?
Sorry for any confusion I'm very new to this site
OriginalGriff 14-Dec-18 9:59am    
What do you mean "multiple variables"? Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.

The better the information you give us, the better the help we can give you!
idkwhatimdoing 14-Dec-18 10:07am    
When selecting a variable or value in one listbox and selecting another in the second I would like to know how to add those selected values together and the solution pop up in a label
sorry
thanks
OriginalGriff 14-Dec-18 10:25am    
What do you think the code I gave you does? :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900