Jump to content

Can't Exit from Script


Roger
 Share

Recommended Posts

I have a problem trying to exit a script using GUI_EVENT_Close. When you select an item from the list it enables the second combo box on the window. After that, any attempt to close the script other than right clicking on the AutoIT tray icon fails. Here is the script.

Example script and ini file below:

#include <GUIConstants.au3>

$path = @SCRIPTDIR & "\settings.ini"
$printeritems = "Accounting"
$CountLocation = 1
$CountPrinter = 1

GUICreate("My GUI combo") ; will create a dialog box that when displayed is centered

$location = GUICtrlCreateCombo ("", 10,10); create first item
GUICtrlSetData(-1, ReadLocationINI(),""); add other item snd set a new default

$printer = GUICtrlCreateCombo ("", 10,40); create first item
GuiCtrlSetState (-1, $GUI_Disable)

GuiSetState ()


Func ReadLocationINI()
$record = IniRead ($path, "Settings", "Records", "")
$locationitems = IniRead ($path, $CountLocation, "Location", "")
If $record <> $CountLocation Then
    Do
        $CountLocation = $CountLocation + 1
        $locationitems = $locationitems & "|" & IniRead ($path, $CountLocation, "Location", "")
    Until $record = $CountLocation
EndIf
Return $locationitems
EndFunc

Func ReadPrinterLocation()
$record = IniRead ($path, $location, "Printers", "")
$printeritems = IniRead ($path, $location, "Printer" & $CountPrinter, "")
If $record <> $CountPrinter Then
    Do
        $CountPrinter = $CountPrinter + 1
        $printeritems = $printeritems & "|" & IniRead ($path, $CountPrinter, "Location", "")
    Until $record = $CountPrinter
EndIf
Return $printeritems
EndFunc

Func LoadPrinters()
    $location = GuiRead ($location)
        GuiCtrlSetData ($printer, ReadPrinterLocation(), "")
        GuiCtrlSetState ($printer, $GUI_Enable)
EndFunc


; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
        If $msg = $location Then
      LoadPrinters()
        EndIf
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

INI File Example: settings.ini (Must be in same directory as script.)

[settings]

Records=2

[1]

Location=Accounting

[Accounting]

printers=1

printer1=printer93

printerdescription1=HP LaserJet 4000

[2]

Location=Sales

[sales]

printers=3

printer1=printer91-1

printerdescription1=HP LaserJet 6MP next to Jim Barth

printer2=printer90

printerdescription2=HP LaserJet 6MP in Front Lobby

printer3=printer95

printerdescription3=HP LaserJet 4500TN

Link to comment
Share on other sites

Thanks this-is-me!! I wasn't paying attention to that little detail. :">

The corrected code is below:

#include <GUIConstants.au3>

$path = @SCRIPTDIR & "\settings.ini"
$printeritems = "Accounting"
$CountLocation = 1
$CountPrinter = 1
Global $locationprinter

GUICreate("My GUI combo") ; will create a dialog box that when displayed is centered

$location = GUICtrlCreateCombo ("", 10,10); create first item
GUICtrlSetData(-1, ReadLocationINI(),""); add other item snd set a new default

$printer = GUICtrlCreateCombo ("", 10,40); create first item
GuiCtrlSetState (-1, $GUI_Disable)

GuiSetState ()


Func ReadLocationINI()
$record = IniRead ($path, "Settings", "Records", "")
$locationitems = IniRead ($path, $CountLocation, "Location", "")
If $record <> $CountLocation Then
    Do
        $CountLocation = $CountLocation + 1
        $locationitems = $locationitems & "|" & IniRead ($path, $CountLocation, "Location", "")
    Until $record = $CountLocation
EndIf
Return $locationitems
EndFunc

Func ReadPrinterLocation()
$record = IniRead ($path, $locationprinter, "Printers", "")
$printeritems = IniRead ($path, $locationprinter, "Printer" & $CountPrinter, "")
If $record <> $CountPrinter Then
    Do
        $CountPrinter = $CountPrinter + 1
        $printeritems = $printeritems & "|" & IniRead ($path, $locationprinter, "Printer" & $CountPrinter, "")
    Until $record = $CountPrinter
EndIf
Return $printeritems
EndFunc

Func LoadPrinters()
    $locationprinter = GuiRead ($location)
        GuiCtrlSetData ($printer, ReadPrinterLocation(), "")
        GuiCtrlSetState ($printer, $GUI_Enable)
EndFunc


; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
        If $msg = $location Then
      LoadPrinters()
        EndIf
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend
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...