Visual Basic: HHHEEEEEEEEELLLLLLLLLPPPPPPPPPPPPP!!!!!!!!!

NikPreviousAcct

No Lifer
Aug 15, 2000
52,763
1
0
I'm simply trying to move a label named "target" across from left to right, like an animation. I've been given a missile launcher program to hash out for my VB class, and the damn bastid of a teacher is making the whole class a damn guessing game. I've been able to deal with it for the most part up until now. WTF??

Here's what I've been able to stumble up with:


Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 97 Then
Launcher.Left = Launcher.Left - 1
End If
If KeyAscii = 100 Then
Launcher.Left = Launcher.Left + 1
End If
End Sub
--------------------------------------
Private Sub Form_Load()
Target.Left = 0
Do While Target.Left = 5880
Target.Left = Target.Left + 1
Loop
End Sub






Can someone please tell me what I'm doing wrong?
 

BoberFett

Lifer
Oct 9, 1999
37,562
9
81
Edit: It would help to know what you're trying to accomplish and what the intended and current behavior is.

Is it that the target won't move? If so, that's because of the loop. You're setting the .Left to zero, then the while is set to Do While .Left = 5880. It'll never get into the loop.

And a loop in the Load event is bad, if it does enter a loop during the Load, it won't even display the form. You'll need to explore the use of a Timer control for this one.
 

BigToque

Lifer
Oct 10, 1999
11,700
0
76
This is from a game I was working on before. Its not great, but it will work.

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
____Select Case KeyCode
________Case vbKeyUp 'Up is Pushed
__________If imgKnight.Top = 120 Then
____________Exit Sub
__________ElseIf imgKnight.Left >= 3600 And imgKnight.Top = 1800 Then
____________Exit Sub
__________Else
____________imgKnight.Top = imgKnight.Top - 120
__________End If
____End Select
End Sub

BTW, if anyone wants to play my first ever game (got me 99% in grade 11 Computer Science), let me know, and I'll upload it somewhere. Note: It sucks ass :)
 

NikPreviousAcct

No Lifer
Aug 15, 2000
52,763
1
0
I can get the target to move, but I can't get it to move slowly enough no to look like it just appears on the right-hand side of the screen. When it gets there, I would need to reset it back to the left side, and that's no problem. I've been "exploring" the timer issue, but I've got some other ideas I'm going to try.

In the coding, I should have put
Do While target.left<5880
target.left=target.left+1
end if

Thanks for the help so far guys!



So far I've got some more code for you guys to play with:

-------------------------------------------
Option Explicit
Dim score As Integer
Dim missiles As Integer
-------------------------------------------

Private Sub Form_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
----Case 97 And (Launcher.Left > 0)
--------Launcher.Left = Launcher.Left - 100
--------Missile.Left = Missile.Left - 100
----Case 100 And (Launcher.Left < 5880)
--------Launcher.Left = Launcher.Left + 100
--------Missile.Left = Missile.Left + 100
----Case 119
--------Launch
----End Select
If (Missile.Top = Target.Top) And (Missile.Left = Target.Left) Then
----Missile.Top = Launcher.Top - 240
----Missile.Left = Launcher.Left + 240
----score = score + 10
----missiles = missiles - 1
----lblscore = score
----lblmissiles = missiles
----End If
End Sub
-------------------------------------------
Private Sub Form_Load()
missiles = 20
score = 0
End Sub
-------------------------------------------
Public Function Launch()
If missiles > 0 Then
----Do While Missile.Top > 0
----Missile.Top = Missile.Top - 10
--------Loop
----If Missile.Top = 0 Then
----Missile.Top = Launcher.Top - 240
----Missile.Left = Launcher.Left + 240
----End If
----missiles = missiles - 1
----lblmissiles.Caption = &quot;Missiles: &quot; &amp; missiles
End If
If missiles = 0 Then
----Missile.Enabled = False
----Missile.Visible = False
End If
End Function
-------------------------------------------



As you can see, I've completely taken out the parts pertaining to moving the target. what I have now works perfectly. But I'm not familiar with X-Y coordinate syntax in VB and I'm thinkin' that the X-Y coordinate root for Missile/Target contact is the way to go. *grr*
 

Pretender

Banned
Mar 14, 2000
7,192
0
0
Ah, the days of simplified programming. What I wouldn't give to be able to eat the red pill and go back to those days.
 

NikPreviousAcct

No Lifer
Aug 15, 2000
52,763
1
0
got it, thanks Stefan.

simple? This is my first delve into VB. It wouldn't be that bad if I were familiar with the program to begin with. But, as I've said before, the teacher's making the class a damn guessing game instead of saying &quot;this is how you get something to move&quot; and &quot;this is how you get the program to realize that things are overlapping/hitting&quot; and then &quot;make this program.&quot;

but nnnnnnooooooooooooooooooo... he's got to say &quot;um... &quot;here's the keyboard and mouse, here's the program CD for installation, now make me a program that does xxx and xxx and xxx.&quot;
 

Pretender

Banned
Mar 14, 2000
7,192
0
0
I wasn't trying to insult you, but I was just reminiscing about the days when I thought I was l33t because I knew VB. Also, as for the reference to the red pill, I was listening to the theme song to the Matrix.
 

NikPreviousAcct

No Lifer
Aug 15, 2000
52,763
1
0
nope, I didn't take it as an insult. I just let off some steam about the class. I got so frustrated with the teacher and the class that I actually broke down last night. :( :| I recognized the reference to the pill too. :) I love that movie!
 

NikPreviousAcct

No Lifer
Aug 15, 2000
52,763
1
0
no, I haven't gotten it down yet. I'm still trying to figure out how to get the target to move more slowly and to figure out how to get the computer to realize that the missile hit the target. i.e.: I've made no progress. I've also talked with my g/f's boss. He uses VB (and writes HTML) for a living. He couldn't help me much either. *grr*
 

Pretender

Banned
Mar 14, 2000
7,192
0
0
It's been a LONG time since I did VB so I don't remember much...but I have a book about VB game programming...it comes with a CD and I remember one of the things (I think it was the first example) was the game had to determine if the ball hit the paddle (it was one of those types of games). I'll find the CD that came with it and upload that example...it's in VB 3.0, but the same functions it uses should still be valid.
 

Pretender

Banned
Mar 14, 2000
7,192
0
0
Ok I believe the file you want to look in will be is Break.frm, but I could be wrong. The list of files can be found here, and I was too lazy to make links to all of them, so just copy and paste the filename (replace contents.htm with whatever filename you want to look at).

[edit]aargh, for some reason, when I uploaded the files, they converted to all uppercase...when pasting change all the letters to uppercase.[/edit]
 

NikPreviousAcct

No Lifer
Aug 15, 2000
52,763
1
0
cool :) that's my next project! ;)

<edit>

I tried it, but I keep getting a &quot;page not found&quot; error. Damn, this is not my week.