Solved

Random maths symbol into textbox

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

10 Experts available now in Live!

Get 1:1 Help Now