Solved

Random maths symbol into textbox

Posted on 2003-12-02
5
726 Views
Last Modified: 2008-03-04
How can i make a random maths symbol, plus, minus, divide, multiply appear into a text box at the click of a button.
0
Comment
Question by:s1555
5 Comments
 

Expert Comment

by:Vrenox
ID: 9858827
Not the best way maybe but the easiest I could think of.. put the math symbols in a hashtable paired with a number from 0 to 3 like so:

Private myHashTable As New HashTable
myHashTable.Add(0, "+")
        myHashTable.Add(1, "-")
        myHashTable.Add(2, "*")
        myHashTable.Add(3, "/")

then in the buttonclick handler all you have to do is the following:

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim myRandomNumGen As New Random
        MathSignText.Text = ""  'Clean up old value
        MathSignText.Text = myHashTable(myRandomNumGen.Next(4))
End Sub

This should do it


0
 
LVL 12

Accepted Solution

by:
roverm earned 250 total points
ID: 9858927
Or simply do this in the onclick event:

        Randomize()
        txtBox.Text = Mid("+-/*", Int(Rnd() * 4) + 1, 1)

D'Mzzl!
RoverM
0
 
LVL 9

Expert Comment

by:malharone
ID: 9871724
i liked roverm's style the best !! simple and does the work.. though could be more generalized

public sub printRandomChar()
        Randomize()
        dim chars as string = "+-/*"
        txtBox.Text = Mid(chars, Int(Rnd() * chars.length) + 1, 1)
end sub


so .. now, all you'd have to do is change the value of chars, and you'd have to remember to change the max. value of string.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10287349
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: roverm {http:#9858927}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now