PDA

Click to See Complete Forum and Search --> : Timer Replacement


kokopeli
Oct 3rd, 2000, 11:29 PM
I was working on something for Chopper1's post, but it was pretty much junk. My question is, how can I do this without a timer control. I couldn't figure how to code the GetTickCount and make it work. Seemed to be going into an infinite loop, and not even showing the form.

Private Sub Timer1_Timer() ' interval set to 10

Dim i As Integer
For i = 0 To Shape1.Count - 1 ' I have four squares,
If Shape1(i).Left > 50 Then ' each a little bigger
Shape1(i).Top = Shape1(i).Top - 20 ' than the one inside
Shape1(i).Height = Shape1(i).Height + 40
Shape1(i).Width = Shape1(i).Width + 40
Shape1(i).Left = Shape1(i).Left - 20
Else
Shape1(i).Left = 1800 'innermost square is of these dimensions
Shape1(i).Top = 1680
Shape1(i).Height = 1935
Shape1(i).Width = 2175
End If
Next i

End Sub


If you can answer this, could you show me with this code.

kedaman
Oct 4th, 2000, 02:31 AM
If you put the code in form_load event (did you?) then it won't load up the form until it exits the event. Try putting it into Form_Activate

kokopeli
Oct 4th, 2000, 12:35 PM
Would it be something like this
[CODE]
Private Sub Form1_Activate()
Dim i As Integer
Dim Start As Long


Do While Start < GetTickCount + 10 ' whatever
Start = GetTickCount
For i = 0 To Shape1.Count - 1 ' I have four squares,
If Shape1(i).Left > 50 Then ' each a little bigger
Shape1(i).Top = Shape1(i).Top - 20 ' than the one inside
Shape1(i).Height = Shape1(i).Height + 40
Shape1(i).Width = Shape1(i).Width + 40
Shape1(i).Left = Shape1(i).Left - 20
Else
Shape1(i).Left = 1800 'innermost square is of these dimensions
Shape1(i).Top = 1680
Shape1(i).Height = 1935
Shape1(i).Width = 2175
End If
Next i
Loop
End Sub

Balder
Oct 4th, 2000, 03:44 PM
To make your code more compact use "With, end With" like this (also runs faster):


Private Sub Form1_Activate()
Dim i As Integer
Dim Start As Long

Do While Start < GetTickCount + 10
Start = GetTickCount
For i = 0 To Shape1.Count - 1
With Shape1(i) '<--
If .Left > 50 Then
.Top = .Top - 20
.Height = .Height + 40
.Width = .Width + 40
.Left = .Left - 20
Else
.Left = 1800
.Top = 1680
.Height = 1935
.Width = 2175
End If
End With '<--
Next i
Loop
End Sub


I hope it work to nest it like this, sorry I canīt help you out with API GetTickCount

kedaman
Oct 5th, 2000, 06:17 AM
Start = GetTickCount'place this outside your loop or it won't end until something slows down the system :eek:
Do While Start < GetTickCount + 10
For i = 0 To Shape1.Count - 1
With Shape1(i)
If .Left > 50 Then
.Top = .Top - 20
.Height = .Height + 40
.Width = .Width + 40
.Left = .Left - 20
Else
.Left = 1800
.Top = 1680
.Height = 1935
.Width = 2175
End If
End With
Next i
doevents 'threading
Loop while forms.count 'exits when your app closes