|
-
Nov 29th, 2000, 01:39 PM
#1
Thread Starter
New Member
Good afternoon,
Could someone help me with my first array. What this program is suppose to do is:
Keeps track of how many games you play and how many guesses each game took. I am able to get the number of guesses for each game to refill in the list box. However, I want to store the number of guesses for each game in an array for future calculations. Could you please take a look at the code below to give me some assistance. If you notice if anything could be coded much similar please don't hesitate....suggestions and opinions always welcomed.
Thanks.
Option Explicit
Dim intAnswer As Integer
Dim intGuessArray(0 To 9) As Integer
Dim intHigh As Integer
Dim inLow As Integer
Dim intTotalGuess As Integer
Dim intTotalGames As Integer
Private Sub cmdGuess_Click()
If txtGuess.Text = "" Then
MsgBox "Guess is Required", vbOKOnly, "Game Program"
txtGuess.SetFocus
Exit Sub
End If
If IsNumeric(txtGuess.Text) = False Then
MsgBox "The guess must be numeric", vbOKOnly, "Game Program"
txtGuess.SetFocus
Exit Sub
End If
If Val(txtGuess.Text) > 10 Then
MsgBox "The guess must be from 1 to 10", vbOKOnly, "Game Program"
txtGuess.SetFocus
Exit Sub
End If
'OLD ONE
'If Val(txtGuess.Text) < intAnswer Then
' lblAnswer.Caption = " The Answer is: Higher"
' intTotalGuess = intTotalGuess + 1
' Exit Sub
'End If
'
'If Val(txtGuess.Text) > intAnswer Then
' lblAnswer.Caption = " The Answer is: Lower"
' intTotalGuess = intTotalGuess + 1
' Exit Sub
'End If
'
'If Val(txtGuess.Text) = intAnswer Then
' intTotalGuess = intTotalGuess + 1
' lblAnswer.Caption = "You are correct, it took you only " & intTotalGuess & " time(s)."
' Exit Sub
'End If
'NEW ONE
intTotalGuess = intTotalGuess + 1
If Val(txtGuess.Text) < intAnswer Then
lblAnswer.Caption = " The Answer is: Higher"
ElseIf Val(txtGuess.Text) > intAnswer Then
lblAnswer.Caption = " The Answer is: Lower"
ElseIf Val(txtGuess.Text) = intAnswer Then
lblAnswer.Caption = "You are correct, it took you only " & intTotalGuess & " time(s)."
End If
End Sub
Private Sub cmdNew_Click()
'Assigns a new answer by generating a random number from 1 - 10 and
'displays the answer to a label
intAnswer = Int(10 * Rnd + 1)
lblmsg.Caption = intAnswer
intTotalGames = intTotalGames + 1
'Clears the Guess box and the Caption Box
txtGuess.Text = ""
lblAnswer.Caption = ""
End Sub
Private Sub cmdshow_Click()
lstGuess.AddItem intTotalGames & " " & intTotalGuess
intTotalGuess = 0
End Sub
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
|