CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2001
    Location
    Belgium
    Posts
    39

    Background processing

    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 ;-)


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Background processing

    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
    [email protected]

    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
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Jul 2001
    Location
    Belgium
    Posts
    39

    Re: Background processing

    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!)


  4. #4
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Background processing

    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
    [email protected]

    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
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured