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
  • Learn & ask questions
Solved

Random maths symbol into textbox

Posted on 2003-12-02
5
728 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

766 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