slowing down a loop

O

OD

I have a access form with a button to show a ticker tape.

What I would like to do is slow down the loop, something like sleep 500,
below is my code.


Private Sub TickerButton_Click()
Dim x, y, z, done As Integer
Dim varMyStr, varMyMsg As String
Dim varCounter As Integer


x = 0
y = 0
z = 0
varMyStr = ("It's hard to soar with eagles, when you fly with turkeys...")

x = Len(varMyStr)
y = 1
z = 20
done = 1

Do While done <= 10
done = done + 1
varMyMsg = Mid(varMyStr, y, z)
Me.TitleLable.Caption = varMyStr
varMyStr = Mid(varMyStr, 2, x - 1)
varMyMsg = Mid(varMyMsg, 1, 1)
varMyStr = varMyStr + varMyMsg
????Sleep 500
Loop
End Sub

this displays a message in a Lable on the form
 
O

OssieMac

If you lookup Timer function in VBA help then you should find a code example
using a loop.
 
M

Marshall Barton

OD said:
I have a access form with a button to show a ticker tape.

What I would like to do is slow down the loop, something like sleep 500,
below is my code.


Private Sub TickerButton_Click()
Dim x, y, z, done As Integer
Dim varMyStr, varMyMsg As String
Dim varCounter As Integer


x = 0
y = 0
z = 0
varMyStr = ("It's hard to soar with eagles, when you fly with turkeys...")

x = Len(varMyStr)
y = 1
z = 20
done = 1

Do While done <= 10
done = done + 1
varMyMsg = Mid(varMyStr, y, z)
Me.TitleLable.Caption = varMyStr
varMyStr = Mid(varMyStr, 2, x - 1)
varMyMsg = Mid(varMyMsg, 1, 1)
varMyStr = varMyStr + varMyMsg
????Sleep 500
Loop
End Sub

this displays a message in a Lable on the form


Not sure I would do it that way instead of using a timer,
but maybe this is what you are looking for:
http://www.mvps.org/access/api/api0021.htm
 
O

OssieMac

Curiosity got the better of me as to what you were trying to do so I had to
test your code and see what happened. I am assuming that you want a scrolling
message and if so this is what I came up with.

Private Sub TickerButton_Click()
Dim x, y, z, done As Integer
Dim varMyStr, varMyMsg As String
Dim varCounter As Integer
Dim PauseTime, Start, Finish, TotalTime

x = 0
y = 0
z = 0
varMyStr = ("It's hard to soar with eagles, when you fly with turkeys...")

x = Len(varMyStr)
y = 1
z = 20
done = 1

Do While done <= 100
done = done + 1
varMyMsg = Mid(varMyStr, y, z)
Me.TitleLable.Caption = varMyStr
varMyStr = Mid(varMyStr, 2, x - 1)
varMyMsg = Mid(varMyMsg, 1, 1)
varMyStr = varMyStr + varMyMsg

PauseTime = 0.1 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
Loop
End Sub
 
O

OD

I had looked at the timer, but i not under stand how it worked. Just tried
it, it did what I wanted it to do.

Thanks You and Marshall Barton for the help
OD
 
O

OD

Thanks Marshall I looked at the web site, but I tried what OssieMac suggested
and it works for now.

Thanks for the help. More than one way to skin a kittie
OD
 
D

Dale Fye

Personally, I think I would use the Forms Timer event. Something like:

Private Sub TickerButton_Click

if me.TickerButton.Caption = "Start ticker" then
me.TitleLable.Tag = "It's hard to soar with eagles, when you fly with
turkeys..."
me.timerinterval = 500
me.TickerButton.Caption = "Stop ticker"
else
me.timerinterval = 0
me.TickerButton.Caption = "Start ticker"
endif

End Sub

Private sub Form_Timer

Static leftChar as intger
Dim strScroll as string

leftChar = leftChar + 1
if leftChar = > len(me.TitleLabel.Tag) + 6 then leftChar = 1

strScroll = me.TitleLabel.Tag & " " & me.TitleLabel.Tag
me.TitleLabel.Caption = Mid(strScroll, leftChar, 20)

End Sub


--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
D

Dymondjack

Just out of curiousity, does this Sleep API suspend activity across the
entire computer? I've used it before (abliet for a brief amount of time),
and noticed that everything from the blinking cursor to moving the mouse
across the screen stops for the specified amount of time. If that is the
case, the practicality of the the API might be rather limited (if one were to
'Sleep' to wait for a file to unlock, would the existing process on the file
continue during this time, or would that sleep as well...).

Food for thought
 
D

Dale Fye

Don't know, have never used the Sleep API.

However, I have had a Pause subroutine that I occassionally use for ages.

Public Sub Pause(Seconds As single)

'inserts a pause in code execution, while allowing other
'windows events to occur
Dim MyTimer As Long

MyTimer = Timer
While Timer - MyTimer < Seconds
DoEvents
Wend

End Sub

I generally just insert a Pause .5 to get a 1/2 second delay in code
execution.

--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
M

Marshall Barton

Dymondjack said:
Just out of curiousity, does this Sleep API suspend activity across the
entire computer? I've used it before (abliet for a brief amount of time),
and noticed that everything from the blinking cursor to moving the mouse
across the screen stops for the specified amount of time. If that is the
case, the practicality of the the API might be rather limited (if one were to
'Sleep' to wait for a file to unlock, would the existing process on the file
continue during this time, or would that sleep as well...).


It's not supposed to. Maybe there was another execution
thread that was dependent on the sleeping procedure??
 

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