Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Need urgent help plz

markblue777markblue777 Member Posts: 184
Hi everyone i need sum urgent help quick plz
how do i make the number for lblNum2 to always be smaller then lblNum1 so the answer is never a decimal
Private Sub cmdNext_Click()
'Generate next additon problem
Dim Number1 As Integer
Dim Number2 As Integer
txtAnswer.Text = ""
lblMessage.Caption = ""
NumProb = NumProb + 1
'Generate random number for addends
Number1 = Int(Rnd * 20)
Number2 = Int(Rnd * 20)
lblNum1.Caption = Format(Number1, "#0")
lblNum2.Caption = Format(Number2, "#0")
'Find sum
sum = Number1 / Number2
cmdNext.Enabled = False
txtAnswer.SetFocus
End Sub

thanks in advanced from
mark

«1

Comments

  • Gurpreet2311Gurpreet2311 Member Posts: 326



    Number1 = Int(Rnd * 20)
    Number2 = Int(Rnd * 20)

    do while number2 > number1
    Number2 = Int(Rnd * 20)
    loop


    [b]Regards
    Er. [blue]Gurpreet Singh [/blue](B.E [blue]Mech.)[/blue][/b]
    [hr]



  • JonathanJonathan Member Posts: 2,914
    : Number1 = Int(Rnd * 20)
    : Number2 = Int(Rnd * 20)
    :
    : do while number2 > number1
    : Number2 = Int(Rnd * 20)
    : loop
    :
    Maybe it'd be more efficient to just swap them over if they're not as we want...

    [code]If Number2 > Number1 Then
    Dim temp as Long
    temp = Number1
    Number1 = Number2
    Number2 = temp
    End If[/code]

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • markblue777markblue777 Member Posts: 184
    : : Number1 = Int(Rnd * 20)
    : : Number2 = Int(Rnd * 20)
    : :
    : : do while number2 > number1
    : : Number2 = Int(Rnd * 20)
    : : loop
    : :
    : Maybe it'd be more efficient to just swap them over if they're not as we want...
    :
    : [code]If Number2 > Number1 Then
    : Dim temp as Long
    : temp = Number1
    : Number1 = Number2
    : Number2 = temp
    : End If[/code]
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :

    thanks but after doing the above it has come up with this line
    sum = Number1 / Number2
    as having and error wot could it be
    from
    mark
  • markblue777markblue777 Member Posts: 184
    : : Number1 = Int(Rnd * 20)
    : : Number2 = Int(Rnd * 20)
    : :
    : : do while number2 > number1
    : : Number2 = Int(Rnd * 20)
    : : loop
    : :
    : Maybe it'd be more efficient to just swap them over if they're not as we want...
    :
    : [code]If Number2 > Number1 Then
    : Dim temp as Long
    : temp = Number1
    : Number1 = Number2
    : Number2 = temp
    : End If[/code]
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :
    and by the way this happens on both methords
    from
    mark
  • JonathanJonathan Member Posts: 2,914
    : : : Number1 = Int(Rnd * 20)
    : : : Number2 = Int(Rnd * 20)
    : : :
    : : : do while number2 > number1
    : : : Number2 = Int(Rnd * 20)
    : : : loop
    : : :
    : : Maybe it'd be more efficient to just swap them over if they're not as we want...
    : :
    : : [code]If Number2 > Number1 Then
    : : Dim temp as Long
    : : temp = Number1
    : : Number1 = Number2
    : : Number2 = temp
    : : End If[/code]
    : :
    : : Jonathan
    : :
    : : ###
    : : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    : :
    :
    : thanks but after doing the above it has come up with this line
    : sum = Number1 / Number2
    : as having and error wot could it be
    : from
    : mark
    :
    It's due to the position of the planet Mars. You may also find your program won't work on some Thursday afternoons.

    Uh...I mean...post the error message, or we really have no clue.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • markblue777markblue777 Member Posts: 184
    : : : : Number1 = Int(Rnd * 20)
    : : : : Number2 = Int(Rnd * 20)
    : : : :
    : : : : do while number2 > number1
    : : : : Number2 = Int(Rnd * 20)
    : : : : loop
    : : : :
    : : : Maybe it'd be more efficient to just swap them over if they're not as we want...
    : : :
    : : : [code]If Number2 > Number1 Then
    : : : Dim temp as Long
    : : : temp = Number1
    : : : Number1 = Number2
    : : : Number2 = temp
    : : : End If[/code]
    : : :
    : : : Jonathan
    : : :
    : : : ###
    : : : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : : : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : : : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    : : :
    : :
    : : thanks but after doing the above it has come up with this line
    : : sum = Number1 / Number2
    : : as having and error wot could it be
    : : from
    : : mark
    : :
    : It's due to the position of the planet Mars. You may also find your program won't work on some Thursday afternoons.
    :
    : Uh...I mean...post the error message, or we really have no clue.
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :
    i get a few on is run time error '11' division by zero
    then another one is run time error '6' overflow
    and thats about it really and also how do i make it so after i type the answer in the text box and click enter how do i make it so i cannot type in the text box until the next question cums up
    from
    mark
  • JonathanJonathan Member Posts: 2,914
    : : : : : Number1 = Int(Rnd * 20)
    : : : : : Number2 = Int(Rnd * 20)
    : : : : :
    : : : : : do while number2 > number1
    : : : : : Number2 = Int(Rnd * 20)
    : : : : : loop
    : : : : :
    : : : : Maybe it'd be more efficient to just swap them over if they're not as we want...
    : : : :
    : : : : [code]If Number2 > Number1 Then
    : : : : Dim temp as Long
    : : : : temp = Number1
    : : : : Number1 = Number2
    : : : : Number2 = temp
    : : : : End If[/code]
    : : : :
    : : : : Jonathan
    : : : :
    : : : : ###
    : : : : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : : : : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : : : : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    : : : :
    : : :
    : : : thanks but after doing the above it has come up with this line
    : : : sum = Number1 / Number2
    : : : as having and error wot could it be
    : : : from
    : : : mark
    : : :
    : : It's due to the position of the planet Mars. You may also find your program won't work on some Thursday afternoons.
    : :
    : : Uh...I mean...post the error message, or we really have no clue.
    : :
    : : Jonathan
    : :
    : : ###
    : : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    : :
    : :
    : i get a few on is run time error '11' division by zero
    Ah, OK. That's because your numbers could be zero. Try something more like:-
    Number1 = 1 + Int(Rnd * 20)
    Number2 = 1 + Int(Rnd * 20)
    Instead so it can never be zero.

    : then another one is run time error '6' overflow
    Overflow? Hmmmm....I can't think how you'd manage that, given you only have integers between 1 and 20! What values are going in when you get the overflow error (e.g. what are Number1 and Number2)?

    : and thats about it really and also how do i make it so after i type
    : the answer in the text box and click enter how do i make it so i
    : cannot type in the text box until the next question cums up
    :
    TextBox.Enabled = False ' To stop people typing in it
    TextBox.Enabled = True ' To allow people to type in it again

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • markblue777markblue777 Member Posts: 184
    : : : : : : Number1 = Int(Rnd * 20)
    : : : : : : Number2 = Int(Rnd * 20)
    : : : : : :
    : : : : : : do while number2 > number1
    : : : : : : Number2 = Int(Rnd * 20)
    : : : : : : loop
    : : : : : :
    : : : : : Maybe it'd be more efficient to just swap them over if they're not as we want...
    : : : : :
    : : : : : [code]If Number2 > Number1 Then
    : : : : : Dim temp as Long
    : : : : : temp = Number1
    : : : : : Number1 = Number2
    : : : : : Number2 = temp
    : : : : : End If[/code]
    : : : : :
    : : : : : Jonathan
    : : : : :
    : : : : : ###
    : : : : : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : : : : : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : : : : : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    : : : : :
    : : : :
    : : : : thanks but after doing the above it has come up with this line
    : : : : sum = Number1 / Number2
    : : : : as having and error wot could it be
    : : : : from
    : : : : mark
    : : : :
    : : : It's due to the position of the planet Mars. You may also find your program won't work on some Thursday afternoons.
    : : :
    : : : Uh...I mean...post the error message, or we really have no clue.
    : : :
    : : : Jonathan
    : : :
    : : : ###
    : : : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : : : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : : : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    : : :
    : : :
    : : i get a few on is run time error '11' division by zero
    : Ah, OK. That's because your numbers could be zero. Try something more like:-
    : Number1 = 1 + Int(Rnd * 20)
    : Number2 = 1 + Int(Rnd * 20)
    : Instead so it can never be zero.
    :
    : : then another one is run time error '6' overflow
    : Overflow? Hmmmm....I can't think how you'd manage that, given you only have integers between 1 and 20! What values are going in when you get the overflow error (e.g. what are Number1 and Number2)?
    :
    : : and thats about it really and also how do i make it so after i type
    : : the answer in the text box and click enter how do i make it so i
    : : cannot type in the text box until the next question cums up
    : :
    : TextBox.Enabled = False ' To stop people typing in it
    : TextBox.Enabled = True ' To allow people to type in it again
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    yo well the over flow thing does not seem to happen any more thanks and the no zero thing cums up any more thatnks for that mate
    but now the text box thing aint working though cos it still lets me type in it after i have hit eneter for the correct answer to be displayed
    from
    mark

  • markblue777markblue777 Member Posts: 184
    : : : : : : : Number1 = Int(Rnd * 20)
    : : : : : : : Number2 = Int(Rnd * 20)
    : : : : : : :
    : : : : : : : do while number2 > number1
    : : : : : : : Number2 = Int(Rnd * 20)
    : : : : : : : loop
    : : : : : : :
    : : : : : : Maybe it'd be more efficient to just swap them over if they're not as we want...
    : : : : : :
    : : : : : : [code]If Number2 > Number1 Then
    : : : : : : Dim temp as Long
    : : : : : : temp = Number1
    : : : : : : Number1 = Number2
    : : : : : : Number2 = temp
    : : : : : : End If[/code]
    : : : : : :
    : : : : : : Jonathan
    : : : : : :
    : : : : : : ###
    : : : : : : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : : : : : : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : : : : : : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    : : : : : :
    : : : : :
    : : : : : thanks but after doing the above it has come up with this line
    : : : : : sum = Number1 / Number2
    : : : : : as having and error wot could it be
    : : : : : from
    : : : : : mark
    : : : : :
    : : : : It's due to the position of the planet Mars. You may also find your program won't work on some Thursday afternoons.
    : : : :
    : : : : Uh...I mean...post the error message, or we really have no clue.
    : : : :
    : : : : Jonathan
    : : : :
    : : : : ###
    : : : : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : : : : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : : : : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    : : : :
    : : : :
    : : : i get a few on is run time error '11' division by zero
    : : Ah, OK. That's because your numbers could be zero. Try something more like:-
    : : Number1 = 1 + Int(Rnd * 20)
    : : Number2 = 1 + Int(Rnd * 20)
    : : Instead so it can never be zero.
    : :
    : : : then another one is run time error '6' overflow
    : : Overflow? Hmmmm....I can't think how you'd manage that, given you only have integers between 1 and 20! What values are going in when you get the overflow error (e.g. what are Number1 and Number2)?
    : :
    : : : and thats about it really and also how do i make it so after i type
    : : : the answer in the text box and click enter how do i make it so i
    : : : cannot type in the text box until the next question cums up
    : : :
    : : TextBox.Enabled = False ' To stop people typing in it
    : : TextBox.Enabled = True ' To allow people to type in it again
    : :
    : : Jonathan
    : :
    : : ###
    : : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    : yo well the over flow thing does not seem to happen any more thanks and the no zero thing cums up any more thatnks for that mate
    : but now the text box thing aint working though cos it still lets me type in it after i have hit eneter for the correct answer to be displayed
    : from
    : mark
    :
    : and by the eway here is where it has to be typed in yea
    Private Sub txtAnswer_KeyPress(KeyAscii As Integer)
    Dim Ans As Integer
    ''Only allow numbers, minus sign, decimal point, return key
    If (KeyAscii >= vbKey0 And KeyAscii <= vbKey9) Or KeyAscii = vbkeyMinus Or KeyAscii = vbKeyDecPt Or KeyAscii = vbKeyBack Then
    Exit Sub
    ElseIf KeyAscii = vbKeyReturn Then
    'Check answer
    Ans = Val(txtAnswer.Text)
    If Ans = sum Then
    NumRight = NumRight + 1
    lblMessage.Caption = "That's The Correct Answer!"
    Else
    lblMessage.Caption = "Your Answer Is Wrong The Correct Anser Is " + Format(sum, "#0")
    End If
    lblScore.Caption = Format(1000 * NumRight / NumProb, "##0")
    cmdNext.Enabled = True
    cmdNext.SetFocus
    txtAnswer.Enabled = False ' To stop people typing in it
    txtAnswer.Enabled = True ' To allow people to type in it again
    Else
    KeyAscii = 0
    End If
    End Sub
    and i have changed it from textbox to txtAnswer (my right name for the textbox so wot could be happening
    from
    mark
  • JonathanJonathan Member Posts: 2,914
    : : : : : : : : Number1 = Int(Rnd * 20)
    : : : : : : : : Number2 = Int(Rnd * 20)
    : : : : : : : :
    : : : : : : : : do while number2 > number1
    : : : : : : : : Number2 = Int(Rnd * 20)
    : : : : : : : : loop
    : : : : : : : :
    : : : : : : : Maybe it'd be more efficient to just swap them over if they're not as we want...
    : : : : : : :
    : : : : : : : [code]If Number2 > Number1 Then
    : : : : : : : Dim temp as Long
    : : : : : : : temp = Number1
    : : : : : : : Number1 = Number2
    : : : : : : : Number2 = temp
    : : : : : : : End If[/code]
    : : : : : : :
    : : : : : : : Jonathan
    : : : : : : :
    : : : : : : : ###
    : : : : : : : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : : : : : : : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : : : : : : : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    : : : : : : :
    : : : : : :
    : : : : : : thanks but after doing the above it has come up with this line
    : : : : : : sum = Number1 / Number2
    : : : : : : as having and error wot could it be
    : : : : : : from
    : : : : : : mark
    : : : : : :
    : : : : : It's due to the position of the planet Mars. You may also find your program won't work on some Thursday afternoons.
    : : : : :
    : : : : : Uh...I mean...post the error message, or we really have no clue.
    : : : : :
    : : : : : Jonathan
    : : : : :
    : : : : : ###
    : : : : : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : : : : : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : : : : : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    : : : : :
    : : : : :
    : : : : i get a few on is run time error '11' division by zero
    : : : Ah, OK. That's because your numbers could be zero. Try something more like:-
    : : : Number1 = 1 + Int(Rnd * 20)
    : : : Number2 = 1 + Int(Rnd * 20)
    : : : Instead so it can never be zero.
    : : :
    : : : : then another one is run time error '6' overflow
    : : : Overflow? Hmmmm....I can't think how you'd manage that, given you only have integers between 1 and 20! What values are going in when you get the overflow error (e.g. what are Number1 and Number2)?
    : : :
    : : : : and thats about it really and also how do i make it so after i type
    : : : : the answer in the text box and click enter how do i make it so i
    : : : : cannot type in the text box until the next question cums up
    : : : :
    : : : TextBox.Enabled = False ' To stop people typing in it
    : : : TextBox.Enabled = True ' To allow people to type in it again
    : : :
    : : : Jonathan
    : : :
    : : : ###
    : : : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : : : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : : : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    : : yo well the over flow thing does not seem to happen any more thanks and the no zero thing cums up any more thatnks for that mate
    : : but now the text box thing aint working though cos it still lets me type in it after i have hit eneter for the correct answer to be displayed
    : : from
    : : mark
    : :
    : : and by the eway here is where it has to be typed in yea
    : Private Sub txtAnswer_KeyPress(KeyAscii As Integer)
    : Dim Ans As Integer
    : ''Only allow numbers, minus sign, decimal point, return key
    : If (KeyAscii >= vbKey0 And KeyAscii <= vbKey9) Or KeyAscii = vbkeyMinus Or KeyAscii = vbKeyDecPt Or KeyAscii = vbKeyBack Then
    : Exit Sub
    : ElseIf KeyAscii = vbKeyReturn Then
    : 'Check answer
    : Ans = Val(txtAnswer.Text)
    : If Ans = sum Then
    : NumRight = NumRight + 1
    : lblMessage.Caption = "That's The Correct Answer!"
    : Else
    : lblMessage.Caption = "Your Answer Is Wrong The Correct Anser Is " + Format(sum, "#0")
    : End If
    : lblScore.Caption = Format(1000 * NumRight / NumProb, "##0")
    : cmdNext.Enabled = True
    : cmdNext.SetFocus
    : txtAnswer.Enabled = False ' To stop people typing in it
    : txtAnswer.Enabled = True ' To allow people to type in it again
    : Else
    : KeyAscii = 0
    : End If
    : End Sub
    : and i have changed it from textbox to txtAnswer (my right name for the textbox so wot could be happening
    :
    You have to put the code in the right place! You need to put the first line where you want the text box to be disabled, and the second one where you want it to be re-enabled.

    : txtAnswer.Enabled = False ' To stop people typing in it
    Put this one at the start of the sub.

    : txtAnswer.Enabled = True ' To allow people to type in it again
    Put this one at the end of the sub.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

«1
Sign In or Register to comment.