Sign in to follow this  
Followers 0
232showtime

If Statement

3 posts in this topic

#1 ·  Posted (edited)

I made hotkey script for the software im Using but when I press yes, msgbox wont close and it keeps on poping up... if i press no message box will close and my script will not run. but i tried if statement on calculator and its working fine. 

#include <MsgBoxConstants.au3>

Global $fPaused = False

HotKeySet("{`}", "TogglePause")



$msgBox = MsgBox($MB_YESNO, "Welcome", "Do you want to use this Program?")

If $msgBox = 6 then
Run("mspaint.exe");try to use paint and its working fine
EndIf

If $msgBox = 7 Then
    Run("CALC.exe");try to use calc and its working fine aswell
    EndIf

While 1
   ;this is where my script runs
  
   Sleep(10)
Wend

Func _IsPressed($hexKey)

   Local $aR, $bO

   $hexKey = '0x' & $hexKey
   $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)
   If Not @error And BitAND($aR[0], 0x8000) = 0x8000 Then
      $bO = 1
   Else
      $bO = 0
   EndIf

   Return $bO
EndFunc  ;==>_IsPressed

Func TogglePause()
    $fPaused = Not $fPaused
    While $fPaused
        Sleep(100)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc   ;==>TogglePause

the script above is the same that im using for my hot key script.... can anyone tell me why its not working on the script that i made from autoit???

Edited by 232showtime

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Tested on Win 7 32 Bit (Working)

>Running AU3Check (3.3.12.0)

HotKeySet("{`}", "TogglePause")   = Pauses script ( NO additional msgbox popup )

Yes - opens Paint

No - opens Calc.exe

If I may make a suggestion: Instead of using MsgBox for this, build a little GUI and use Switch case...

Edit: - you could also do something like this if you want to stick to MsgBox

Using Select Case instead of If statement:

#include <Inet.au3>
Local $PublicIP = _GetIP()

$iMsgBoxAnswer = MsgBox(1, "IP Address", "Your IP Address is: " & $PublicIP & @CRLF & "Copy to Clipboard?")
Select
        Case $iMsgBoxAnswer = 1 ;OK
                ClipPut($PublicIP)
                
        Case $iMsgBoxAnswer = 2 ;Cancel

EndSelect
Edited by l3ill
1 person likes this

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I got it fixed, I used select statement, Thanks for replying. but I want to know why If statement is not working properly on my script that I made using autoit. when I run my Script MsgBox will appear and ask do you want to use this program? If I press yes my script will Run and MsgBox will Pop up again and ask the same question and If Select Yes again it will do the same thing over and over again. but if I click no Scrip will not run and MsgBox will close. is there anybug from the latest version of autoit??? I try to used the same Script from above and used other app. like calculator and mspaint and its working fine. : :'( :

EDIT: thank you for your help dabbler really appreciate it. and already figure it out, why if statement is not working properly my script was already compiled and kept running it.

Global $fPaused = False

HotKeySet("{`}", "TogglePause")


$msgBox = MsgBox($MB_YESNO, "Welcome", "Do you like to run this program?")
If $msgBox = 6 Then
    Run(Myscript.exe) ;Compiled Script that I've made from auto it
   $msgBox = 7 Then
        Exit
EndIf

While 1

;script is also running here lol

WEnd
;Made it something like this, works like a charm

$msgBox = MsgBox($MB_YESNO, "Welcome", "Noob")
If $msgBox = 7 Then
    Exit
EndIf
While 1
;Script runs here
WEnd

Forgive Im a Beginner in Autoit... :ILA2: :ILA2: :ILA2:

Edited by 232showtime

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

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  
Followers 0