By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,971 Members | 900 Online
Bytes IT Community
Submit an Article
Got Smarts?
Share your bits of IT knowledge by writing an article on Bytes.

Auto Scroll text in a static label

100+
P: 133
Well i cannont remember where i picked this code up, but i have seen
it asked for in many forums, Many times so i thought i'd add it here (Since this is my favourite forum).


Auto scroll text in a static label.

To your Form...
Add 1 label
Add 1 command Button
Add 1 Timer
Add 1 Textbox

Code: ( vb 6 )

DECLARATIONS:

Expand|Select|Wrap|Line Numbers
  1.     Dim s As Integer
  2.     Dim dta As String
  3.  
  4.  
  5. Private Sub Command1_Click()
  6.     Label1.Caption = ""
  7.     Timer1.Enabled = True
  8.     Timer1.Interval = 100
  9.     Label1.Width = 4335
  10.     Label1.Font = "Palatino Linotype"
  11.     Label1.Font.Size = 13
  12.     Label1.Font.Bold = False
  13. End Sub
  14.  
  15. Private Sub Timer1_Timer()
  16.  
  17.     ' put your text here in dta string
  18.     dta = "Whatever text you want to scroll" & Space$(40)
  19.     s = s + 1
  20.     Label1.Caption = Mid(dta, 1, s)
  21.     If Len(Label1.Caption) >= 42 Then Label1.Caption = Right(Label1.Caption, 41)
  22.  
  23.     If s = Len(dta) Then
  24.         Label1.Caption = ""
  25.         s = 0
  26.     End If
  27. End Sub
It is very self explanatory very easy to use just cut & paste code , and then add command button, timer and label.

Hope this helps , if you like this i have 85 more basic / very usefull how to's ready to use code samples.

GobbleGob.
Thanks for reading.
Mar 13 '08 #1
Share this Article
Share on Google+