Hi,
I'm fairly new to VB6 and I have started to create a Bird Hunt game (Bird flies up - you shoot it).
I have implemented a scoring system which adds your score and name to a txt file, as well as the birds movment and click events.
I would like some constructive criticism on my coding (Bear in mind it is pretty basic atm - New to the scene).
It is run on Word using two Userforms.
Userform1:
Userform2:Code:Sub go_Click() x = 0 Start = 0 If (MsgBox("Are you ready?", 4)) = vbYes Then PauseTime2 = 2 ' Set duration. Start2 = Timer ' Set start time. Do While Timer < Start2 + PauseTime DoEvents ' Yield to other processes. Loop Finish = Timer ' Set end time. TotalTime = Finish - Start2 ' Calculate total time. UserForm1.Flight ' Run Flight Sub End If End Sub Sub Result() If x > 0 And check = False Then ' If the score is greater than 0 bird.Visible = False ' Hide the Bird j = (x + (i * 10) - (4 * i) + Int(bird.Top / i)) ' Calculate the score k = k + j response = MsgBox("Good Shot! You scored " & j & " points. Do you want to play again?", vbYesNo) If response = vbNo Then MsgBox ("Thanks for playing, you scored " & k & " points.") user = InputBox("Please Enter your name") Call UserForm2.FillVars(k, user) UserForm1.Hide UserForm2.Show ElseIf response = vbYes Then bird.Move random, 438 ' Reset the bird shot = False UserForm1.Flight End If ElseIf check = True Then ' If the bird reached the top and you didn't score MsgBox ("It got away!") bird.Move random, 438 ' Reset the bird shot = False lives = lives + 1 If lives = 1 Then lifelbl = "1st try." ElseIf lives = 2 Then lifelbl = "2nd try." ElseIf lives = 3 Then lifelbl = "Last try!" End If MsgBox ("Lives Lost: " & lives) If lives > 3 Then MsgBox ("You ran out of lives!") user = InputBox("Please Enter your name") Call UserForm2.FillVars(k, user) UserForm1.Hide UserForm2.Show End If End If End Sub Sub bird_Click() x = x + 1 ' Add one to the score shot = True End Sub Sub Flight() check = False bird.Enabled = True shot = False random = Int((500 * Rnd) + 1) If Int(TotalTime) = 2 Then PauseTime = 10 ' Duration Start = Timer bird.Visible = True If easy.Value = True Then Do While Timer < Start + PauseTime If shot = False Then bird.Top = bird.Top - (10 / 50) ' Move the bird up by the speed / 50 UserForm1.Repaint ' Repaint the form DoEvents If bird.Top < 1 Then ' If the bird is < 1 pixel from the top check = True ' Switch check to true UserForm1.Result Exit Do ' Exit the loop End If Else i = 10 UserForm1.Result Exit Do End If Loop ElseIf medium.Value = True Then Do While Timer < Start + PauseTime If shot = False Then bird.Top = bird.Top - (20 / 50) ' Move the bird up by the speed / 50 UserForm1.Repaint ' Repaint the form DoEvents If bird.Top < 1 Then ' If the bird is < 1 pixel from the top check = True ' Switch check to true UserForm1.Result Exit Do ' Exit the loop End If Else i = 20 UserForm1.Result Exit Do End If Loop ElseIf hard.Value = True Then Do While Timer < Start + PauseTime If shot = False Then bird.Top = bird.Top - (30 / 50) ' Move the bird up by the speed / 50 UserForm1.Repaint ' Repaint the form DoEvents If bird.Top < 1 Then ' If the bird is < 1 pixel from the top check = True ' Switch check to true UserForm1.Result Exit Do ' Exit the loop End If Else i = 30 UserForm1.Result Exit Do End If Loop End If End If End Sub
Thanks for your input,Code:Dim k As Integer Dim names As String Dim UserName As String Dim user As String Sub ok_Click() ok.Enabled = False Open "h:\users.txt" For Append As #1 Print #1, user; Tab(2); k Close #1 Open "h:\users.txt" For Input As #1 names = Input(LOF(1), #1) Close #1 scorelbl.Caption = (names) End Sub Sub FillVars(ByRef k1 As Integer, user1 As String) k = k1 user = user1 End Sub Sub UserForm_Initialize() Open "h:\users.txt" For Input As #1 names = Input(LOF(1), #1) Close #1 scorelbl.Caption = (names) End Sub
Loader




Reply With Quote