Results 1 to 8 of 8

Thread: High & low scores from input box

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    18
    I have to make this program with High and Low bowling scores that will display them in a label after you enter scores in a message box. But I don't know any idea how

    Here's what I got so far:
    Code:
    Private strTempScore As String, lnghigh As Long, lnglow As Long, intscore As Integer
    Const strTitle As String = "Bowling scores"
    Const strPrompt As String = "Enter a score (-1 to finish):"
    Const intSentinel As Integer = -1  'Loop flag
    
    Private Sub cmddone_Click()
    End
    End Sub
    
    Private Sub cmdscores_Click()
    
    strTempScore = InputBox(strPrompt, strTitle) 'Get Score
    
    If strTempScore = "" Then
        intscore = intSentinel
    Else
        intscore = strTempScore
    End If
    
    Do While intscore <> intSentinel
         
        strTempScore = InputBox(strPrompt, strTitle)
        If strTempScore = "" Then
            intscore = intSentinel
        Else
            intscore = strTempScore
        End If
    Loop
    End Sub
    
    Private Sub cmdstats_Click()
    lblhigh.Caption = lnghigh
    lbllow.Caption = lnglow
    End Sub
    
    Private Sub Form_Load()
    
    
    lblhigh.Caption = ""
    lbllow.Caption = ""
    End Sub

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    It would be a lot easier to create a form that contained two TextBoxes named for example, txtHigh and txtLow. The title of the form (or a label on the form) could say "Please enter your scores". You would also place appropriate labels next to the two textboxes so that the user would know what to enter. Once having done that your "output" label's caption would simply be "Your high score is " & txtHigh.Text & " and your low score is " & txtLow & "!"

    Another thing you could do is include validation code that makes sure both textboxes have something in them and that val(txtHight) is >= then val(txtLow).

    Let me know if you get an "A".

  3. #3
    Lively Member
    Join Date
    Jun 1999
    Posts
    120
    incorporate the minor changes in your cmdscores_Click sub i'd made below:
    see if this works...

    [code]
    Private Sub cmdscores_Click()
    strTempScore = InputBox(strPrompt, strTitle) 'Get Score

    If strTempScore = "" Then
    intscore = intSentinel
    Else
    intscore = strTempScore
    End If

    'For the first score, it is both the high and the low...
    [B]lnghigh = intscore [B]
    lnglow = intscore

    Do While intscore <> intSentinel
    strTempScore = InputBox(strPrompt, strTitle)
    If strTempScore = "" Then
    intscore = intSentinel
    Else
    intscore = strTempScore

    ' Check if the score is higher than the highest score so far
    lnghigh = Iif(intscore > lnghigh,intscore,lnghigh)

    ' Check if the score is lower that the lowest score so far
    lnglow = Iif(intscore < lnglow,intscore,lnglow) End If
    Loop
    End Sub

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    18

    always says -1 for low score because...

    It always displays -1 for the low number because it is the loop flag to stop the input boxes how can I stop that? here is the code:

    Code:
    Private strTempScore As String, lnghigh As Long, lnglow As Long, intscore As Integer
    Const strTitle As String = "Bowling scores"
    Const strPrompt As String = "Enter a score (-1 to finish):"
    Const strSentinel As String = -1 'Loop flag
    
    Private Sub cmddone_Click()
    End
    End Sub
    
    Private Sub cmdscores_Click()
    
    strTempScore = InputBox(strPrompt, strTitle) 'Get Score
    
    If strTempScore = "" Then
        intscore = strSentinel
    Else
        intscore = strTempScore
    End If
    
    lnghigh = intscore
    lnglow = intscore
    
    Do While intscore <> strSentinel
         
        strTempScore = InputBox(strPrompt, strTitle)
        If strTempScore = "" Then
            intscore = strSentinel
        Else
            intscore = strTempScore
        
    ' Check if the score is higher than the highest score so far
          lnghigh = IIf(intscore > lnghigh, intscore, lnghigh)
    ' Check if the score is lower that the lowest score so far
          lnglow = IIf(intscore < lnglow, intscore, lnglow)
    End If
    Loop
    End Sub
    
    Private Sub cmdstats_Click()
    lblhigh.Caption = lnghigh
    lbllow.Caption = lnglow
    End Sub
    
    Private Sub Form_Load()
    
    
    lblhigh.Caption = ""
    lbllow.Caption = ""
    End Sub

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    lnglow = IIf(intscore < lnglow, intscore, lnglow)

    If intscore <> -1 Then
    If intscore < lnglow then
    lnglow = intscore
    End If
    End If

    By the way while the IIf structure looks compact, it actually takes longer to execute then the If/Then/Else construct.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    18

    Still doesn't work

    Still displays -1 It's weird

  7. #7
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    Actually, it's not so weird...you have your "flag" declared as a constant, which means it will NEVER change value! A flag is usually a boolean (yes/no, true/false), and you should just declare it as a normal, Private variable. Then assign it the -1 value in Form_Load or at the start of the procedure where you will be testing it. Also, if it is supposed to be a number, don't declare it as a String! Use an Integer or a Long for whole numbers.
    ~seaweed

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    18

    no

    it still doesn't work ays -1 for low score

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