Solved

listbox problem

Posted on 2003-11-27
200 Views
Im a beginner to vb.NET and im making a program that requires the user to select an item from a list box (add, subtract, divide, multiply, random). Once the user has selected which one they want, when they click on it i would like the appropriate symbol to appear in a textbox.

If anyone can help with making the choice random work too, i would be very greatful.
0
Question by:s1555
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 1

Expert Comment

ID: 9832932
In the OnClick event put the following code for a list namded List1:

Select Case lstCaptures.ListIndex
Case 1: Text1.Text = "Subtract"
Case 2: Text1.Text = "Multiply"
Case 3: Text1.Text = "Divide"
Case 4: Text1.Text = "Random"
End Select

To generate a random number between A and B use:

Randomize Timer
iRandom = Int((B - A + 1) * Rnd + A)
0

LVL 1

Accepted Solution

Mutare99 earned 50 total points
ID: 9832942
Oh, I see, you want the Random choice to pick one of the others.  You can use this for that:

Select Case lstCaptures.ListIndex
Case 1: Text1.Text = "Subtract"
Case 2: Text1.Text = "Multiply"
Case 3: Text1.Text = "Divide"
Case 4
Randomize Timer
iRandom = Int((4 - 1 + 1) * Rnd + 1)
Select Case iRandom
Case 2: Text1.Text = "Subtract"
Case 3: Text1.Text = "Multiply"
Case 4: Text1.Text = "Divide"
End Select
End Select

0

LVL 3

Expert Comment

ID: 9833934
If you want the appropriate symbol to appear in the textbox, just change the above code to

Text1.Text = "+"
or
Text1.Text = "-"
.. etc.
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month3 days, 9 hours left to enroll