dcsimg
Results 1 to 8 of 8

Thread: [RESOLVED] Looping while Form is active

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,073

    Resolved [RESOLVED] Looping while Form is active

    I show Form2 and then go into a loop. What can I put in the loop to test so that when Form2 is closed (clicking on X button or command button) I can exit the loop

    Code:
      '
      '
      Form2.Show
      
      Do While True
        DoEvents
         '
         ' What code here to exit loop
         '
      Loop
      '
      '


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,449

    Re: Looping while Form is active

    You can use a form-level boolean variable and test within the loop whether or not the variable is set to true. Remember to set it to false before entering the loop
    Code:
    ...
       If bAbort = True Then Exit Do
    ...
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,073

    Re: Looping while Form is active

    I'm aware of using a switch but I was thinking without setting a variable; maybe something like If Form2.Active = False Then Exit Do or something that is already part of the Form properties


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,946

    Re: Looping while Form is active

    You could use the tag or some other property of the form but does it really matter? Either way you are using a switch.
    Why do you need it to stay in the loop while the other form is shown and you do realize that the controls on the current form will still be active which could possibly cause unexpected results due to the doevents

    Is there a reson that you are not using the modal flag instead?

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,449

    Re: Looping while Form is active

    If Form2 is unloaded and you later reference Form2 to test a property in the Do:Loop, then Form2 will re-load
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,423

    Re: Looping while Form is active

    Is there a valid reason to stay waiting on Form1 while Form2 is being shown? Is there any code that you need to execute during that time? if not, if all you want is just wait there then you should simply show your Form2 modally:
    Code:
    Form2.Show vbModal

  7. #7

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,073

    Re: Looping while Form is active

    OK, modal is what I was looking for. Thanks all


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width