Results 1 to 5 of 5

Thread: Timer Replacement

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    118
    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.
    Code:
    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.
    Kokopeli
    VB6 SP3

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    118

    Like this?

    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

    Kokopeli
    VB6 SP3

  4. #4
    Member
    Join Date
    Sep 2000
    Location
    Sweden
    Posts
    37

    Wink Use 'With, End With'

    To make your code more compact use "With, end With" like this (also runs faster):

    Code:
    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
    Balder = Viking God
    VB6/VC++ Enterprise Editions

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Code:
    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
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width