|
-
Dec 16th, 2006, 03:56 PM
#1
Thread Starter
Addicted Member
DoEvents
I guys I need your help again on DoEvents. As You all know, doevents will repaint the windows so users wil not be annoy when we have a long loop.
Here's the situation: I load records from access and write it to a text file for exmaple:
VB Code:
Public Sub LoadName()
Dim rc As Recordset, sql As String
sql = "SELECT * FROM name"
Set rc = cn.Execute(sql)
Do While Not rc.EOF
Writetext(rc("fistname"))
DoEvents
rc.MoveNext
Loop
PS: i have like 30 000 records.
As you see, the doevents will repaint the window on every record. I read the forum someone post an alternative way for a doevent for like 10 times by
VB Code:
For i = 0 To 900
i mod 10 = 0 then DoEvents
Next
But that only for a for ..next loop. Anybody know a way for the do ..while loop
-
Dec 16th, 2006, 03:58 PM
#2
Re: DoEvents
Simply have a variable that'll do lngA = lngA + 1 and check for the value of lngA. Math is very lightweight, especially in a compiled application.
-
Dec 16th, 2006, 04:02 PM
#3
Re: DoEvents
Or, you could use DoEvents only when it's needed by using the GetInputState() API function.
VB Code:
Private Declare Function GetInputState Lib "user32" Alias "GetInputState" () As Long
Public Sub LoadName()
Dim rc As Recordset, sql As String
sql = "SELECT * FROM name"
Set rc = cn.Execute(sql)
Do While Not rc.EOF
Writetext(rc("fistname"))
[COLOR=Red]If GetInputState Then DoEvents[/COLOR]
rc.MoveNext
Loop
There is a better API to use but I forgot what it is. This will speed up your loop a lot and free up some unneeded CPU.
-
Dec 16th, 2006, 04:39 PM
#4
Re: DoEvents
However, making an API call is far more costy than some little math You can combine these though (GetQueueState with some validation might be a better choice though).
-
Dec 16th, 2006, 06:09 PM
#5
Re: DoEvents
 Originally Posted by Merri
However, making an API call is far more costy than some little math  You can combine these though (GetQueueState with some validation might be a better choice though).
Yup, combining both would probably be even better.
-
Dec 17th, 2006, 04:49 AM
#6
Re: DoEvents
in a do while loop you can still bump a number:
I.e.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|