Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Visual Basic (https://www.askmehelpdesk.com/forumdisplay.php?f=469)
-   -   If statement (https://www.askmehelpdesk.com/showthread.php?t=209546)

  • Apr 25, 2008, 01:40 PM
    panderso
    If statement
    Hi I am doing this simple program in visual basic express

    Sum.Text = Val(Num1.Text * 3) + Val(Num2.Text) + Val(Num3.Text) - Val(Num3.Text)

    This allows the user to enter number of wins (which gets x by 3) number of draws and number of losses.

    I have to limit the user to entering a combination of only 10 i.e 4 wins 3 draws 3 lose.

    I have been trying to put an it statement in that will prompt user to check input if they enter a combination of less or more than 10, any help would be great.

    I hope this makes sense.

    Thanks fr looking:)
  • Apr 25, 2008, 05:22 PM
    Scleros
    My Basic is rusty, but the general idea would be:

    Code:

    Do (Forever)
      Wins = InputBox(Wins)
      Draws = InputBox(Draws)
      Losses = InputBox(Losses)

      If (Wins + Draws + Losses) <> 10 Then
        MessageBox "Stupid User!"
      Else
        Sum = Wins*3 + Draws + Losses - Losses (Your code?)
       
        Exit Do
      End If
    Loop

    [Use Sum]

  • Apr 29, 2008, 12:44 PM
    melondotnet
    It may be better to create a system by which the user can not procede without entering the correct num of things, by having a continue button disabled.
    Form:

    Imaging you have three text boxes, and a continue button.

    txtWins as textbox
    txtLoses as textbox
    txtDraws as textbox
    next as button [auto disabled on form load]

    Code:


    Private Sub Input_Change(ByVal sender... ) Handels txtWins.TextChanged, txtLoses.TextChanged, txtDraws.TextChanged 'Revise this, It may not be accurate!

    'If the text in any of the text boxs changes, run a CHECK
    'The Handeling code may not be accurate. I havn't had multiple handle events leading to the same outcome for a long time.

    Check_10()

    End Sub

    Sub Check_10()

    If Cint(txtWins.text) + Cint(txtLoses.Text) + Cint(txtDraws.Text) = 10 Then
    'If inputs add up to 10, enable the continue button
    next.Enabled = True
    Else
    'If inputs add up to something over than 10, disable it
    next.Enabled = False
    End If

    End Sub

    :End Code

    Hope this helps

  • All times are GMT -7. The time now is 07:37 PM.