Jump to content
helmar

How to exit this script

Recommended Posts

helmar

I have a script that displays prayers on screen.  I am trying to keep it minimal.  I want the script to exit if at anytime the user clicks on the "x" in the extendedmsgbox.  What am I missing?  Thanks in advance for any thoughts / suggestions / comments.

 

#Region options, includes, & variables
Opt('MustDeclareVars', 1)
#include "ExtMsgBox.au3"
Global $hm = 0, $d = 0, $AppTitle = "Praying", $Amen = "Amen.", $Continue = "continue...", $x = 0

Global Const $Prayer1 = "Prayer1 prayer prayer."
Global Const $Prayer2 = "Prayer2 prayer prayer." & @CRLF & @CRLF & "The second paragraph of prayer 2."
Global Const $Prayer3 = "Prayer3 prayer prayer." & @CRLF & @CRLF & "The second paragraph of prayer 3."
Global Const $Prayer4 = "Prayer4 prayer prayer." & @CRLF & @CRLF & "The second paragraph of prayer 4."
Global Const $Prayer5 = "Prayer5 prayer prayer." & @CRLF & @CRLF & "The second paragraph of prayer 5."
Global Const $Prayer6 = "Prayer6 prayer prayer." & @CRLF & @CRLF & "The second paragraph of prayer 6."
Global Const $Prayer7 = "Prayer7 prayer prayer." & @CRLF & @CRLF & "The second paragraph of prayer 7."
Global Const $Prayer8 = "Prayer8 prayer prayer." & @CRLF & @CRLF & "The second paragraph of prayer 8."
#EndRegion options, includes, & variables

;To do next - create a menu system that asks what prayers your would like to prayer and then act on the selection

;set the baseline, not needed yet, but will remind me to use it if I change EMB settings later in the code
_ExtMsgBoxSet(Default)
; Increase font size and max width (I think)
_ExtMsgBoxSet(-1, -1, -1, -1, 22, -1, 1000)

Say($AppTitle, $Prayer1, $Amen)
While $x <> 0
    Daily()
WEnd
Say($AppTitle, $Prayer1, $Amen)

Func Daily()
    TheMorning()
    TheLitany()
    Say("Prayer for our intentions", $Prayer8, $Amen)
EndFunc

Func TheMorning()
    Say($AppTitle, $Prayer2, $Amen)
    Say($AppTitle, $Prayer3, $Continue)
    Say($AppTitle, $Prayer4, $Amen)
EndFunc

Func TheLitany()
    Say($AppTitle, $Prayer2, $Amen)
    Say($AppTitle, $Prayer5, $Continue)
    Say($AppTitle, $Prayer6, $Continue)
    Say($AppTitle, $Prayer7, $Amen)
EndFunc

Func Say($Text, $Prayer, $Button)
;~  $x = MsgBox($MB_SYSTEMMODAL, $Text, $Prayer)
    $x = _ExtMsgBox(0, $Button, $Text, $Prayer)
EndFunc

 

StringSize.au3

ExtMsgBox.au3

Edited by helmar
added requested files

Share this post


Link to post
Share on other sites
helmar
10 minutes ago, Zedna said:

Post source of


ExtMsgBox.au3

Done

Share this post


Link to post
Share on other sites
benched42

Zelda ..... Really? The code ExtMsgBox.au3 is available on the AutoIt Wiki. It's an excellent UDF posted by Melba23 .

Helmar, are you using the latest version? I recently had to update the version I have been using for years. The latest version is 22 Mar 2018.

  • Sad 1

Who lied and told you life would EVER be fair?

Share this post


Link to post
Share on other sites
helmar
10 minutes ago, benched42 said:

Helmar, are you using the latest version? I recently had to update the version I have been using for years. The latest version is 22 Mar 2018.

Yes, that is the version I am using.

Share this post


Link to post
Share on other sites
benched42

I believe that you might need to insert a value for the $Button variable, since you choose to explicitly define all variables.


Who lied and told you life would EVER be fair?

Share this post


Link to post
Share on other sites
helmar
1 minute ago, benched42 said:

I believe that you might need to insert a value for the $Button variable, since you choose to explicitly define all variables.

By 'declaring' $Button in the Say() function initialization, I thought I didn't need to put it up top.  Are you saying give it a default value if I forget to pass that parm?

Why is $x not being evaluated by the While/WEnd?

Share this post


Link to post
Share on other sites
Jos

Try using this Func Say:

Func Say($Text, $Prayer, $Button)
;~  $x = MsgBox($MB_SYSTEMMODAL, $Text, $Prayer)
    $x = _ExtMsgBox(0, $Button, $Text, $Prayer)
    if not $x then Exit
EndFunc

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Melba23

helmar,

You get a return value of 0 if the _ExtMsgBox [X] is pressed (as explained in the function header within the UDF itself), so just look for that:

Func Say($Text, $Prayer, $Button)
    If _ExtMsgBox(0, $Button, $Text, $Prayer) = 0 Then
        Exit
    EndIf
EndFunc

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Jos
9 minutes ago, benched42 said:

I believe that you might need to insert a value for the $Button variable, since you choose to explicitly define all variables.

 

34 minutes ago, benched42 said:

Zelda  benched42 ..... Really?

;)


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
helmar

Thank you Melba23 and Jos, you helped me get that resolved.  I opted to remove $x completely and read the result of the EMB inline.

Jos, I understand what you were saying in that one comment, however it did cause me to look at optional variables in defining a function (which I had never done before).  Instead of declaring up top $Amen (which is the norm), I am now declaring it in the function declaration

Func Say($Text, $Prayer, $Button = "Amen")

and sending $Continue for those exceptions when the text is very verbose for one screen or the like.  Reduces code size and makes adding prayers easier.

Share this post


Link to post
Share on other sites
Jos
46 minutes ago, helmar said:

Jos, I understand what you were saying

My second post was for @benched42 and solely about the initial remark made towards @Zedna:) 
I namely agree with zedna that posted issues should be runable without any searching for extra's first....  that's all.

JOs 


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
helmar
1 hour ago, Jos said:

posted issues should be runable without any searching for extra's first

I thought about that, made a (poor) call that it would be in high use  - my error.  I almost commented out the calls to the UDF, and just used the native MsgBox in the posting, but that would have changed the question / answer (I think).

Share this post


Link to post
Share on other sites
helmar

Question:  what are some of the nuances with touch screen / tablets / orientation and EMB?  I "think" if I move the EMB set statement into the Say() function, I should be addressing if someone starts the script from a normal desktop, and then switches to tablet or portrait etc.

Func Say($Text, $Prayer, $Button = "Amen")
    _ExtMsgBoxSet(Default) ;set the baseline
    _ExtMsgBoxSet(-1, -1, -1, -1, 22, -1, @DesktopWidth-25)
    If _ExtMsgBox(0, $Button, $Text, $Prayer) = 0 Then
        Exit
    EndIf
EndFunc

 

Edited by helmar
broader audience

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

×