Results 1 to 3 of 3

Thread: [RESOLVED] [EXCEL] UserForms: Interrupt an Event by another one

  1. #1

    Thread Starter
    New Member RaytracerFFM's Avatar
    Join Date
    Jun 2010
    Location
    Frankfurt, Germany
    Posts
    15

    Resolved [RESOLVED] [EXCEL] UserForms: Interrupt an Event by another one

    Hi guys,

    really could use some help!

    Trying to keep this simple:

    I have a simple UserForm with 2 buttons. The run button sets a global variable to true and starts a loop, the cancel button just sets the global variable to false which is tested inside the loop.

    Code:
    Option Explicit
    
    Dim blState As Boolean
    
    Private Sub CommandButton_Cancel_Click()
    
        blState = False
    
    End Sub
    
    Private Sub CommandButton_Run_Click()
        Dim i As Integer
        
        i = 0
        blState = True
        
        While blState = True And i < 10000
            Debug.Print i
            i = i + 1
        Wend
    
    End Sub
    Problem is: As soon as the loop is entered, the UserForm will react to nothing.

    Maybe this is the normal behavior, but I need a way to stop the loop if the user decides to cancel out.

    Any ideas? That would be great!!!!

    I'm attaching the Workbook.

    cheers,
    ray
    Attached Files Attached Files
    Last edited by RaytracerFFM; Jun 14th, 2010 at 11:29 AM.

    If your query has been Solved, please mark it as such in the top menu via Mark Thread Resolved under Thread Tools

    Was a post helpful? Then you might care to rate it by clicking Rate This Post on the lower left hand side of it

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [EXCEL] UserForms: Interrupt an Event by another one

    Code:
    Option Explicit
    
    Dim blState As Boolean
    
    Private Sub CommandButton_Cancel_Click()
        blState = False
    End Sub
    
    Private Sub CommandButton_Run_Click()
        Dim i As Integer
        
        i = 0
        blState = True
        
        While blState = True And i < 10000
            DoEvents '<~~ Add this to your code
            i = i + 1
        Wend
    End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    New Member RaytracerFFM's Avatar
    Join Date
    Jun 2010
    Location
    Frankfurt, Germany
    Posts
    15

    Smile Re: [EXCEL] UserForms: Interrupt an Event by another one

    Something things are sooo simple, but you just don't see them

    I new i could rely on you koolsid

    Thanx a million.... again

    cheers,
    ray

    If your query has been Solved, please mark it as such in the top menu via Mark Thread Resolved under Thread Tools

    Was a post helpful? Then you might care to rate it by clicking Rate This Post on the lower left hand side of it

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