Scolling Text

tt1611

Registered User.
Local time
Today, 13:43
Joined
Jul 17, 2009
Messages
132
Can someone please look at this code for me. I got this code of another forum (forgot the user's name so unable to reference) but all I am trying to do is get text to scroll from left to right in smooth transition.

The below code works


Code:
Private Sub cmdscroll_Click()
Dim x As Integer, y As Integer
Dim Start, delay
For x = 1 To 100
Start = Timer
delay = Start + 1
Do While Timer < delay
lbl1.Caption = Mid(lbl1.Caption, 2) & Left(lbl1.Caption, 1)
lbl2.Caption = Mid(lbl2.Caption, 2) & Left(lbl2.Caption, 1)

DoEvents
Loop
DoEvents
Start = Timer
delay = Start + 1
Next x
End Sub

but it makes the text scroll too fast. The answer he had was to increase the delay time ie
Code:
delay = start+3000
. I have tried that to no avail.

My form has a command button as you can see from the code and 2 label boxes. The cmd button should start the scroll once clicked.

Thanks
 
This is because your scrolling inside the loop:
Code:
Do While Timer < delay
lbl1.Caption = Mid(lbl1.Caption, 2) & Left(lbl1.Caption, 1)
lbl2.Caption = Mid(lbl2.Caption, 2) & Left(lbl2.Caption, 1)

DoEvents
Loop
Instead do it outside...
Code:
Do While Timer < delay

DoEvents
Loop
lbl1.Caption = Mid(lbl1.Caption, 2) & Left(lbl1.Caption, 1)
lbl2.Caption = Mid(lbl2.Caption, 2) & Left(lbl2.Caption, 1)

Even better dont use the loop but use a API Sleep:
Code:
Option Compare Database
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub cmdScroll_Click()
    Dim x As Integer
    For x = 1 To 100
        Sleep 1000
        lbl1.Caption = Mid(lbl1.Caption, 2) & Left(lbl1.Caption, 1)
        lbl2.Caption = Mid(lbl2.Caption, 2) & Left(lbl2.Caption, 1)
        DoEvents
    Next x
End Sub
 
Namliam
Thanks for this. This works like a charm.
Question; This scrolling text will be on an updatee dashboard so I need the loop to be somewhat infinite.

For x = 1 to ???
I guess is my question to keep the loop going.

Any thoughts. I really appreciate your help. I have been able to adjust the speed of the scroll by decreasing the sleep value which is great.
 
Do while Time() < #18:00:00#
...
Loop

that would stop the scrolling at 18:00 ... maybe that would work???

Otherwize if you want true 'infinity'
Do while True
....
Loop
 
You have been a great help. I have one final question. On that same form I am using as my dashboard, I have a timer event that is running that runs queries on textboxes every second. This includes date and time textboxes that act as a running clock (ie timer() requerying every second).

When I implement that above loop with the sleep timer, the clock stops/struggles to keep in sync and will only run when the scrolling text is stopped from the compiler. My code for the current form is as so.

Please note the examples I had above were only a test of what I really wanted. I have been able to look at your examples and make the necessary changes to fit my project. The code below is live code. Please advice on this if you can ie if there is a way where I can a) run both events under one timer or b) have 2 timer evernts like I do now work concurrently

Private Sub Form_Timer()

Dim a As Integer
a = CInt(Me.txtopentoday.Value)
If a >= 5 Then
Me.txtopentoday.ForeColor = 255

Else
Me.txtopentoday.ForeColor = 0
End If
Me.txtdate.Requery
Me.txttime.Requery
Me.txtopentoday = DLookup("[Tickets Opened Today]", "[NewTickets]")
Me.txtclosedtoday = DLookup("[Tickets Closed Today]", "[TodayClosed]")

Me.txtinprog = DLookup("[Total Acknowledged Tickets]", "[TotalInProg]")
Me.TXTHOLD = DLookup("[Total Hold Tickets]", "[TotalHold]")

Me.txt14.Requery

End Sub

txt14 in this case is the txtbox where my scrolling text is.

Thanks again for all your help.
 
Have you considered using a status bar on your form. You can setup your own panels and hav the info diplayd there. Also you can use built in Date and Time values that work independantly from anything else that is going on in the form.

This is an MS Access AxtiveX control

attachment.php
 

Attachments

  • statusbar.JPG
    statusbar.JPG
    28.6 KB · Views: 163
Hey Crake
A very good idea. The only thing is I have my dashboard mounted up on a 22" Monitor in our office. I needed to have both the ticketing info as well as any updates from our dashboard that pulls info from another table. So not sure if this will be large enough to display.
 
The status bar is sizeable across the total width of any form, irespective of size. The wider the form the more space you have to play with. Each individual panel can be sized independantly.
 

Users who are viewing this thread

Back
Top Bottom