Jump to content

Script Wont Work complied, but works when run in SciTE.


Recommended Posts

My script works when it is run in SciTE, but as soon as I compile it and run the .exe, it loads then ends. :(

(I see the script in my processes, but then shuts down right after it starts.) I got no idea why this happens, :)

but it probley because of my strange GUI coding structor. (I "jerry-rigged" it all togther. :D ) So I was wondering,

if anyone could explain why this happens and how I could fix it. Also tips on how to improve my code are

very welcomed! :( (Below is my code.)

#include <GUIConstants.au3>

#NoTrayIcon

Global $Pennys = 1
Global $Nickels = 2
Global $Dimes = 3
Global $Quarters = 4
Global $HalfDollars = 5
Global $TotalCoins

$MainGUI = GUICreate("Coin Counter", 219, 320, 192, 125)
GUICtrlSetFont(-1, 9, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("Coins", 8, 8, 201, 305)
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUICtrlCreateGroup("Pennys", 16, 24, 169, 41)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Display_Pennys = GUICtrlCreateInput($Pennys, 24, 40, 97, 21, $ES_RIGHT, $WS_EX_CLIENTEDGE)
GUICtrlSetState(-1, $GUI_DISABLE)
$Set_Pennys = GUICtrlCreateButton("Change", 128, 40, 49, 21)

GUICtrlCreateGroup("Nickels", 16, 72, 169, 41)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Display_Nickels = GUICtrlCreateInput($Nickels, 24, 88, 97, 21, $ES_RIGHT, $WS_EX_CLIENTEDGE)
GUICtrlSetState(-1, $GUI_DISABLE)
$Set_Nickels = GUICtrlCreateButton("Change", 128, 88, 49, 21)

GUICtrlCreateGroup("Dimes", 16, 120, 169, 41)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Display_Dimes = GUICtrlCreateInput($Dimes, 24, 136, 97, 21, $ES_RIGHT, $WS_EX_CLIENTEDGE)
GUICtrlSetState(-1, $GUI_DISABLE)
$Set_Dimes = GUICtrlCreateButton("Change", 128, 136, 49, 21)

GUICtrlCreateGroup("Quarters", 16, 168, 169, 41)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Display_Quarters = GUICtrlCreateInput($Quarters, 24, 184, 97, 21, $ES_RIGHT, $WS_EX_CLIENTEDGE)
GUICtrlSetState(-1, $GUI_DISABLE)
$Set_Quarters = GUICtrlCreateButton("Change", 128, 184, 49, 21)

GUICtrlCreateGroup("Half Dollars", 16, 216, 169, 41)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Display_HalfDollars = GUICtrlCreateInput($HalfDollars, 24, 232, 97, 21, $ES_RIGHT, $WS_EX_CLIENTEDGE)
GUICtrlSetState(-1, $GUI_DISABLE)
$Set_HalfDollars = GUICtrlCreateButton("Change", 128, 232, 49, 21)

$TotalCoins = ($Pennys * .01) + ($Nickels * .05) + ($Dimes * .1) + ($Quarters * .25) + ($HalfDollars * .5)

GUICtrlCreateGroup("Total Coins", 96, 264, 105, 41)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Display_Coins = GUICtrlCreateInput("$ " & $TotalCoins, 104, 280, 89, 21, $ES_RIGHT, $WS_EX_CLIENTEDGE)
GUICtrlSetState(-1, $GUI_DISABLE)

$Clear_Coins = GUICtrlCreateButton("Clear Coins", 16, 275, 75, 25)

GUISetState(@SW_SHOW)

While 1
    
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
            
        Case $msg = $Set_Pennys
            
            
            GUISetState(@SW_DISABLE)
            $test = GUICreate("Change Pennys", 245, 37, 588, 620)
            $Change_Pennys = GUICtrlCreateInput($Pennys, 72, 8, 113, 21, $ES_RIGHT, $WS_EX_CLIENTEDGE)
            $Set = GUICtrlCreateButton("Set", 192, 8, 41, 21)
            $Minus_Coin = GUICtrlCreateButton("-", 8, 8, 25, 21)
            $Plus_Coin = GUICtrlCreateButton("+", 40, 8, 25, 21)
            GUISwitch($test)
            GUISetState(@SW_SHOW)
            
            While 1
                $msg = GUIGetMsg(2)
                Select
                    Case $msg = $GUI_EVENT_CLOSE
                        GUISetState(@SW_HIDE)
                        GUISetState(@SW_ENABLE, $MainGUI)
                        WinActivate("Coin Counter")
                        ExitLoop
                        
                    Case $msg = $Set
                        $i = 0
                        While 1
                            $New_Pennys = GUICtrlRead($Change_Pennys)
                            If $New_Pennys > 50000 Then
                                MsgBox(0, "Error ( Liar )", $New_Pennys & " pennys eh?, well then I guess" & @CRLF & "Im the Captain _
                                        of the 'U.S.S. your a dirty liar' then." & @CRLF & "Now lets try this again... Just without the lying part.")
                                GUICtrlSetData($Change_Pennys, $Pennys)
                                ExitLoop
                            EndIf
                            
                            If StringIsDigit($New_Pennys) = 0 Then
                                MsgBox(0, "Error ( Not A Positive Number )", $New_Pennys & " Is not a positive number, _
                                        please only use" & @CRLF & " positive numbers, OR I WILL DISTROY YOU!")
                                GUICtrlSetData($Change_Pennys, $Pennys)
                                ExitLoop
                            EndIf
                            
                            $Pennys = $New_Pennys
                            GUICtrlSetData($Display_Pennys, $Pennys)
                            $TotalCoins = ($Pennys * .01) + ($Nickels * .05) + ($Dimes * .1) + _
                                    ($Quarters * .25) + ($HalfDollars * .5)
                            GUICtrlSetData($Display_Coins, "$ " & $TotalCoins)
                            GUISetState(@SW_HIDE)
                            GUISetState(@SW_ENABLE, $MainGUI)
                            WinActivate("Coin Counter")
                            GUISetState(@SW_SHOW, $MainGUI)
                            $i = 1
                            ExitLoop
                        WEnd
                        If $i = 1 Then ExitLoop
                        
                    Case $msg = $Plus_Coin
                        While 1
                            $New_Pennys = GUICtrlRead($Change_Pennys)
                            If $New_Pennys < 0 Then
                                MsgBox(0, "Error ( Negative Pennys )", "I dont think its possible to have negative " & @CRLF _
                                         & "pennys, but hey I might be wrong.")
                                GUICtrlSetData($Change_Pennys, $Pennys)
                                ExitLoop
                            EndIf
                            $New_Pennys = $New_Pennys + 1
                            If $New_Pennys > 50000 Then
                                MsgBox(0, "Error ( Liar )", $New_Pennys & " pennys eh?, well then I guess" & @CRLF & "Im the Captain _
                                        of the 'U.S.S. your a dirty liar' then." & @CRLF & "Now lets try this again... Just without the lying part.")
                                GUICtrlSetData($Change_Pennys, $Pennys)
                                ExitLoop
                            EndIf
                            GUICtrlSetData($Change_Pennys, $New_Pennys)
                            ExitLoop
                        WEnd
                    Case $msg = $Minus_Coin
                        While 1
                            $New_Pennys = GUICtrlRead($Change_Pennys)
                            If $New_Pennys < 0 Then
                                MsgBox(0, "Error ( Negative Pennys )", "I dont think its possible to have negative " & @CRLF _
                                         & "pennys, but hey I might be wrong.")
                                GUICtrlSetData($Change_Pennys, $Pennys)
                                ExitLoop
                            EndIf
                            $New_Pennys = $New_Pennys - 1
                            If $New_Pennys = -1 Then
                                MsgBox(0, "Error ( Negative Pennys )", "I dont think its possible to have negative one " & @CRLF _
                                         & "pennys, but hey I might be wrong.")
                                GUICtrlSetData($Change_Pennys, 0)
                                ExitLoop
                            EndIf
                            GUICtrlSetData($Change_Pennys, $New_Pennys)
                            ExitLoop
                        WEnd
                EndSelect
            WEnd
            
        Case $msg = $Clear_Coins
            $Pennys = 0
            $Nickels = 0
            $Dimes = 0
            $Quarters = 0
            $HalfDollars = 0
            $TotalCoins = 0
            GUICtrlSetData($Display_Pennys, $Pennys)
            GUICtrlSetData($Display_Nickels, $Nickels)
            GUICtrlSetData($Display_Dimes, $Dimes)
            GUICtrlSetData($Display_Quarters, $Quarters)
            GUICtrlSetData($Display_HalfDollars, $HalfDollars)
            GUICtrlSetData($Display_Coins, $TotalCoins)
    EndSelect
WEnd
Exit

I think it might be because I made a GUI over a GUI, then im hiding one and showing the other when I switch

to a new window... :oops:

Edited by S.C.G.R.
Link to comment
Share on other sites

1

there is a problem in the message box text

& @CRLF & "Im the Captain _; needs a closing '"' and an & 
                                        of the 'U.S.S. your a dirty liar' then." & @CRLF & "Now lets t

look at mine below

2

because you are "creating" the $test GUI, you need to use guidelete, or you will have more than 1 GUI with the same handle... makes for errors later

3

this compiled and worked

#include <GUIConstants.au3>

#NoTrayIcon

Global $Pennys = 1
Global $Nickels = 2
Global $Dimes = 3
Global $Quarters = 4
Global $HalfDollars = 5
Global $TotalCoins

$MainGUI = GUICreate("Coin Counter", 219, 320, 192, 125)
GUICtrlSetFont(-1, 9, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("Coins", 8, 8, 201, 305)
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUICtrlCreateGroup("Pennys", 16, 24, 169, 41)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Display_Pennys = GUICtrlCreateInput($Pennys, 24, 40, 97, 21, $ES_RIGHT, $WS_EX_CLIENTEDGE)
GUICtrlSetState(-1, $GUI_DISABLE)
$Set_Pennys = GUICtrlCreateButton("Change", 128, 40, 49, 21)

GUICtrlCreateGroup("Nickels", 16, 72, 169, 41)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Display_Nickels = GUICtrlCreateInput($Nickels, 24, 88, 97, 21, $ES_RIGHT, $WS_EX_CLIENTEDGE)
GUICtrlSetState(-1, $GUI_DISABLE)
$Set_Nickels = GUICtrlCreateButton("Change", 128, 88, 49, 21)

GUICtrlCreateGroup("Dimes", 16, 120, 169, 41)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Display_Dimes = GUICtrlCreateInput($Dimes, 24, 136, 97, 21, $ES_RIGHT, $WS_EX_CLIENTEDGE)
GUICtrlSetState(-1, $GUI_DISABLE)
$Set_Dimes = GUICtrlCreateButton("Change", 128, 136, 49, 21)

GUICtrlCreateGroup("Quarters", 16, 168, 169, 41)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Display_Quarters = GUICtrlCreateInput($Quarters, 24, 184, 97, 21, $ES_RIGHT, $WS_EX_CLIENTEDGE)
GUICtrlSetState(-1, $GUI_DISABLE)
$Set_Quarters = GUICtrlCreateButton("Change", 128, 184, 49, 21)

GUICtrlCreateGroup("Half Dollars", 16, 216, 169, 41)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Display_HalfDollars = GUICtrlCreateInput($HalfDollars, 24, 232, 97, 21, $ES_RIGHT, $WS_EX_CLIENTEDGE)
GUICtrlSetState(-1, $GUI_DISABLE)
$Set_HalfDollars = GUICtrlCreateButton("Change", 128, 232, 49, 21)

$TotalCoins = ($Pennys * .01) + ($Nickels * .05) + ($Dimes * .1) + ($Quarters * .25) + ($HalfDollars * .5)

GUICtrlCreateGroup("Total Coins", 96, 264, 105, 41)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Display_Coins = GUICtrlCreateInput("$ " & $TotalCoins, 104, 280, 89, 21, $ES_RIGHT, $WS_EX_CLIENTEDGE)
GUICtrlSetState(-1, $GUI_DISABLE)

$Clear_Coins = GUICtrlCreateButton("Clear Coins", 16, 275, 75, 25)

GUISetState(@SW_SHOW)

While 1
    
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
            
        Case $msg = $Set_Pennys
            
            
            GUISetState(@SW_DISABLE, $MainGUI)
            $test = GUICreate("Change Pennys", 245, 37, 588, 620)
            $Change_Pennys = GUICtrlCreateInput($Pennys, 72, 8, 113, 21, $ES_RIGHT, $WS_EX_CLIENTEDGE)
            $Set = GUICtrlCreateButton("Set", 192, 8, 41, 21)
            $Minus_Coin = GUICtrlCreateButton("-", 8, 8, 25, 21)
            $Plus_Coin = GUICtrlCreateButton("+", 40, 8, 25, 21)
            GUISwitch($test)
            GUISetState(@SW_SHOW, $test)
            
            While 1
                $msg = GUIGetMsg(2)
                Select
                    Case $msg = $GUI_EVENT_CLOSE
                        GUIDelete($test)
                        GUISetState(@SW_ENABLE, $MainGUI)
                        WinActivate("Coin Counter")
                        ExitLoop
                        
                    Case $msg = $Set
                        $i = 0
                        While 1
                            $New_Pennys = GUICtrlRead($Change_Pennys)
                            If $New_Pennys > 50000 Then
                                MsgBox(0, "Error ( Liar )", $New_Pennys & " pennys eh?, well then I guess" & @CRLF & "Im the Captain " & _
                                    "of the 'U.S.S. your a dirty liar' then." & @CRLF & "Now lets try this again... Just without the lying part.")
                                GUICtrlSetData($Change_Pennys, $Pennys)
                                ExitLoop
                            EndIf
                            
                            If StringIsDigit($New_Pennys) = 0 Then
                                MsgBox(0, "Error ( Not A Positive Number )", $New_Pennys & " Is not a positive number, " & _
                                    "please only use" & @CRLF & " positive numbers, OR I WILL DISTROY YOU!")
                                GUICtrlSetData($Change_Pennys, $Pennys)
                                ExitLoop
                            EndIf
                            
                            $Pennys = $New_Pennys
                            GUICtrlSetData($Display_Pennys, $Pennys)
                            $TotalCoins = ($Pennys * .01) + ($Nickels * .05) + ($Dimes * .1) + _
                                    ($Quarters * .25) + ($HalfDollars * .5)
                            GUICtrlSetData($Display_Coins, "$ " & $TotalCoins)
                             GUIDelete($test)
                            GUISetState(@SW_ENABLE, $MainGUI)
                            WinActivate("Coin Counter")
                            GUISetState(@SW_SHOW, $MainGUI)
                            $i = 1
                            ExitLoop
                        WEnd
                        If $i = 1 Then ExitLoop
                        
                    Case $msg = $Plus_Coin
                        While 1
                            $New_Pennys = GUICtrlRead($Change_Pennys)
                            If $New_Pennys < 0 Then
                                MsgBox(0, "Error ( Negative Pennys )", "I dont think its possible to have negative " & @CRLF _
                                         & "pennys, but hey I might be wrong.")
                                GUICtrlSetData($Change_Pennys, $Pennys)
                                ExitLoop
                            EndIf
                            $New_Pennys = $New_Pennys + 1
                            If $New_Pennys > 50000 Then
                                MsgBox(0, "Error ( Liar )", $New_Pennys & " pennys eh?, well then I guess" & @CRLF & "Im the Captain " & _
                                    "of the 'U.S.S. your a dirty liar' then." & @CRLF & "Now lets try this again... Just without the lying part.")
                                GUICtrlSetData($Change_Pennys, $Pennys)
                                ExitLoop
                            EndIf
                            GUICtrlSetData($Change_Pennys, $New_Pennys)
                            ExitLoop
                        WEnd
                    Case $msg = $Minus_Coin
                        While 1
                            $New_Pennys = GUICtrlRead($Change_Pennys)
                            If $New_Pennys < 0 Then
                                MsgBox(0, "Error ( Negative Pennys )", "I dont think its possible to have negative " & @CRLF _
                                         & "pennys, but hey I might be wrong.")
                                GUICtrlSetData($Change_Pennys, $Pennys)
                                ExitLoop
                            EndIf
                            $New_Pennys = $New_Pennys - 1
                            If $New_Pennys = -1 Then
                                MsgBox(0, "Error ( Negative Pennys )", "I dont think its possible to have negative one " & @CRLF _
                                         & "pennys, but hey I might be wrong.")
                                GUICtrlSetData($Change_Pennys, 0)
                                ExitLoop
                            EndIf
                            GUICtrlSetData($Change_Pennys, $New_Pennys)
                            ExitLoop
                        WEnd
                EndSelect
            WEnd
            
        Case $msg = $Clear_Coins
            $Pennys = 0
            $Nickels = 0
            $Dimes = 0
            $Quarters = 0
            $HalfDollars = 0
            $TotalCoins = 0
            GUICtrlSetData($Display_Pennys, $Pennys)
            GUICtrlSetData($Display_Nickels, $Nickels)
            GUICtrlSetData($Display_Dimes, $Dimes)
            GUICtrlSetData($Display_Quarters, $Quarters)
            GUICtrlSetData($Display_HalfDollars, $HalfDollars)
            GUICtrlSetData($Display_Coins, $TotalCoins)
    EndSelect
WEnd
Exit

the Syntax Check Beta ... should have caught that... but it does not!!!

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

Thank you friend. :)

But can you give an example of...

because you are "creating" the $test GUI, you need to use guidelete, or you will have more than 1 GUI with the same handle... makes for errors later

I'm kinda slow and hard headed, so if i dont see it I dont learn. :">

the Syntax Check Beta ... should have caught that... but it does not!!!

yea, maybe you should pass that on to the person who is in charge of the Syntax Check Beta...

Edited by S.C.G.R.
Link to comment
Share on other sites

Creating a GUI is when you do...

$my_variable = GUICreate("My GUI")

"$my_variable" is now what they call a "handle". Think of it like a wormhole. Through this wormhole you can access the GUI's dimension.

If you then do...

$my_variable = GUICreate("My Other GUI")

You have just opened the same wormhole, but to a second dimension, so one single "handle" now points to two separate places. From this side it looks like everything's working fine, but if you actually jumped into this wormhole, bad things would happen to your anatomy.

So before you create a new wormhole ("handle"), you first close the old one.

Or else give the second one a different name.

-mu

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