Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fire 2 arrows across the screen 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
i have a problem?

i have fired a label across the screen using random speed with the following code under the command button in visual basic 5


for a = 20 to 14000 step int(rnd * 12 + 1)
label1.left = a
next a

after this i wanted to fire 2 labels across the screen.I wanted them to start exactly at the same time but finish in different orders instead of finishing together.

i tryed different permutations with the code and a rnd statement after the step but the arrows fired one after each other. i.e the first arrow would fire, and when that had reached the end the second arrow would fire because of the programme order.I tryed to assign variables under the command button . How do i do it. I tryed 2 different variables and 2 for statements and 2 next statements but obvoiusly this caused an error. Can you help me?
 
Have you tried this?

Suppose you have labela and labelb that you want to move on a form that is 14000 twips wide (as appears from your example above).

Dim SpeedA as Long
Dim SpeedB as Long

'get a speed for A and B
SpeedA = int(rnd * 12 + 1)
SpeedB = int(rnd * 12 + 1)

Do Until ((labela.Left + labela.Width >= 14000) _
And (labelb.Left + labelb.Width >= 14000))

If (labela.Left + labela.Width < 14000) Then
labela.left = labela.left + SpeedA
End If

If (labelb.Left + labelb.Width < 14000) Then
labelb.Left = labelb.Left + SpeedB
End If

Loop

This will loop until the right edge of both controls reach the edge of the form. During each loop, if each control hasn't reached the edge yet, then that label is moved forward by its precalculated speed.
The If statements are necessary to keep each control from moving past the edge because labela might reach the edge before labelb does, thus the loop will continue (the loop exits when both controls have reached the edge). However, since labela has gone as far as it should, we do not want to move it, so we only move labelb.

Hope this helps.

Steve
 
thank you for your help steve.

sbd510 rocks

the programme was great you solved my problem thank you very much

i have spent bloody hours trying to work the bloody thing out.






 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top