Jump to content

Shouldn't this be looping?


 Share

Recommended Posts

Here is my script.

$random_ms = 12

If $random_ms = 12 Then
    Do

    MsgBox(0, "Variable Test", $random_ms)
        $random_ms = $random_ms + 1

    Until $random_ms = 23
EndIF



If $random_ms = 23 Then
    $random_ms = 12 
EndIf

For some reason the MsgBox will not loop back to 12, and repeat the count from 12-23. Logic tells me this should be looping, but it isn't. Any help, or a better method would be greatly appreciated.

Link to comment
Share on other sites

Two problems:

1. Your do loop stop at 23 so it never executes the MsgBox(0, "Variable Test", $random_ms) when $random_ms is 23. Set the limit to 24.

2.The code stops when the last if statement is executed, it won't jump to the beginning of the program again. Put a while loop around it.

$random_ms = 12

while 1

If $random_ms = 12 Then
    Do

    MsgBox(0, "Variable Test", $random_ms)
        $random_ms = $random_ms + 1

    Until $random_ms = 24
EndIF



If $random_ms = 24 Then
    $random_ms = 12
EndIf

WEnd
Edited by rliiack

My Projects:Smart Icons

Link to comment
Share on other sites

Here is my script.

$random_ms = 12

If $random_ms = 12 Then
    Do

    MsgBox(0, "Variable Test", $random_ms)
        $random_ms = $random_ms + 1

    Until $random_ms = 23
EndIF

If $random_ms = 23 Then
    $random_ms = 12 
EndIf

For some reason the MsgBox will not loop back to 12, and repeat the count from 12-23. Logic tells me this should be looping, but it isn't. Any help, or a better method would be greatly appreciated.

You need to check $random_ms before you exit your loop.

random_ms = 12

If $random_ms = 12 Then
    Do

    MsgBox(0, "Variable Test", $random_ms)
    $random_ms = $random_ms + 1

    If $random_ms = 23 Then
    $random_ms = 12
    EndIf

    Until $random_ms = 23
EndIF
Link to comment
Share on other sites

Wow, thanks a ton for all of the help. However I figured out a method which did what I wanted too while I was waiting for a response, which turned out to be exactly what booge suggested. Only problem is my until. I would like be able to exit the script upon clicking the X on the message box. I searched the help document, and couldn't find anything. Here's what I have so far.

$random_ms = 12

If $random_ms = 12 Then
    
    Do
        
        MsgBox(0, "Variable Test", $random_ms)
        $random_ms = $random_ms + 1
        
        If $random_ms = 23 Then
            
            $random_ms = 12
        EndIf
    
    Until $random_ms = 24   
EndIf

It keeps looping, which is good, but it doesn't stop. I had to terminate through windows task manager.

Link to comment
Share on other sites

Exit upon clicking the X? I don't know if that possible.. but this works for me:

$random_ms = 12

If $random_ms = 12 Then
    
    Do
        
        $input = MsgBox(1, "Variable Test.. hit Cancel to exit", $random_ms)
        If $input = 2 Then Exit
        $random_ms = $random_ms + 1
        
        If $random_ms = 23 Then
            
            $random_ms = 12
        EndIf
    
    Until $random_ms = 24   
EndIf

Hi ;)

Link to comment
Share on other sites

I dont think its possible either because OK and X both return 1.

Also use Exitloop if you don't want program to end.

Edited by Beege
Link to comment
Share on other sites

Exit upon clicking the X? I don't know if that possible.. but this works for me:

$random_ms = 12

If $random_ms = 12 Then
    
    Do
        
        $input = MsgBox(1, "Variable Test.. hit Cancel to exit", $random_ms)
        If $input = 2 Then Exit
        $random_ms = $random_ms + 1
        
        If $random_ms = 23 Then
            
            $random_ms = 12
        EndIf
    
    Until $random_ms = 24   
EndIf

Yes, that works perfectly well, however, if anyone does know of a method to terminate with the X button, it may be useful to me later if you care to share. Thanks a lot guys!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...