Jump to content

MsgBox Responses


Recommended Posts

Hi Guys,

This might be a bit of a basic question for you experts but here we go anyway. After looking all over google i havent come up with an answer yet.

I am trying to get a response from a MsgBox to perform the next task in an IF statement so i have this as my MsgBox code:

MsgBox(3, "Application Installed", $Found)

So this gives me some text and i am asked to press Yes / No or Cancel - at the moment whichever i press makes zero difference it just carries on processing whatever is next.

Below is a what i am after but i havent figured out how to intercept the button response:

$HRW = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{5525400A-82E2-48B6-AC66-689D7CF7DF39}", "UninstallString")
If $HRW = "MsiExec.exe /X{5525400A-82E2-48B6-AC66-689D7CF7DF39}" Then
    $installed = MsgBox(3, "Application Installed", $Found)
    If $installed = "Yes" Then
    Run("C:\Windows\System32\Notepad.exe")
    EndIf
Else
    MsgBox(0, "Application Not Installed", $NotFound)
EndIf

Im not sure i can use multiple IF statements inside another statement?

If anyone can point me in the right direction that would be appreciated (It may be i have to use something other than a MsgBox but so far i havent come up with anything).

Thanks

Dan

Link to comment
Share on other sites

Assign the return value of MsgBox to a variable and then do your processing based on the buttons clicked.

$iResult = MsgBox(3, "Application Installed", $Found)
If $iResult = 1 ... ; Yes Button pressed
If $iResult = 2 ... ; No Button pressed
If $iResult = 3 ... ; Cancel Button pressed

MsgBox returns the ID of the pressed button.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

goss34,

No need for Google - if you look at the Help file page for MsgBox, you will see that it "Returns the ID of the button pressed". Just below that is the list of return values:

Button      Pressed Return Value 

OK          1 
CANCEL      2 
ABORT       3 
RETRY       4 
IGNORE      5 
YES         6 
NO          7 
TRY AGAIN   10 
CONTINUE    11

So you need to replace

If $installed = "Yes" Then

with

If $installed = 6 Then

Simple! :P

And you can nest as many If statements as you want - but be careful to close them all or you might not get the result you want. :blink:

M23

Edit:

water,

You might like to check on those return values! ;)

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi Again,

Thanks for the responses Melba that worked wonderful i now have it almost perfected :-)

One final question is that i was intending to use the "goto" command but it has been removed.

Im trying to check for a folder and if it exists i want to skip the next 2 lines which are a create and copy (these steps wouldnt be needed if the folder is already there).

DirCreate("C:\SoftwareInstallation\Application\Office")
DirCopy ("\\FileServer\Software\Licensed\Office", "C:\SoftwareInstallation\Application\Office" ,1)
RunAsWait - This line installs the application

I would like the statement above DirCreate to be something like:

If FileExists ("C:\SoftwareInstallation\Application\Office")
    Goto, RunInstall    
    DirCreate
    DirCopy
    :RunInstall
    EndIf
    RunAsWait

Hopefully you can see what im trying to achieve and point me in the right direction (I dont think the "while" command does what i need from what i have understood so far).

Thanks

Link to comment
Share on other sites

water,

You might like to check on those return values! ;)

As always you are right :blink: Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

goss34,

GOTO !?!?!?! Go and wash your mouth out at once! :blink:

You can do what you want very easily the "structured" way: ;)

If Not FileExists ("C:\SoftwareInstallation\Application\Office") Then
    DirCreate
    DirCopy
EndIf
RunAsWait

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

goss34,

Be very careful using Not in AutoIt - unlike most other languages, Not is the highest priority operator here. This means that you can very easily not Not what you think you are Noting - if you see what I mean. :

Other than very simple cases (such as the above) I ALWAYS I always put the expression I want to Not into parentheses. ;)

Here is why:

Let us start with a simple If statement:

; Declare a variable
$var1 = 1

; Should be True
If $var1 = 1 Then
    MsgBox(0, "Easy", "True")
Else
    MsgBox(0, "Easy", "False")
EndIf

Well, that worked!

Now add a Not into the mix:

; Declare a variable
$var1 = 1

; Now use Not - surely this must be True as $var1 = 1 and therefore $var1 <> 3
If Not $var1 = 3 Then
    MsgBox(0, "Oops", "True")
Else
    MsgBox(0, "Oops", "False")
EndIf

That did not work as we expected, did it. :blink: The reason why is because Not has the highest priority, so the AutoIt evaluates the expression as

{ Not $var1 } = { 3 }

The Not only affects $var1 and not the whole expression.

Let us try again, but with parentheses:

; Declare a variable
$var1 = 1

; Now use Not with parentheses - will this be True?
If Not ($var1 = 3) Then
    MsgBox(0, "Aaah", "True")
Else
    MsgBox(0, "Aaah", "False")
EndIf

And we get what logic tells us we should! :nuke:

All clear? :P

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Be very careful using Not in AutoIt - unlike most other languages, Not is the highest priority operator here.

In what languages is this not the case? I'm pretty sure Not is always higher than any logical comparison. It is a unary operation. Those come right after grouping operations such as (). After that come the multiplication, division, modulo, then the add, subtract. Then you get the bitwise ops, and FINALLY the comparison.

As a side note, autoit does do 1 thing I noticed that does not follow normal order of operations. Logical AND is supposed to come before Logical OR, autoit treats them as equal and processes whatever it gets to 1st.

Link to comment
Share on other sites

  • Moderators

ShawnW,

In what languages is this not the case?

No idea! :P I was quoting a long-lost thread (or at least I cannot find it ;) ) which discussed Not and someone much more experienced than I was at the time came out with that remark. I am a trusting soul, so I took it at face value. :blink:

Anyway, the basic advice is good - ALWAYS use parentheses with Not!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...