Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Random maths symbol into textbox

Posted on 2003-12-02
5
Medium Priority
?
733 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
[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
  • Learn & ask questions
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 1000 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

715 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