Results 1 to 6 of 6

Thread: Generating a random plus, minus, devide, etc...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    67

    Question

    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!
    Private Sub DeepCrap
    on error blame microsoft
    if microsoft = screwed then
    blame aol
    end if
    end deep crap

    Ahh VB6 Enterprise Edition

  2. #2
    Guest
    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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    67
    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
    Private Sub DeepCrap
    on error blame microsoft
    if microsoft = screwed then
    blame aol
    end if
    end deep crap

    Ahh VB6 Enterprise Edition

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    67
    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
    Private Sub DeepCrap
    on error blame microsoft
    if microsoft = screwed then
    blame aol
    end if
    end deep crap

    Ahh VB6 Enterprise Edition

  5. #5
    Guest
    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

  6. #6
    Guest
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width