How can i slow this down?

Dillon

Member
Joined
Nov 22, 2008
Messages
6
Programming Experience
Beginner
I'm am making a marquee in vb, and I got it to work! but it is scrolling really fast, i cant find how to slow it down... I tried to set the value of c higher, trying to slow the loop down a bit, but it didnt work :confused:, any help is greatly appreciated! Thanks!

-Dillon

Heres the code, when the button is clicked:

VB.NET:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

sasa:
        For c As Integer = 1 To 500 Step 1
            c = c + 1
            If c = 500 Then
                GoTo asas
            End If
        Next c
asas:
        Do
            Label1.Top = Label1.Top + 1
            If Label1.Top = pnl.Width Then
                Label1.Top = 1
                GoTo sasa
            End If

        Loop
    End Sub
 
Use a Timer, set the Label location in Tick event, use timer Interval to control the speed.
 
Please never use GoTo again. This will have the same net result without using spaghetti code:
VB.NET:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim keepDoing As Boolean = True

    Do
        For c As Integer = 1 To 499 Step 1
            c = c + 1
        Next c

        Do
            Label1.Top = Label1.Top + 1
            If Label1.Top = pnl.Width Then
                Label1.Top = 1
                keepDoing = False
            End If

        Loop While keepDoing
    Loop
End Sub
There's never a need to use GoTo.
 
Back
Top