This VB project will scroll text across a form. Add 2 text boxes
(named txtMessage and txtScroll) and a button (named
Command1) to a form then paste this code to the form's module.
Code:
Option Explicit
Private Sub Form_Load()
Me.Left = 0
Me.Width = Screen.Width
txtScroll.Locked = True
txtScroll.Text = ""
txtScroll.BorderStyle = 0
txtScroll.BackColor = vbBlack
txtScroll.ForeColor = vbWhite
txtScroll.Top = 0
txtScroll.Left = 0
txtScroll.Height = 240
txtScroll.Width = Me.Width
Command1.Caption = "Add Text"
Command1.Width = TextWidth(Command1.Caption) + 220
txtMessage = "Add you're message here"
txtMessage.Width = TextWidth(txtMessage) + 300
End Sub
Private Sub Form_Activate()
txtMessage.SetFocus
'prime txtScroll
Do Until TextWidth(txtScroll) >= txtScroll.Width
txtScroll = txtScroll & "."
Loop
txtScroll = txtScroll & "First message is scrolling on to form..."
StartMessage
End Sub
Private Sub Command1_Click()
'add message
txtScroll = txtScroll & txtMessage
End Sub
Private Sub txtMessage_GotFocus()
txtMessage.SelStart = 0
txtMessage.SelLength = Len(txtMessage.Text)
End Sub
Private Sub StartMessage()
Do Until Trim(txtScroll.Text) = ""
DoEvents
If TextWidth(txtScroll.Text) >= txtScroll.Width Then
'strip first char.
txtScroll.Text = Right(txtScroll.Text, Len(txtScroll.Text) - 1)
Else
'add a space to end of message
txtScroll = txtScroll & " "
End If
Pause 0.075 'changes speed default=.075 seconds/character
Loop
MsgBox "No more messages"
End Sub
Private Sub Pause(gSeconds As Single)
Dim gCurrent As Single
'operations wait for gSeconds to ellapse
gCurrent = Timer
Do While Timer - gCurrent < Val(gSeconds)
DoEvents
Loop
End Sub
Note: To change the scroll speed adjust the Pause call.