Jump to content
Sign in to follow this  
RAWBERRY

Shouldn't this be looping?

Recommended Posts

RAWBERRY

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.

Share this post


Link to post
Share on other sites
Mison

try:

$random_ms = 12
While 1
    MsgBox(0,"",$random_ms)
    $random_ms += 1
    If $random_ms = 23 Then $random_ms = 12
WEnd

Hi ;)

Share this post


Link to post
Share on other sites
rliiack

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

Share this post


Link to post
Share on other sites
Beege

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

Share this post


Link to post
Share on other sites
RAWBERRY

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.

Share this post


Link to post
Share on other sites
Mison

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 ;)

Share this post


Link to post
Share on other sites
Beege

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

Share this post


Link to post
Share on other sites
RAWBERRY

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!

Share this post


Link to post
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
Sign in to follow this  

×