Click to See Complete Forum and Search --> : Background processing


Sephozzy
August 16th, 2001, 03:43 AM
I have the following code:


private Sub cmdLink_Click()
on error GoTo ErrorHandler

Dim Source as string

cdlGetFile.DialogTitle = "Link Database"
cdlGetFile.InitDir = App.Path
cdlGetFile.Filter = "database|link.mdb"
cdlGetFile.ShowOpen
Source = cdlGetFile.FileName
ImportCPLink Source
Exit Sub

ErrorHandler:
MsgBox Err.Description, vbCritical, "error"
Exit Sub
End Sub

...
private Sub ImportCPLink(Source as string)
set dbsLink = OpenDatabase(Source)
set rstCompany = dbsLink.OpenRecordset("COMPANY", dbOpenForwardOnly)

Do While Not rstCompany.EOF
' do all sorts of stuff
rstCompany.MoveNext
Loop

rstCompany.Close
dbsLink.Close
End Sub




Everything works fine BUT (there's always a but) my window isn't updated while the program is processing the while loop. Since I'm fairly new to VB I don't know a way to put the processing in the background or another way to update the GUI.

Please help out a C++ programmer who is stuck with VB for now. Just as I rate answers in the VCC forums I will rate yours if it helps ;-)

Cakkie
August 16th, 2001, 04:15 AM
The application probably "freezes" when doing the WHILE LOOP. You can use DoEvents to return control to the system to do some things like updating the screen. Just place it somewhere in the loop and things should be way better.

Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook

Sephozzy
August 16th, 2001, 04:27 AM
Thanks, it worked just fine. Nice to see other people from Belgium on the forums ;-)

BTW nice signature but there's a typo in there: idot-proof should probably be idiot-proof, if it's intentional just disregard the remark (DOH!)

Cakkie
August 16th, 2001, 04:32 AM
Indeed nice to see some Belgium people here. About the sig, corrected it, unless i made another idiotic mistake, but hey, as the sig says, the universe is winning, and sometimes we all belong to the idiot part of the world.

Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook