Jump to content

[SOLVED]Config GUI; Saving to .Ini file using save button


JonBMN
 Share

Recommended Posts

I'm trying to make a GUI interface that recieves data from my Archangel.ini as default, but can be changed and then saved to the .ini from the GUI program. I'm having trouble creating the save button function that actually writes to the .ini file. Any help would be much appreciated.

My ConfigurationGUI.au3

#include <GlobalVars.au3>
#include <ArchLib.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
Global $ButtonSave, $ButtonCancel, $msg, $PRI1, $PRI2, $PRI3, $PRI4, $PRI5, $PRI6, $PRI7, $PRI8, $PRI9, $PRI10, $msg2


DecodeIni("Archangel.Ini", False) ;Decodes the .Ini File
;ConsoleWrite($IniProgramGroup & @CR)
GUICreate("Archangel Configuration Setup", 500, 400) ;Creates the GUI window
GUISetBkColor(0x00E0eeeF) ;Sets Background color
$ButtonSave = GUICtrlCreateButton("Save", 200, 350, 45, 30) ;Save button
$ButtonCancel = GUICtrlCreateButton("Cancel", 300, 350, 45, 30) ;Cancel Button
GUICtrlCreateTab(0, 0, 500, 340) ;Creates the tab
GUICtrlCreateTabItem("Speed") ;First tab item
GUICtrlCreateLabel("Speed Settings", 10, 25) ;Creates the label for the configuration drop down menu
GUICtrlCreateLabel("Show the Speed:", 10, 100) ;Creates the label for the Show the speed config
GUICtrlCreateLabel("Speed limit:", 10, 175) ;Creates the label for the Speed limit config
GUICtrlCreateCombo("", 275, 100) ;Creates the drop down box
GUICtrlSetData(10, "Yes|No", $ShowSpeed) ;Puts the data into the drop down box
GUICtrlCreateCombo("", 275, 175) ;Creates the drop down box
GUICtrlSetData(11, "1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30", $SpeedLimit) ;Puts the data into the drop down box

GUICtrlCreateTabItem("Serial Settings") ;Tab with serial settings
GUICtrlCreateLabel("Serial Settings", 10, 25) ;Creates the label for the serial settings
GUICtrlCreateLabel("Communications Port:", 10, 75) ;Creates the label for the commport setting
GUICtrlCreateLabel("Baudrate:", 10, 150) ;Creates the label for the Baudrate
GUICtrlCreateCombo("", 275, 75) ;Creates the drop down box
GUICtrlSetData(16, "1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50", $NumericPort) ;Puts data into drop down box
GUICtrlCreateCombo("", 275, 150) ;Creates drop down box
GUICtrlSetData(17, "2400|4800|9600|19200|38400|57600|115200|31250", $BaudRate) ;Puts data into drop down box

GUICtrlCreateTabItem("Accesories") ;keyboard, mouse, touchscreen options
GUICtrlCreateLabel("Accesories settings", 10, 25) ;Creates label for accesories settings
GUICtrlCreateLabel("Block options:", 10, 75) ;Creates the label for the block options
GUICtrlCreateCombo("", 275, 75) ;Creates the dorp down box
GUICtrlSetData(21, "None|Both|Mouse/Touchscreen|Keyboard", $AlphaBlock[$BlockOption]) ;Puts data into drop down box

GUICtrlCreateTabItem("Run Plates") ;Run plate option tab
GUICtrlCreateLabel("Ability to run plates", 10, 25) ;creates label for plate running config
GUICtrlCreateLabel("Run Plates", 10, 75) ;creates the label for plate running setting
GUICtrlCreateCombo("", 275, 75) ;creates drop down box
GUICtrlSetData(25, "Yes|No", $RunPlates) ;puts data into drop down box

GUICtrlCreateTabItem("Windows Priority") ;windows priority tab
GUICtrlCreateLabel("Select Windows Priority", 10, 25) ;creates label for windows priority config
GUICtrlCreateLabel("Priority 1:", 10, 40) ;creates label for windows priority 1
GUICtrlCreateLabel("Maximize:", 100, 40) ;creates label for maximize window
GUICtrlCreateLabel("Priority 2:", 10, 80) ;creates label for windows priority 2
GUICtrlCreateLabel("Maximize:", 100, 80) ;creates label for maximize window
GUICtrlCreateLabel("Priority 3:", 10, 120) ;creates label for windows priority 3
GUICtrlCreateLabel("Maximize:", 100, 120) ;creates label for maximize window
GUICtrlCreateLabel("Priority 4:", 10, 160) ;creates label for windows priority 4
GUICtrlCreateLabel("Maximize:", 100, 160) ;creates label for maximize window
GUICtrlCreateLabel("Priority 5:", 10, 200) ;creates label for windows priority 5
GUICtrlCreateLabel("Maximize:", 100, 200) ;creates label for maximize window
GUICtrlCreateLabel("Priority 6:", 200, 40) ;creates label for windows priority 6
GUICtrlCreateLabel("Maximize:", 300, 40) ;creates label for maximize window
GUICtrlCreateLabel("Priority 7:", 200, 80) ;creates label for windows priority 7
GUICtrlCreateLabel("Maximize:", 300, 80) ;creates label for maximize window
GUICtrlCreateLabel("Priority 8:", 200, 120) ;creates label for windows priority 8
GUICtrlCreateLabel("Maximize:", 300, 120) ;creates label for maximize window
GUICtrlCreateLabel("Priority 9:", 200, 160) ;creates label for windows priority 9
GUICtrlCreateLabel("Maximize:", 300, 160) ;creates label for maximize window
GUICtrlCreateLabel("Priority 10:", 200, 200) ;creates label for windows priority 10
GUICtrlCreateLabel("Maximize:", 300, 200) ;creates label for maximize window
GUICtrlCreateCombo("", 100, 55) ;Drop down box for maximize selection
GUICtrlSetData(48, "Yes|No", $IniMaximize[1]) ;puts data into drop down box for maximize selection
GUICtrlCreateCombo("", 100, 95) ;Drop down box for maximize selection
GUICtrlSetData(49, "Yes|No", $IniMaximize[2]) ;puts data into drop down box for maximize selection
GUICtrlCreateCombo("", 100, 135) ;Drop down box for maximize selection
GUICtrlSetData(50, "Yes|No", $IniMaximize[3]) ;puts data into drop down box for maximize selection
GUICtrlCreateCombo("", 100, 175) ;Drop down box for maximize selection
GUICtrlSetData(51, "Yes|No", $IniMaximize[4]) ;puts data into drop down box for maximize selection
GUICtrlCreateCombo("", 100, 215) ;Drop down box for maximize selection
GUICtrlSetData(52, "Yes|No", $IniMaximize[5]) ;puts data into drop down box for maximize selection
GUICtrlCreateCombo("", 300, 55) ;Drop down box for maximize selection
GUICtrlSetData(53, "Yes|No", $IniMaximize[6]) ;puts data into drop down box for maximize selection
GUICtrlCreateCombo("", 300, 95) ;Drop down box for maximize selection
GUICtrlSetData(54, "Yes|No", $IniMaximize[7]) ;puts data into drop down box for maximize selection
GUICtrlCreateCombo("", 300, 135) ;Drop down box for maximize selection
GUICtrlSetData(55, "Yes|No", $IniMaximize[8]) ;puts data into drop down box for maximize selection
GUICtrlCreateCombo("", 300, 175) ;Drop down box for maximize selection
GUICtrlSetData(56, "Yes|No", $IniMaximize[9]) ;puts data into drop down box for maximize selection
GUICtrlCreateCombo("", 300, 215) ;Drop down box for maximize selection
GUICtrlSetData(57, "Yes|No", $IniMaximize[10]) ;puts data into drop down box for maximize selection
$PRT1 = GUICtrlCreateCombo("", 10, 55) ;Drop down box for priority input
GUICtrlSetData(58, "Spillman Mobile|None|Example1|Example2", $IniPriority[1]) ;puts data into drop down box for priority input/selection
$PRT2 = GUICtrlCreateCombo("", 10, 95) ;Drop down box for priority input
GUICtrlSetData(59, "Spillman Mobile|None|Example1|Example2", $IniPriority[2]) ;puts data into drop down box for priority input/selection
$PRT3 = GUICtrlCreateCombo("", 10, 135) ;Drop down box for priority input
GUICtrlSetData(60, "Spillman Mobile|None|Example1|Example2", $IniPriority[3]) ;puts data into drop down box for priority input/selection
$PRT4 = GUICtrlCreateCombo("", 10, 175) ;Drop down box for priority input
GUICtrlSetData(61, "Spillman Mobile|None|Example1|Example2", $IniPriority[4]) ;puts data into drop down box for priority input/selection
$PRT5 = GUICtrlCreateCombo("", 10, 215) ;Drop down box for priority input
GUICtrlSetData(62, "Spillman Mobile|None|Example1|Example2", $IniPriority[5]) ;puts data into drop down box for priority input/selection
$PRT6 = GUICtrlCreateCombo("", 200, 55) ;Drop down box for priority input
GUICtrlSetData(63, "Spillman Mobile|None|Example1|Example2", $IniPriority[6]) ;puts data into drop down box for priority input/selection
$PRT7 = GUICtrlCreateCombo("", 200, 95) ;Drop down box for priority input
GUICtrlSetData(64, "Spillman Mobile|None|Example1|Example2", $IniPriority[7]) ;puts data into drop down box for priority input/selection
$PRT8 = GUICtrlCreateCombo("", 200, 135) ;Drop down box for priority input
GUICtrlSetData(65, "Spillman Mobile|None|Example1|Example2", $IniPriority[8]) ;puts data into drop down box for priority input/selection
$PRT9 = GUICtrlCreateCombo("", 200, 175) ;Drop down box for priority input
GUICtrlSetData(66, "Spillman Mobile|None|Example1|Example2", $IniPriority[9]) ;puts data into drop down box for priority input/selection
$PRT10 = GUICtrlCreateCombo("", 200, 215) ;Drop down box for priority input
GUICtrlSetData(67, "Spillman Mobile|None|Example1|Example2", $IniPriority[10]) ;puts data into drop down box for priority input/selection
GUISetState(@SW_SHOW) ;Shows the GUI window
;MsgBox(2, "Checker", $PRT1) ;Checks the ControlID
;MsgBox(2, "error detection", $DataSelect) ;error detection(combo 4)

;Makes cancel button and the close button(top right x) close the program
While -1
$msg = GUIGetMsg()
Select
Case $msg = $ButtonCancel Or $msg = $GUI_EVENT_CLOSE
Case "Show the speed"
If "Yes" Or "No" Then
FileWriteLine("Archangel.ini", 10)
EndIf
ExitLoop
EndSelect
WEnd

My GlobalVars.au3

; Path Variables
Global $IniName = "Archangel.ini"
Global $ProgramDir = @ProgramFilesDir & "\Archangel"

;From ini
Global $IniProgramGroup = ""
Global $IniVersion = ""
Global $ShowSpeed = "No"
Global $CommPort = ""
Global $NumericPort
Global $BaudRate = 9600
Global $SpeedLimit = 15
Global $ClearOnTop = "No"
Global $IniFiles, $IniFileName[10]
Global $IniPriorities, $IniPriority[11], $IniMaximize[11]
Global $RunPlates = "No"
Global $BlockOption = 1
Global $BlockMouse = True
Global $AlphaBlock[4]
$AlphaBlock[0] = "None"
$AlphaBlock[1] = "Both"
$AlphaBlock[2] = "Mouse/TouchScreen"
$AlphaBlock[3] = "Keyboard"

; Log Variables
Global $LogHandle = -1
Global $LogError = False
Global $LogDetail = "No"
Global $LogFile = ""
Global $Sequence = "Init"

; Log / Error / Debugs
Global $Debug = False
Global $IsErrorFatal = "No", $ErrorTitle = "", $ErrorMessage = ""

; Miscellaneous
Const $SpeedCursor = "Current speed is "
Global $LenSpeedCursor = StringLen($SpeedCursor)
Global $SFResult[2]
$SFResult[0] = "failed"
$SFResult[1] = "successful"

; Speed Variables
Global $LastSpeed = 0

; Communications to Herbie
Global $Kernel32Handle = -1
Global $SerialPortHandle = -1
Global $DCB_Struct = ""
Global $CommTimeout = ""
Global $CommTimeout_Struct = ""
Global $CommState = ""
Global $CommState_Struct = ""
Global $HerbieError = False
Global $ReceivedFromHerbie = ""
Global $SpeedValidation = "410D"
Global $CurrentSpeed = 0

; SDX Dongle
Global $SDXHandle = -1
Global $tSDXHID = DllStructCreate("DWORD")

My Archlib.au3

Func DecodeIni($FullIniPath, $LogIt)
Local $NotFound = "Not Found", $Result = 0, $Index = 0
$ErrorTitle = "Error Reading Initialization File"
$ErrorMessage = $FullIniPath
$IsErrorFatal = True
$IniProgramGroup = IniRead($FullIniPath, "Version", "ProgramGroup", $NotFound)
If $IniProgramGroup = $NotFound Then
MyError()
EndIf
$IniVersion = IniRead($FullIniPath, "Version", "VersionNumber", $NotFound)
If $IniVersion = $NotFound Then
_MyError()
EndIf
$NumericPort = IniRead($FullIniPath, "Communication", "Port", $NotFound)
If $IniVersion = $NotFound Then
_MyError()
EndIf
$CommPort = "COM" & $NumericPort
If ($NumericPort > 9) Then
$CommPort = "\\.\" & $CommPort
EndIf
$BaudRate = IniRead($FullIniPath, "Communication", "Baudrate", $NotFound)
If $IniVersion = $NotFound Then
_MyError()
EndIf
$SpeedLimit = IniRead($FullIniPath, "ProgramOptions", "SpeedLimit", $NotFound)
If $IniVersion = $NotFound Then
_MyError()
EndIf
$ShowSpeed = IniRead($FullIniPath, "ProgramOptions", "ShowSpeed", $NotFound)
If $IniVersion = $NotFound Then
_MyError()
EndIf
$ClearOnTop = IniRead($FullIniPath, "ProgramOptions", "ClearOnTop", $NotFound)
If $IniVersion = $NotFound Then
_MyError()
EndIf
$RunPlates = IniRead($FullIniPath, "ProgramOptions", "RunPlates", $NotFound)
If $IniVersion = $NotFound Then
_MyError()
EndIf
$Result = IniRead($FullIniPath, "ProgramOptions", "Block", $NotFound)
If $IniVersion = $NotFound Then
_MyError()
EndIf
$BlockMouse = True
Select
Case $Result = "None"
$BlockOption = 0
$BlockMouse = False
Case $Result = "Both"
$BlockOption = 1
Case $Result = "Mouse"
$BlockOption = 2
Case $Result = "Keyboard"
$BlockOption = 3
$BlockMouse = False
Case Else
$BlockOption = 0
EndSelect
$LogDetail = IniRead($FullIniPath, "LogOptions", "LogDetail", $NotFound)
If $IniVersion = $NotFound Then
_MyError()
EndIf
$LogFile = IniRead($FullIniPath, "LogOptions", "LogFile", $NotFound)
If $IniVersion = $NotFound Then
_MyError()
EndIf
$Index = 1
While 1
$IniFileName[$Index] = IniRead($FullIniPath, "Files", "File" & $Index, $NotFound)
If $IniFileName[$Index] = $NotFound Then
ExitLoop
EndIf
$Index += 1
WEnd
$IniFiles = $Index - 1
$Index = 1
While 1
$IniPriority[$Index] = IniRead($FullIniPath, "WindowPriorties", "WindowPriority" & $Index, $NotFound)
If $IniPriority[$Index] = $NotFound Then
ExitLoop
EndIf
$Index += 1
WEnd
$IniPriorities = $Index - 1
$Index = 1
While 1
$IniMaximize[$Index] = IniRead($FullIniPath, "WindowPriorties", "WindowMaximize" & $Index, $NotFound)
If $IniMaximize[$Index] = $NotFound Then
ExitLoop
EndIf
$Index += 1
WEnd
If $LogIt = False Then
Return
EndIf
WriteLog(" Ini Path: " & $FullIniPath)
WriteLog(" Program: " & $IniProgramGroup)
WriteLog(" Version: " & $IniVersion)
WriteLog(" Port: " & $CommPort)
WriteLog(" Baudrate: " & $BaudRate)
WriteLog("SpeedLimit: " & $SpeedLimit)
WriteLog(" ShowSpeed: " & $ShowSpeed)
WriteLog("ClearOnTop: " & $ClearOnTop)
WriteLog(" RunPlates: " & $RunPlates)
WriteLog(" Block: " & $AlphaBlock[$BlockOption])
WriteLog(" LogDetail: " & $LogDetail)
WriteLog(" LogFile: " & $LogFile)
WriteLog("Priorities: " & $IniPriorities)
If $IniPriorities >= 1 Then
For $Index = 1 To $IniPriorities
WriteLog("Priority " & $Index & ": " & $IniPriority[$Index])
WriteLog("Maximize " & $Index & ": " & $IniMaximize[$Index])
Next
EndIf
EndFunc

Func MyCopyProgressOn($Title, $SFileName, $DFileName, $FileSize, $Operation)
Local $DisplayName = ""
$DisplayName = "Source: " & StringLower($SFileName)
ProgressOn($Title, $DisplayName, "0 of " & _StringAddThousandsSepEx($FileSize) & " bytes " & $Operation & " (0%)")
EndFunc

Func MyCopyProgressSet($ProgressBytes, $FileSize, $Operation)
Local $Percent = 0
$Percent = Round((($ProgressBytes / $FileSize) * 100), 0)
If $Percent >= 100 Then
$Percent = 99
$ProgressBytes = $FileSize - 1
EndIf
ProgressSet($Percent, _StringAddThousandsSepEx($ProgressBytes) & " of " & _StringAddThousandsSepEx($FileSize) & " bytes " & $Operation & " (" & $Percent & "%)")
Sleep(1)
EndFunc

Func MyCopyProgressOff()
ProgressSet(100 , "Done")
Sleep(500)
ProgressOff()
EndFunc

Func MyError()
Beep()
MsgBox(0, $ErrorTitle, $ErrorMessage)
If $IsErrorFatal = True Then
Exit
EndIf
EndFunc

Func MyProgressCopy($FullSRC, $FullDST)
Dim $OptEnv = "", $OptVar = "", $size = 0, $count = 0, $timer = 0, $progress = 0, $in = 0, $out = 0
Local $Bin, $Chunk, $ProgTitle
$ErrorTitle = "Error Copying File"
$ErrorMessage = $FullSRC
$IsErrorFatal = True
; Turn off expanded environment or variables, can cause problems for binary read
$OptEnv = Opt("ExpandEnvStrings", 0)
$OptVar = Opt("ExpandVarStrings", 0)
; Get size of file to determine remaining
$Size = FileGetSize($FullSRC)
If $Size = 0 Then
MyError()
EndIf
; Set up initial variables
$Count = 0 ;keep count of bytes copied
$Chunk = 102400 ;amount of data to copy at a time (bytes) (10kB)
$Progtitle = "Copying File ..." ;title of progress bar window
$Timer = TimerInit() ;initialize timer to keep track of update frequency
; Show progress bar
MyCopyProgressOn("Copying File ...", $FullSRC, $FullDST, $size, "copied")
; Open input and output files (exit if error)
$In = FileOpen($FullSRC, 4)
If @error <> 0 Then
MyError()
EndIf
$Out = FileOpen($FullDST, 2)
If @error = -1 Then
FileClose($In)
MyError()
EndIf
; Start reading input
$Bin = FileRead($In, $Chunk)
While @error = 0
; Write chunk of data, keep trying for up to 10 seconds if failed
Do
FileWrite($Out, $Bin)
Until (@error = 0) Or (TimerDiff($timer) > 10000)
If @error <> 0 Then
FileClose($In)
FileClose($Out)
MyError()
EndIf
; Update copy counter
$Count = $Count + $Chunk
; Update progress as specified
MyCopyProgressSet($Count, $Size, "copied")
$timer = TimerInit()
; get chunk of data
$bin = FileRead($In, $Chunk)
WEnd
FileClose($In)
FileClose($Out)
MyCopyProgressOff()
; Reset expanded environment or variables
Opt("ExpandEnvStrings", $OptEnv)
Opt("ExpandVarStrings", $OptVar)
EndFunc

Func WaitWithProgress($Caption, $Seconds)
ProgressOn($Caption & ". Please wait ...", "")
Local $Loops = 0, $Delay = 0, $Percent = 0
$Loops = Round(($Seconds * 2.0),0)
$Delay = Round ((($Seconds / $Loops) * 1000), 0)
For $I = 1 to $Loops
$Percent = (($I / $Loops) * 100)
ProgressSet($Percent)
Sleep($Delay)
Next
ProgressOff()
EndFunc

Func TurnOffOnTop()
Local $Index = 0, $Result = 0, $WindowList, $iExStyles = 0, $Candidate = 0
$WindowList = WinList()
For $Index = 1 to $WindowList[0][0]
$iExStyles = _WinAPI_GetWindowLong($WindowList[$Index][1],$GWL_EXSTYLE)
$Candidate = ($WindowList[$Index][0] <> "") And (IsWindowVisible($WindowList[$Index][1]))
$Candidate = $Candidate And (BitAND($iExStyles,$WS_EX_TOPMOST))
$Candidate = $Candidate And (StringLeft($WindowList[$Index][0], $LenSpeedCursor) <> $SpeedCursor)
If $Candidate = 1 Then
$Result = WinSetOnTop($WindowList[$Index][1], "", 0)
WriteLog($WindowList[$Index][0] & " topmost set was: " & $SFResult[$Result])
EndIf
Next
EndFunc

Func IsWindowVisible($WindowHandle)
If BitAnd( WinGetState($WindowHandle), 2 ) Then
Return 1
Else
Return 0
EndIf
EndFunc

My Archangel.ini file

[Version]

ProgramGroup=Archangel

VersionNumber=1.00

[Communication]

Port=35

Baudrate=9600

[ProgramOptions]

SpeedLimit=25

ShowSpeed=No

ClearOnTop=Yes

RunPlates=No

Block=None

[LogOptions]

LogDetail=No

LogFile=Archangel.log

[Files]

File1=Archangel.exe

File2=sdx.dll

File3=Green.ico

File4=Red.ico

[WindowPriorties]

WindowPriority1=Spillman Mobile -

WindowMaximize1=Yes

Edited by JonBMN
Link to comment
Share on other sites

Just reverse the process you use to read from the INI file when you're writing to it. When you press save, you can (for example) use IniWrite($FullIniPath, "LogOptions", "LogDetail", $LogDetail). This will write to the LogOptions section, in the key LogDetail the contents of the variable $LogDetail.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I'm not a mind reader, post the script so I can see what you're doing and perhaps I can figure out what is wrong.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

#include <GlobalVars.au3>
#include <ArchLib.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
Global $ButtonSave, $ButtonCancel, $msg, $PRI1, $PRI2, $PRI3, $PRI4, $PRI5, $PRI6, $PRI7, $PRI8, $PRI9, $PRI10, $msg2


DecodeIni("Archangel.Ini", False)   ;Decodes the .Ini File
;ConsoleWrite($IniProgramGroup & @CR)
GUICreate("Archangel Configuration Setup", 500, 400)   ;Creates the GUI window
GUISetBkColor(0x00E0eeeF)   ;Sets Background color
$ButtonSave = GUICtrlCreateButton("Save", 200, 350, 45, 30)   ;Save button
$ButtonCancel = GUICtrlCreateButton("Cancel", 300, 350, 45, 30)    ;Cancel Button
GUICtrlCreateTab(0, 0, 500, 340)   ;Creates the tab
GUICtrlCreateTabItem("Speed")   ;First tab item
GUICtrlCreateLabel("Speed Settings", 10, 25)   ;Creates the label for the configuration drop down menu
GUICtrlCreateLabel("Show the Speed:", 10, 100)  ;Creates the label for the Show the speed config
GUICtrlCreateLabel("Speed limit:", 10, 175)   ;Creates the label for the Speed limit config
GUICtrlCreateCombo("", 275, 100)   ;Creates the drop down box
GUICtrlSetData(10, "Yes|No", $ShowSpeed)    ;Puts the data into the drop down box
GUICtrlCreateCombo("", 275, 175)   ;Creates the drop down box
GUICtrlSetData(11, "1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30", $SpeedLimit)    ;Puts the data into the drop down box

GUICtrlCreateTabItem("Serial Settings")    ;Tab with serial settings
GUICtrlCreateLabel("Serial Settings", 10, 25)   ;Creates the label for the serial settings
GUICtrlCreateLabel("Communications Port:", 10, 75)    ;Creates the label for the commport setting
GUICtrlCreateLabel("Baudrate:", 10, 150)    ;Creates the label for the Baudrate
GUICtrlCreateCombo("", 275, 75)   ;Creates the drop down box
GUICtrlSetData(16, "1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50", $NumericPort)   ;Puts data into drop down box
GUICtrlCreateCombo("", 275, 150)   ;Creates drop down box
GUICtrlSetData(17, "2400|4800|9600|19200|38400|57600|115200|31250", $BaudRate)  ;Puts data into drop down box

GUICtrlCreateTabItem("Accesories")   ;keyboard, mouse, touchscreen options
GUICtrlCreateLabel("Accesories settings", 10, 25)   ;Creates label for accesories settings
GUICtrlCreateLabel("Block options:", 10, 75) ;Creates the label for the block options
GUICtrlCreateCombo("", 275, 75) ;Creates the dorp down box
GUICtrlSetData(21, "None|Both|Mouse/Touchscreen|Keyboard", $AlphaBlock[$BlockOption]) ;Puts data into drop down box 

GUICtrlCreateTabItem("Run Plates") ;Run plate option tab
GUICtrlCreateLabel("Ability to run plates", 10, 25)  ;creates label for plate running config
GUICtrlCreateLabel("Run Plates", 10, 75) ;creates the label for plate running setting
GUICtrlCreateCombo("", 275, 75) ;creates drop down box
GUICtrlSetData(25, "Yes|No", $RunPlates) ;puts data into drop down box

GUICtrlCreateTabItem("Windows Priority") ;windows priority tab
GUICtrlCreateLabel("Select Windows Priority", 10, 25) ;creates label for windows priority config
GUICtrlCreateLabel("Priority 1:", 10, 40)  ;creates label for windows priority 1
GUICtrlCreateLabel("Maximize:", 100, 40)    ;creates label for maximize window
GUICtrlCreateLabel("Priority 2:", 10, 80)   ;creates label for windows priority 2
GUICtrlCreateLabel("Maximize:", 100, 80)  ;creates label for maximize window
GUICtrlCreateLabel("Priority 3:", 10, 120)   ;creates label for windows priority 3
GUICtrlCreateLabel("Maximize:", 100, 120)   ;creates label for maximize window
GUICtrlCreateLabel("Priority 4:", 10, 160)   ;creates label for windows priority 4
GUICtrlCreateLabel("Maximize:", 100, 160)   ;creates label for maximize window
GUICtrlCreateLabel("Priority 5:", 10, 200)   ;creates label for windows priority 5
GUICtrlCreateLabel("Maximize:", 100, 200)   ;creates label for maximize window
GUICtrlCreateLabel("Priority 6:", 200, 40)   ;creates label for windows priority 6
GUICtrlCreateLabel("Maximize:", 300, 40)   ;creates label for maximize window
GUICtrlCreateLabel("Priority 7:", 200, 80)   ;creates label for windows priority 7
GUICtrlCreateLabel("Maximize:", 300, 80)    ;creates label for maximize window
GUICtrlCreateLabel("Priority 8:", 200, 120)  ;creates label for windows priority 8
GUICtrlCreateLabel("Maximize:", 300, 120)    ;creates label for maximize window
GUICtrlCreateLabel("Priority 9:", 200, 160)  ;creates label for windows priority 9
GUICtrlCreateLabel("Maximize:", 300, 160)   ;creates label for maximize window
GUICtrlCreateLabel("Priority 10:", 200, 200)   ;creates label for windows priority 10
GUICtrlCreateLabel("Maximize:", 300, 200)   ;creates label for maximize window
GUICtrlCreateCombo("", 100, 55)      ;Drop down box for maximize selection
GUICtrlSetData(48, "Yes|No", $IniMaximize[1])  ;puts data into drop down box for maximize selection
GUICtrlCreateCombo("", 100, 95)   ;Drop down box for maximize selection
GUICtrlSetData(49, "Yes|No", $IniMaximize[2])  ;puts data into drop down box for maximize selection
GUICtrlCreateCombo("", 100, 135)    ;Drop down box for maximize selection
GUICtrlSetData(50, "Yes|No", $IniMaximize[3])   ;puts data into drop down box for maximize selection
GUICtrlCreateCombo("", 100, 175)      ;Drop down box for maximize selection
GUICtrlSetData(51, "Yes|No", $IniMaximize[4])    ;puts data into drop down box for maximize selection
GUICtrlCreateCombo("", 100, 215)    ;Drop down box for maximize selection
GUICtrlSetData(52, "Yes|No", $IniMaximize[5])    ;puts data into drop down box for maximize selection
GUICtrlCreateCombo("", 300, 55)    ;Drop down box for maximize selection
GUICtrlSetData(53, "Yes|No", $IniMaximize[6])  ;puts data into drop down box for maximize selection
GUICtrlCreateCombo("", 300, 95)   ;Drop down box for maximize selection
GUICtrlSetData(54, "Yes|No", $IniMaximize[7])     ;puts data into drop down box for maximize selection
GUICtrlCreateCombo("", 300, 135)   ;Drop down box for maximize selection
GUICtrlSetData(55, "Yes|No", $IniMaximize[8])   ;puts data into drop down box for maximize selection
GUICtrlCreateCombo("", 300, 175)   ;Drop down box for maximize selection
GUICtrlSetData(56, "Yes|No", $IniMaximize[9])   ;puts data into drop down box for maximize selection
GUICtrlCreateCombo("", 300, 215)    ;Drop down box for maximize selection
GUICtrlSetData(57, "Yes|No", $IniMaximize[10])   ;puts data into drop down box for maximize selection
$PRT1 = GUICtrlCreateCombo("", 10, 55)    ;Drop down box for priority input
GUICtrlSetData(58, "Spillman Mobile|None|Example1|Example2", $IniPriority[1])  ;puts data into drop down box for priority input/selection
$PRT2 = GUICtrlCreateCombo("", 10, 95)    ;Drop down box for priority input
GUICtrlSetData(59, "Spillman Mobile|None|Example1|Example2", $IniPriority[2])  ;puts data into drop down box for priority input/selection
$PRT3 = GUICtrlCreateCombo("", 10, 135)    ;Drop down box for priority input
GUICtrlSetData(60, "Spillman Mobile|None|Example1|Example2", $IniPriority[3])  ;puts data into drop down box for priority input/selection
$PRT4 = GUICtrlCreateCombo("", 10, 175)    ;Drop down box for priority input
GUICtrlSetData(61, "Spillman Mobile|None|Example1|Example2", $IniPriority[4])  ;puts data into drop down box for priority input/selection
$PRT5 = GUICtrlCreateCombo("", 10, 215)    ;Drop down box for priority input
GUICtrlSetData(62, "Spillman Mobile|None|Example1|Example2", $IniPriority[5])  ;puts data into drop down box for priority input/selection
$PRT6 = GUICtrlCreateCombo("", 200, 55)    ;Drop down box for priority input
GUICtrlSetData(63, "Spillman Mobile|None|Example1|Example2", $IniPriority[6])  ;puts data into drop down box for priority input/selection
$PRT7 = GUICtrlCreateCombo("", 200, 95)    ;Drop down box for priority input
GUICtrlSetData(64, "Spillman Mobile|None|Example1|Example2", $IniPriority[7])  ;puts data into drop down box for priority input/selection
$PRT8 = GUICtrlCreateCombo("", 200, 135)    ;Drop down box for priority input
GUICtrlSetData(65, "Spillman Mobile|None|Example1|Example2", $IniPriority[8])  ;puts data into drop down box for priority input/selection
$PRT9 = GUICtrlCreateCombo("", 200, 175)    ;Drop down box for priority input
GUICtrlSetData(66, "Spillman Mobile|None|Example1|Example2", $IniPriority[9])  ;puts data into drop down box for priority input/selection
$PRT10 = GUICtrlCreateCombo("", 200, 215)    ;Drop down box for priority input
GUICtrlSetData(67, "Spillman Mobile|None|Example1|Example2", $IniPriority[10])  ;puts data into drop down box for priority input/selection
GUISetState(@SW_SHOW)    ;Shows the GUI window
;MsgBox(2, "Checker", $PRT1)   ;Checks the ControlID
;MsgBox(2, "error detection", $DataSelect)   ;error detection(combo 4)

;Makes cancel button and the close button(top right x) close the program
While -1
   $msg = GUIGetMsg()
   Select
   Case $msg = $ButtonCancel Or $msg = $GUI_EVENT_CLOSE
   Case $ButtonSave 
 IniWrite("Archangel.ini", "Show the speed", $ShowSpeed, 10)

   ExitLoop
   EndSelect
WEnd

Link to comment
Share on other sites

It exits because you put an ExitLoop in there after the first IniWrite statement, after it leaves the While loop, there's nothing left for it to do so it closes.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Fixed:

While -1
$msg = GUIGetMsg()
Select
Case $msg = $ButtonCancel Or $msg = $GUI_EVENT_CLOSE
Quit()
Case $ButtonSave
$result = IniWrite("Archangel.ini", "ProgramOptions", "ShowSpeed", $ShowSpeed)
ConsoleWrite($result & $ShowSpeed & @CR)
EndSelect
WEnd

Func Quit()
Exit
EndFunc

It still does not save yes to the $ShowSpeed variable

Edited by JonBMN
Link to comment
Share on other sites

Is $ShowSpeed a variable that holds a control ID for a control of some sort? If so, use GUICtrlRead($ShowSpeed) instead.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Using the GUICtrlRead function instead of putting in the $ShowSpeed variable, which did not particularly work, I put in the handle for the drop down box selection GUICtrlRead(10); which succesfully worked.

Edited by JonBMN
Link to comment
Share on other sites

Never EVER use hard coded numbers in place of controlIDs or handles. Assign the control IDs and handles to a variable when you create the controls in your script, and always use the variable in the rest of the script. All it takes is for you to add or remove a control and the whole script starts acting weird, with no indication of why it's acting the way it is.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Obviously I didn't mean assign them all to the same variable, that would be silly. You create either a separate variable for each control you're going to need to interact with later, or create one array that holds all the control IDs.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I'm having trouble getting the $Index to hold the 1-10 numbers so that I don't have to write all the windows priorities out and instead use a loop to plugin 1, 2, 3, etc.. If more of my code needs to be posted let me know, but thanks for the help everyone.

Figured it out; heres the code for it.

;creates the while loop for the cancel button and the save button/saves configuration settings as well
While -1
   $msg = GUIGetMsg()
   Select
   Case $msg = $ButtonCancel Or $msg = $GUI_EVENT_CLOSE
 Quit()
   Case $ButtonSave 
 IniWrite("Archangel.ini", "ProgramOptions", "ShowSpeed", GUICtrlRead($Speed1))
 IniWrite("Archangel.ini", "ProgramOptions", "SpeedLimit", GUICtrlRead($Speed2))
 IniWrite("Archangel.ini", "Communication", "Port", GUICtrlRead($Commun1))
 IniWrite("Archangel.ini", "Communication", "Baudrate", GUICtrlRead($Commun2))
 IniWrite("Archangel.ini", "ProgramOptions", "Block", GUICtrlRead($Block1))
 IniWrite("Archangel.ini", "ProgramOptions", "RunPlates", GUICtrlRead($RunP1))
      ;creates a for loop to plugin 1-10 using index for the windows priorities and maximize boxes
 For $Index = 1 to 10
        IniWrite("Archangel.ini", "WindowPriorties", "WindowPriority" & $Index, GUICtrlRead($PRI[$Index]))
   IniWrite("Archangel.ini", "WindowPriorties", "WindowMaximize"  & $Index, GUICtrlRead($MAX[$Index]))
      Next
;ConsoleWrite($result & $ShowSpeed & @CR)    ;error detector
   EndSelect
WEnd
Edited by JonBMN
Link to comment
Share on other sites

I have another question. Lets say that one of my windows priorities is "Example1" and I want to enter Example2 into the program; instead of the code; how if I'm using GUICtrlCreateCombo and GUISetData would I be able to do this?

EDIT: There is no way to do what I wanted to do with GUICtrlCreateCombo; I had to change all of them to GUICtrlCreateInput like so:

$PRI[1] = GUICtrlCreateInput("", 10, 55, 100) ;creates input control
GUICtrlSetData($PRI[1], $IniPriority[1], $IniPriority[1]) ;puts data into input control for priority input
Edited by JonBMN
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

×
×
  • Create New...