-
Ok, I am kinda creating this "math" program to solve a game called krypto but I have a problem I need a code that can generate random : + , -, *,/, so that i can put them between variebles : A * B + C * D - E = G and have it generate the functions at random and place them between the variebles. Some help? Thanks
PS: I don't care if its an OCX, win API, or just plain old VB code as long as it does what I want it to!
-
Try this:
Code:
Private Sub Command1_Click()
Randomize
RetVal = Int((4 * Rnd) + 1)
If RetVal = 1 Then RetSign = "+"
If RetVal = 2 Then RetSign = "-"
If RetVal = 3 Then RetSign = "*"
If RetVal = 4 Then RetSign = "/"
MsgBox RetSign
End Sub
-
Hmmm i got the code but im still a little confused on how i can use it..can u please break it down a bit ... thanks a lot for the help
-
I mean i get how to generate a random function but how do i use it between 2 numbers like say the generated function is plus so how do i get it to do 1 + 2 and then check if that equals 3 thanks
-
This is the only thing I could think of.
Code:
Private Sub Command1_Click()
Randomize
RetVal = Int((4 * Rnd) + 1)
If RetVal = 1 Then RetSign = "+"
If RetVal = 2 Then RetSign = "-"
If RetVal = 3 Then RetSign = "*"
If RetVal = 4 Then RetSign = "/"
If RetSign = "+" Then
RetNum = 5 + 5
ElseIf RetSign = "-" Then
RetNum = 5 - 5
ElseIf RetSign = "*" Then
RetNum = 5 * 5
ElseIf RetSign = "/" Then
RetNum = 5 / 5
End If
MsgBox RetNum
End Sub
-
It'll be much shorter if you use the Choose() function.
Add this to a Form with 2 TextBoxes and a CommandButton.
Code:
Randomize
Num = Choose(Int(Rnd * 4) + 1, Val(Text1) + Val(Text2), Text1 - Text2, Text1 / Text2, Text1 * Text2)
Print Num