Visual Basic 6

hyperfire

New Member
I have to make a game for a lesson in school and unfortunately i have to make it on the visual basic program in school rather than my home version which is more modern and unfortunately not compatible. ( i can't install anything, i'm just going to run it in debug.)

The game is a simple game where you click on a christmas present that moves every .65 of a second the code so far is as follows.

Dim time As Integer
Dim score As Integer
Dim highscore As Integer
Dim bestgroup As Integer
Dim group As Integer

Private Sub Command1_Click()
group = InputBox("Please enter your group number", "Group number", "0")
score = 0
time = 0
Timer1.Enabled = True
Timer2.Enabled = True
Image1.Visible = True
End Sub

Private Sub Command3_Click()
Timer1.Enabled = False
Timer2.Enabled = False
Image1.Visible = False
If score > highscore Then bestgroup = group
If score > highscore Then highscore = score
End Sub

Private Sub Command5_Click()
MsgBox ("The highscore of " & highscore & " was scored by group number " & bestgroup & ".")
End Sub


Private Sub Picture1_Click()
score = score + 10
Text1.Text = score
End Sub


Private Sub Timer1_Timer()
time = time + 1
If score > highscore Then bestgroup = group
If score > highscore Then highscore = score
If time = 60 Then Timer1.Enabled = False
If time = 60 Then Timer2.Enabled = False
If time = 60 Then Picturebox1.Visible = False
End



My problem is the function that makes the present move to random locations, I'm not familiar with the old version of vb and it is different. There is no one in school who i know of (including teachers.) who could help. Can anyone suggest some code that upon a timer "ticking" moves an image to a random location.
 
i tried that first, no one seems to want to answer in any of those either. Normally there are one or two around the forum who know vb6 but this was a last chance anyway. Looks like i'll just have to experiment until i get something that works.

I generally don't use cf as much because of the lack of actual programming but i thought i'd take a shot.
 
I have VB6 but I don't use it very much. Typically what you would do to move an object around is use a timer or counter etc as you mentioned. On each tick you:

Generate a random number (Google "vb random number" eg link). Limit so it's less than the screen width. That's the X.

Ditto for Y using screen height as max

Move object to the X and Y.

Anything you cannot do, Google "vb whatever you want"
 
Okay, i have changed the game idea. I want to know how to use keycode inputs for the arrow keys. Normally i would use:
If e.keycode = keys.up Then x = 5
and so on for each key. This doesn't work on visual basic 6 anyone know what i should use instead?
 
Google it as I suggested. If vb6 is very different to other vb versions then Google "vb6 key input" (no quotes). There's 400,000 results to choose from. Here's one link.
 
I'm not stupid. (in fact it would be fair to say i am quite the opposite) I googled it before coming here. The reason i posted here was because i was in a lesson and had to leave and didnt have enough time to do a check. This doesn't require me to be online in all the time it takes to get an answer.

Thanks for the link anyway saves me looking through google next time i need it.
 
Last edited:
Back
Top