|
-
Mar 29th, 2000, 10:14 AM
#1
Thread Starter
Junior Member
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
-
Mar 29th, 2000, 11:16 AM
#2
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".
-
Mar 29th, 2000, 02:48 PM
#3
Lively Member
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
-
Mar 30th, 2000, 02:55 AM
#4
Thread Starter
Junior Member
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
-
Mar 30th, 2000, 03:28 AM
#5
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.
-
Apr 4th, 2000, 10:17 AM
#6
Thread Starter
Junior Member
Still doesn't work
Still displays -1 It's weird
-
Apr 4th, 2000, 10:40 AM
#7
Frenzied Member
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.
-
Apr 6th, 2000, 07:22 AM
#8
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|