Results 1 to 10 of 10
  1. #1
    3 Star Lounger
    Join Date
    Feb 2003
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Moving Objects on a VB Form (vb 6)

    I made a Form (Blank2.frm) with 4-5 images on it. Three of the objects (Dozer, Truck and Cars) are set to move on a Timer event which is triggered by the Form_Load. This all works fine as a stand-alone project. The problem is I then imported this Form (Blank2) into my main Project and opened it with Blank2.Show. Now the "animation" doesn't work. How do I get the objects to Move? I tried changing the code from the Form_Load event to Form_Activate. This didn't work. What is missing?
    Here's the code. And I will attach the form.

    Option Explicit
    Dim DeltaX As Integer


    Private Sub Timer1_Timer()

    Dozer.Move Dozer.Left - DeltaX
    Truck.Move Truck.Left + DeltaX
    Cars.Move Cars.Left + DeltaX

    If Dozer.Left <= Truck.Left + 150 Then
    Truck.Move Truck.Left - DeltaX * 5
    End If

    If Dozer.Left <= Cars.Left + 600 Then
    Cars.Move Cars.Left - DeltaX * 6
    End If

    End Sub




    Private Sub Form_Load()
    Timer1.Interval = 75 ' Set Interval.
    DeltaX = 100 ' Initialize variables.

    End Sub

  2. #2
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Moving Objects on a VB Form (vb 6)

    Try putting breakpoints on the Form_Load and Timer1_Timer lines and see if the code actually fires.

    I just tried a quick & dirty test, and it worked fine for me.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  3. #3
    3 Star Lounger
    Join Date
    Feb 2003
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Moving Objects on a VB Form (vb 6)

    Thanks Bryan,
    Yes the commands are firing. But, AFTER the end of the everything else.

    I've worked some more on this project and have attached an expanded version. It's almost working now.
    The new version has a Form1 (the start up form) with a cmd button to start the previous form (Blank2) witch contains the animation.
    What I'm trying to acheive is a more colorful "progress bar" that will run WHILE doing other tasks in the background ( in this
    case opening a large Excel file which takes 15-20 seconds).
    The current attached version opens the xl file, THEN does the animation. I tried " Blank2.Show vbnonmodal" , thinking the "nonmodal" would allow simultaneous task operation, but this didn't quite do it

  4. #4
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Moving Objects on a VB Form (vb 6)

    This is what I think is happening, and I'm sure I'll be corrected when I'm wrong.

    VB applications are single threaded. Which means that they can only do one thing at a time.

    So what I see is happening is that you open the "animation" form and then you run a routine to open excel and the workbook. While that routine is running, the timer time comes and goes, but it can't fire the Timer event because you GetXL procedure is running.

    As soon as the app finished the GetXL Procedure, the Timer event can fire and cause your animations to animate.

    I don't know if there is anyway to get what you want to happen, to actually happen in VB.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  5. #5
    3 Star Lounger
    Join Date
    Feb 2003
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Moving Objects on a VB Form (vb 6)

    OK, Yes you are correct about the sequence of how it is currently working.

    BUT if that is the case -- single threaded VB --, how can a standard ProgressBar (Microsoft Windows Common Componets) work in the fore as other events are fired in the background?

    A few yrs back I installed a PBar in a spreadsheet and got it to show + increment while other things occurred "off stage" by launching the PB with "obj.Show vbnonmodal."

    Perhaps xl is multithreaded????
    If I remember correctly I incremented it by actually placing an "increment cmd" periodically throughout the code that was running in the backgrnd. the Increments were 5-10% at a time so I didn't need too many of these to fire. In ther current project, I would not be able to set these "increment cmds" in the GetXL task.
    Does any of this help?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Moving Objects on a VB Form (vb 6)

    I fear that this is an issue with Excel, although I don't know for sure. Normally, applications allow other processes to handle events from time to time - the instruction to do that in your own application is DoEvents. This is a relatively high overhead. I suspect that Excel doesn't allow event processing while loading a workbook for efficiency reasons - loading large or complicated workbooks might take forever if other processes keep on interfering.

  7. #7
    3 Star Lounger
    Join Date
    Feb 2003
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Moving Objects on a VB Form (vb 6)

    Thanks for the input, Hans. Maybe we should go at this from a different angle:

    In VB 6.0 when I click on: Projects=>Components=>Microsoft Windows Common Controls 6.0 (Sp4) =>ProgressBar I get a PB control. Can I make it work (show incremental movement) at the same time that Excel is loading in the background? If so, how?

    I obviously don't have much experience in this area, but I was under the impression that assigning a modality ( modal vs nonmodal) had something to do with releasing control to another app or procedure. Hans and Bryan, if I understand you correctly, you are saying that VB is "single threaded" and won't work symultaneously with another app and that Excel doesn't like sharing either, especially while loading a file.

    Maybe we need to teach these kids some manners ! <img src=/S/bouncenburn.gif border=0 alt=bouncenburn width=31 height=31> <img src=/S/bif.gif border=0 alt=bif width=70 height=28>

  8. #8
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Moving Objects on a VB Form (vb 6)

    <hr>how can a standard ProgressBar (Microsoft Windows Common Componets) work in the fore as other events are fired in the background?<hr>
    You actually answered your own question,
    <hr>"I incremented it by actually placing an "increment cmd" periodically throughout the code that was running in the backgrnd"<hr>
    Unfortunatley I don't know of anyother way of doing it.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  9. #9
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Moving Objects on a VB Form (vb 6)

    <hr>won't work symultaneously with another app <hr>
    It fires events with another app running. I think the problem stems from the fact that you are opening Excel, and the workbook, from your application.

    That is where the single threadedness of VB is causing the problem. VB has to wait until the procedure that loads Excel and the workbook to finish running to continue on with the code. Which means that no events will fire until that procedure is done running.

    If you step through the code, you will see that the VB app appears to stop on the lines that load Excel and the workbook until they are done loading, but that is just VB waiting until that line of code is finished running before it can move on to the next line.

    Does that make sense?
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  10. #10
    3 Star Lounger
    Join Date
    Feb 2003
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Moving Objects on a VB Form (vb 6)

    Yes, unfortunately it does. Thanks, though, for helping me see what is happening. I guess the user will just have to wait patiently with a few labels (One Moment Please.... ) etc and maybe an image of a clock?? --- Where can I find a good Clock clip art?

    I will also try to work with Excel to make my workbook smaller (and faster).

    Thanks

Posting Permissions

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