Solved

listbox problem

Posted on 2003-11-27
6
198 Views
Last Modified: 2010-05-01
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
Comment
Question by:s1555
  • 2
6 Comments
 
LVL 1

Expert Comment

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

Select Case lstCaptures.ListIndex
    Case 0: Text1.Text = "Add"
    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

by:
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 0: Text1.Text = "Add"
    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 1: Text1.Text = "Add"
            Case 2: Text1.Text = "Subtract"
            Case 3: Text1.Text = "Multiply"
            Case 4: Text1.Text = "Divide"
        End Select
End Select

0
 
LVL 3

Expert Comment

by:ashoooo
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question