Scrolling text

A

asukuo

Hi all.
Following Access VBA code, scroll text in a label name lblScroll of a Form.
- Timer interval 250
- On Timer following code:

Private Sub Form_Timer()
Static strMsg As String, intLet As Integer, intLen As Integer
Dim strTmp As String
Const TXTLEN = 40
If Len(strMsg) = 0 Then
strMsg = Space(TXTLEN) & "Welcome all" & Space(TXTLEN)
intLen = Len(strMsg)
End If
intLet = intLet + 1
If intLet > intLen Then intLet = 1
strTmp = Mid(strMsg, intLet, TXTLEN)
lblScroll.Caption = strTmp
End Sub

How gets same results in Excel Userform using API ?
Regards, John.
 
P

Patrick Molloy

Add two buttons - cmdStart and cmdStop to a userform,
plus a label- lblScroll
Add the following code - I used yours without any
changes...


Option Explicit
Private bStop As Boolean
Sub New_Timer()
Dim t As Double
Do
t = Timer
Form_Timer
Do
DoEvents
Loop Until Timer > (t + 0.25)
Loop Until bStop
End Sub

Private Sub Form_Timer()
Static strMsg As String, intLet As Integer, _
intLen As Integer
Dim strTmp As String
Const TXTLEN = 40
If Len(strMsg) = 0 Then
strMsg = Space(TXTLEN) & "Welcome all" & _
Space(TXTLEN)
intLen = Len(strMsg)
End If
intLet = intLet + 1
If intLet > intLen Then intLet = 1
strTmp = Mid(strMsg, intLet, TXTLEN)
lblScroll.Caption = strTmp
End Sub
Private Sub cmdStart_Click()
bStop=False
Call New_Timer
End Sub
Private Sub cmdStop_Click()
bStop = True
End Sub

ru the form. click the start button to begin scrolling &
the stop button to stop it. Thje keys are (1) the boolean
bStop which is used to control the outer do-loop and
the 'timer' do-loop that controls the wait period after
calling the scrolling sub (ie your code)
Essentially the sub New_Timer replaces the in-built
Access timer.

Patrick Molloy
Microsoft Excel MVP
 
A

asukuo

Thanks Patrick.
Regards, John.
Patrick Molloy said:
Add two buttons - cmdStart and cmdStop to a userform,
plus a label- lblScroll
Add the following code - I used yours without any
changes...


Option Explicit
Private bStop As Boolean
Sub New_Timer()
Dim t As Double
Do
t = Timer
Form_Timer
Do
DoEvents
Loop Until Timer > (t + 0.25)
Loop Until bStop
End Sub

Private Sub Form_Timer()
Static strMsg As String, intLet As Integer, _
intLen As Integer
Dim strTmp As String
Const TXTLEN = 40
If Len(strMsg) = 0 Then
strMsg = Space(TXTLEN) & "Welcome all" & _
Space(TXTLEN)
intLen = Len(strMsg)
End If
intLet = intLet + 1
If intLet > intLen Then intLet = 1
strTmp = Mid(strMsg, intLet, TXTLEN)
lblScroll.Caption = strTmp
End Sub
Private Sub cmdStart_Click()
bStop=False
Call New_Timer
End Sub
Private Sub cmdStop_Click()
bStop = True
End Sub

ru the form. click the start button to begin scrolling &
the stop button to stop it. Thje keys are (1) the boolean
bStop which is used to control the outer do-loop and
the 'timer' do-loop that controls the wait period after
calling the scrolling sub (ie your code)
Essentially the sub New_Timer replaces the in-built
Access timer.

Patrick Molloy
Microsoft Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top