Has anyone had problems with this? On two machines I have, both with latest
releases and sp1 for Ofiice 2003 the following code runs 'like a dog' and
hogs 100% of cpu cycles, even with no other user processes executing. The
letters come out very, very slowly. Usually the first line comes after a
long wait, the next part comes regularly as is hoped for.

Private Sub TypeString(str As String, delay As Long)
Dim iIndex As Long
Dim iStringLength As Long
Dim oDoc As Document
Set oDoc = ActiveDocument
Dim oRange As Range
Set oRange = oDoc.Content
oRange.Text = ""
iStringLength = Len(str)
For iIndex = 1 To iStringLength
oRange.Collapse wdCollapseEnd
oRange.Text = Mid$(str, iIndex, 1)
DoPause delay
Next iIndex
End Sub

Private Sub DoPause(secs As Long)
Dim fFinish As Single
fFinish = Timer + secs
Do While Timer < fFinish
DoEvents
Loop
End Sub

Public Sub ShowMessage()
TypeString "Happy New Year" & vbCrLf & "from" & vbCrLf & "Joe", 2
End Sub

I run ShowMessage via alt+F8 and double clicking list box entry.
Perhaps there is something else wrong with the code?

Thanks

--
Joe

Re: Doevents in Word 2003 by Joe

Joe
Sat Jan 03 11:52:13 CST 2004

"Malcolm Smith" <malcolm.smith@DragAndDrop.com> wrote in message
news:memo.20040103174147.2436B@mksmith.aits-uk.net...
> Joe
>
> I wouldn't say that it was hogging the CPU. The loop is going around and
> around all the time. That's fair enough; but the DoEvents is making sure
> that nothing else is blocked.
>
> So, the CPU is going to be busy for 2 seconds per character doing nothing
> but to go in a loop and cast a DoEvents.
>
> If you ran something else then that second application wouldn't take any
> longer because the Word application isn't hogging the CPU.
>
> Do you really mean to spend a two second pause between each character?
>
> Also, note that you have in your DoPause() function a variable which holds
> a Single type but you put into it a Long type. Do you mean to do this?

Not sure what you mean. Timer returns a single, I add on a long for the
finish time.
>
> - Malc
What I mean is that the letters don't come out at a regular pace, I was
trying to get a two second pause between each letter, what I get is periods
of inactivity followed by five or six leters at a time. When I look in task
manager my machine is running at 100%.

Thanks for the help.

--
Joe