Results 1 to 3 of 3

Ending Do While Loop out of a sub

Threaded View

roldy Ending Do While Loop out of a... 01-22-2020, 11:59 AM
AlphaFrog Re: Ending Do While Loop out... 01-22-2020, 12:16 PM
roldy Re: Ending Do While Loop out... 01-22-2020, 12:24 PM
  1. #1
    Registered User
    Join Date
    12-14-2018
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    28

    Ending Do While Loop out of a sub

    This code I'm working on works in conjunction with SolidWorks but the problem exists in vba. A bit of context first. I have two text boxes that show information regarding two different object selections. The first text box, controlpath, shows the name of the sketch selection. The second textbox, object, shows the name of an extrusion object and also displays the parent object to the selection in a 3rd text box, terminating object. When I click on either the 1st or 2nd text box, I have a Do While Loop that loops until I make a selection in SolidWorks. When a selection has been made, a subroutine runs to retrieve information. This information is displayed in the text box and I exit the Do Loop if the selection is valid. Outside of the Do While Loop I have a call back into the same textbox MouseUp event that I was currently in. This is done so that my MouseUp event remains triggered so that the user can make a different selection for that text box without having to click back in it. I would like to keep this feature. Also, at anypoint in the Do While Loop the user can select the other text box, which has basically the same looping code/MouseUp event call. When an object has been selected for the 2nd text box, the 3rd text box unlocks and I can click on it and this object is highlighted (selected) in SolidWorks. If I click on the 3rd text box and when it's MouseUp event private sub ends, I drop back into the previous text boxes Do While Loop.

    Herein lies the problem. When I click into another text box, while I'm in a different text box looping, is there a way to exit text box A's MouseUp event from text box B's? Is there a better way of coding a text box to continually have a MouseUp event until I select a different text box?

    pseudo code:

    Private Sub objTxtBox_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    
       Do While objSelection < 2
          DoEvents
          GetObjName objSelection
          objname.text = objSelection.name
          If validsel = true then
             Exit Do
          End if
       Loop
    
       objTxtBox_MouseUP(1,0,X,Y)
    
    end sub
    
    
    Private Sub sketchTxtBox_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    
       Do While sketchSelection < 2
          DoEvents
          GetObjName sketchSelection
          sketchname.text = sketchSelection.name
          If validsel = true then
             Exit Do
          End if
       Loop
    
       sketchTxtBox_MouseUP(1,0,X,Y)
    
    end sub
    Last edited by roldy; 01-22-2020 at 12:24 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Never Ending Loop
    By oggyoggy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-26-2019, 03:42 PM
  2. Help on ending Loop
    By TimBrowne in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-11-2016, 07:28 AM
  3. [SOLVED] Do Until loop not ending
    By Dralky in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-15-2014, 09:57 PM
  4. Do until Loop not ending
    By Alexm963 in forum Word Programming / VBA / Macros
    Replies: 6
    Last Post: 12-28-2012, 05:09 PM
  5. [SOLVED] ending a sub FOR loop in a main FOR loop
    By samkumar in forum Word Programming / VBA / Macros
    Replies: 2
    Last Post: 09-27-2012, 05:35 AM
  6. Ending a Loop
    By kirsty in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-25-2010, 01:11 PM
  7. Never ending loop
    By Theodjinn in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-23-2008, 04:08 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1