Results 1 to 4 of 4

Thread: Looping Problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2000
    Posts
    16

    Angry

    I have been writing this code and i can't seem to get it to work. The form contains a line and a timer. I can't get it out of the constant loop. If anyone can help it would be greatly appreciated.

    The Code is like this:
    General declarations
    Option Explicit
    Dim x1
    Dim x2
    Dim y1
    Dim y2
    Dim R
    Dim G
    Dim B
    Dim intcount As Integer
    Public Sub Intervals()
    Dim make
    Dim go
    make = Timer
    Do Until go >= make + 0.14
    go = Timer
    Loop

    End Sub
    Private Sub Command1_Click()
    timer1.Enabled = True

    End Sub
    Private Sub Command2_Click()
    timer1.Enabled = False

    End Sub
    Private Sub timer1_Timer()
    R = Int(240 * Rnd)
    G = Int(240 * Rnd)
    B = Int(240 * Rnd)


    Do Until timer1.Enabled = False
    Randomize
    Line1.BorderColor = Int(RGB(R, G, B * Rnd))
    Line1.x1 = Int(Form1.Width * Rnd) + 1
    Line1.y1 = Int(Form1.Height * Rnd) + 1
    Line1.x2 = Int(Form1.Width * Rnd) + 1
    Line1.y2 = Int(Form1.Height * Rnd) + 1
    Intervals
    Cls
    Loop



    timer1.Enabled = False

    End Sub


    Thank you!!!


  2. #2
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    The following line produces an indefinete loop...

    Code:
    ...
    
    Do Until timer1.Enabled = False 
    Randomize 
    Line1.BorderColor = Int(RGB(R, G, B * Rnd)) 
    Line1.x1 = Int(Form1.Width * Rnd) + 1 
    Line1.y1 = Int(Form1.Height * Rnd) + 1 
    Line1.x2 = Int(Form1.Width * Rnd) + 1 
    Line1.y2 = Int(Form1.Height * Rnd) + 1 
    Intervals 
    Cls 
    Loop
    
    ...
    what it need is that the timer1.enabled = false be inside the loop for the loop to be effective

    example:

    right before the 'Cls' you should put an if statement that checks to see if whatever ur trying to do happens so that you can place inside the code if timer1.enabled = true or false;

    Code:
    If something happens Then
        Timer1.Enabled = False
    End If
    Hope that helps... msg me if it doesnt...
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2000
    Posts
    16
    I tried this to a certain extent. I must be using the wrong event inside th if then statement. I can't really figure it out yet. Any hints?? Thanks

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Thumbs up

    The event wont ever get fired since you won't let it.

    Put a doevents in the interval loop
    Code:
    Do Until go >= make + 0.14 
     go = Timer 
     Doevents
    Loop while forms.count 'avoid hang up if you close your app while in the loop
    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