Jump to content
Sign in to follow this  
JonBMN

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

Recommended Posts

JonBMN

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

Share this post


Link to post
Share on other sites
BrewManNH

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

Share this post


Link to post
Share on other sites
JonBMN

Thank you BrewManNH I shall try that out and post my results.

Share this post


Link to post
Share on other sites
JonBMN

I'm stuck on getting the window to stay open because of the case statements I put in to save to the .ini file. Any suggestions?

Share this post


Link to post
Share on other sites
BrewManNH

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

Share this post


Link to post
Share on other sites
JonBMN

#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

Share this post


Link to post
Share on other sites
JonBMN

This is the first time I've done this and am still learning; so don't be to harsh :)

Share this post


Link to post
Share on other sites
BrewManNH

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

Share this post


Link to post
Share on other sites
JonBMN

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

Share this post


Link to post
Share on other sites
BrewManNH

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

Share this post


Link to post
Share on other sites
JonBMN

Thank you BrewMan

EDIT: $ShowSpeed was the variable that holds the default selection from the .ini

Edited by JonBMN

Share this post


Link to post
Share on other sites
JonBMN

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

Share this post


Link to post
Share on other sites
JonBMN

Also tried the same for the SpeedLimit selection with GUICtrlRead(11); it worked successfully as well.

Share this post


Link to post
Share on other sites
BrewManNH

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

Share this post


Link to post
Share on other sites
JonBMN

Can you show me an example of the single variable holding all the controlIDs? I don't know if you meant variables or really did mean variable

Share this post


Link to post
Share on other sites
BrewManNH

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

Share this post


Link to post
Share on other sites
JonBMN

Okay thank you for the clarification.

Share this post


Link to post
Share on other sites
JonBMN

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

Share this post


Link to post
Share on other sites
JonBMN

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

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
Sign in to follow this  

  • Similar Content

    • PuneetTewani
      By PuneetTewani
      Mouse click (using coordinates) not working on NSE NOW software. Works well everywhere else.
    • TheDcoder
      By TheDcoder
      Hello Guys! I wanted to share all my knowledge on arrays! Hope may enjoy the article , Lets start!
      Declaring arrays!
      Declaring arrays is a little different than other variables: 
      ; Rules to follow while declaring arrays: ; ; Rule #1: You must have a declarative keyword like Dim/Global/Local before the declaration unless the array is assigned a value from a functions return (Ex: StringSplit) ; Rule #2: You must declare the number of dimensions but not necessarily the size of the dimension if you are gonna assign the values at the time of declaration. #include <Array.au3> Local $aEmptyArray[0] ; Creates an Array with 0 elements (aka an Empty Array). Local $aArrayWithData[1] = ["Data"] _ArrayDisplay($aEmptyArray) _ArrayDisplay($aArrayWithData) That's it
      Resizing Arrays
      Its easy! Just like declaring an empty array! ReDim is our friend here:
      #include <Array.au3> Local $aArrayWithData[1] = ["Data1"] ReDim $aArrayWithData[2] ; Change the number of elements in the array, I have added an extra element! $aArrayWithData[1] = "Data2" _ArrayDisplay($aArrayWithData) Just make sure that you don't use ReDim too often (especially don't use it in loops!), it can slow down you program.
      Best practice of using "Enum"
      You might be wondering what they might be... Do you know the Const keyword which you use after Global/Local keyword? Global/Local are declarative keywords which are used to declare variables, of course, you would know that already by now , If you check the documentation for Global/Local there is a optional parameter called Const which willl allow you to "create a constant rather than a variable"... Enum is similar to Const, it declares Integers (ONLY Integers):
      Global Enum $ZERO, $ONE, $TWO, $THREE, $FOUR, $FIVE, $SIX, $SEVEN, $EIGHT, $NINE ; And so on... ; $ZERO will evaluate to 0 ; $ONE will evaluate to 1 ; You get the idea :P ; Enum is very useful to declare Constants each containing a number (starting from 0) This script will demonstrate the usefulness and neatness of Enums :
      ; We will create an array which will contain details of the OS Global Enum $ARCH, $TYPE, $LANG, $VERSION, $BUILD, $SERVICE_PACK Global $aOS[6] = [@OSArch, @OSType, @OSLang, @OSVersion, @OSBuild, @OSServicePack] ; Now, if you want to access anything related to the OS, you would do this: ConsoleWrite(@CRLF) ConsoleWrite('+>' & "Architecture: " & $aOS[$ARCH] & @CRLF) ConsoleWrite('+>' & "Type: " & $aOS[$TYPE] & @CRLF) ConsoleWrite('+>' & "Langauge: " & $aOS[$LANG] & @CRLF) ConsoleWrite('+>' & "Version: " & $aOS[$VERSION] & @CRLF) ConsoleWrite('+>' & "Build: " & $aOS[$BUILD] & @CRLF) ConsoleWrite('+>' & "Service Pack: " & $aOS[$SERVICE_PACK] & @CRLF) ConsoleWrite(@CRLF) ; Isn't it cool? XD You can use this in your UDF(s) or Program(s), it will look very neat!
      Looping through an Array
      Looping through an array is very easy! . There are 2 ways to loop an array in AutoIt!
      Simple Way:
      ; This is a very basic way to loop through an array ; In this way we use a For...In...Next Loop! Global $aArray[2] = ["Foo", "Bar"] ; Create an array ; This loop will loop 2 times because our $aArray contains 2 elements. For $vElement In $aArray ; $vElement will contain the value of the elements in the $aArray... one element at a time. ConsoleWrite($vElement & @CRLF) ; Prints the element out to the console Next ; And that's it! Advanced Way:
      ; This is an advanced way to loop through an array ; In this way we use a For...To...Next Loop! Global $aArray[4] = ["Foo", "Bar", "Baz", "Quack"] ; Create an array ; This loop will loop 2 times because our $aArray contains 2 elements. For $i = 0 To UBound($aArray) - 1 ; $i is automatically created and is set to zero, UBound($aArray) returns the no. of elements in the $aArray. ConsoleWrite($aArray[$i] & @CRLF) ; Prints the element out to the console. Next ; This is the advanced way, we use $i to access the elements! ; With the advanced method you can also use the Step keyword to increase the offset in each "step" of the loop: ; This will only print every 2nd element starting from 0 ConsoleWrite(@CRLF & "Every 2nd element: " & @CRLF) For $i = 0 To UBound($aArray) - 1 Step 2 ConsoleWrite($aArray[$i] & @CRLF) Next ; This will print the elements in reverse order! ConsoleWrite(@CRLF & "In reverse: " & @CRLF) For $i = UBound($aArray) - 1 To 0 Step -1 ConsoleWrite($aArray[$i] & @CRLF) Next ; And that ends this section! For some reason, many people use the advance way more than the simple way . For more examples of loops see this post by @FrancescoDiMuro!
      Interpreting Multi-Dimensional Arrays
      Yeah, its the most brain squeezing problem for newbies, Imagining an 3D Array... I will explain it in a very simple way for ya, so stop straining you brain now! . This way will work for any array regardless of its dimensions...
      Ok, Lets start... You can imagine an array as a (data) mine of information:

      ; Note that: ; Dimension = Level (except the ground level :P) ; Element in a Dimension = Path ; Level 2 ----------\ ; Level 1 -------\ | ; Level 0 ----\ | | ; v v v Local $aArray[2][2][2] ; \-----/ ; | ; v ; Ground Level ; As you can see that $aArray is the Ground Level ; All the elements start after the ground level, i.e from level 0 ; Level 0 Contains 2 different paths ; Level 1 Contains 4 different paths ; Level 2 Contains 8 different paths ; When you want too fill some data in the data mine, ; You can do that like this: $aArray[0][0][0] = 1 $aArray[0][0][1] = 2 $aArray[0][1][0] = 3 $aArray[0][1][1] = 4 $aArray[1][0][0] = 5 $aArray[1][0][1] = 6 $aArray[1][1][0] = 7 $aArray[1][1][1] = 8 ; Don't get confused with the 0s & 1s, Its just tracing the path! ; Try to trace the path of a number with the help of the image! Its super easy! :D I hope you might have understand how an array looks, Mapping your way through is the key in Multi-Dimensional arrays, You take the help of notepad if you want! Don't be shy!
      Frequently Asked Questions (FAQs) & Their answers
      Q #1. What are Arrays?
      A. An Array is an datatype of an variable (AutoIt has many datatypes of variables like "strings", "integers" etc. Array is one of them). An Array can store information in a orderly manner. An Array consist of elements, each element can be considered as a variable (and yes, each element has its own datatype!). AutoIt can handle 16,777,216 elements in an Array, If you have an Array with 16,777,217 elements then AutoIt crashes.
      Q #2. Help! I get an error while declaring an Array!?
      A. You tried to declare an array like this:
      $aArray[1] = ["Data"] That is not the right way, Array is a special datatype, since its elements can be considered as individual variables you must have an declarative keyword like Dim/Global/Local before the declaration, So this would work:
      Local $aArray[1] = ["Data"] Q #3. How can I calculate the no. of elements in an array?
      A. The UBound function is your answer, Its what exactly does! If you have an multi-dimensional Array you can calculate the total no. of elements in that dimension by specifying the dimension in the second parameter of UBound
      Q #4. Why is my For...Next loop throwing an error while processing an Array?
      A.  You might have done something like this:
      #include <MsgBoxConstants.au3> Local $aArray[10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Local $iMyNumber = 0 For $i = 0 To UBound($aArray) ; Concentrate here! $iMyNumber += $aArray[$i] Next MsgBox($MB_OK, "Sum of all Numbers!", $iMyNumber) Did you notice the mistake? UBound returns the no. of elements in an array with the index starting from 1! That's right, you need to remove 1 from the total no. of elements in order to process the array because the index of an array starts with 0! So append a simple - 1 to the statment:
      #include <MsgBoxConstants.au3> Local $aArray[10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Local $iMyNumber = 0 For $i = 0 To UBound($aArray) - 1 $iMyNumber += $aArray[$i] Next MsgBox($MB_OK, "Sum of all Numbers!", $iMyNumber) Q #5. Can an Array contain an Array? How do I access an Array within an Array?
      A. Yes! It is possible that an Array can contain another Array! Here is an example of an Array within an Array:
      ; An Array can contain another Array in one of its elements ; Let me show you an example of what I mean ;) #include <Array.au3> Global $aArray[2] $aArray[0] = "Foo" Global $aChildArray[1] = ["Bar"] $aArray[1] = $aChildArray _ArrayDisplay($aArray) ; Did you see that!? The 2nd element is an {Array} :O ; But how do we access it??? ; You almost guessed it, like this: ; Just envolope the element which contains the {Array} (as shown in _ArrayDisplay) with brackets (or parentheses)! :D ConsoleWrite(($aArray[1])[0]) ; NOTE the brackets () around $aArray[1]!!! They are required or you would get an syntax error! ; So this: $aArray[1][0] wont work!  
      More FAQs coming soon!
    • Sven-Seyfert
      By Sven-Seyfert
      Hi Community,

      I use a UDF by @smashly to play a video in a GUI. That works fine for my main monitor.
      But when I change the X and Y positions of the GUI (also for the video) to my second or third monitor, the video plays, I can hear the sound of it, but I don't see the video.

      I debugged the UDF and checked the Microsoft description for MCI Command Strings which are used in the UDF (docs.microsoft...) - everything is fine, so I got no clue why the video isn't displayed.

      PlayVideoTest.au3:
       
      VideoInGui_by_Smashky.au3 (UDF):
       
      The example video:
       
      It would be great when anyone can help .
      Is there maybe a other way to play (display videos in GUI)?

      Thanks for any suggestion - I'm grateful!
      Sven
    • simonc8
      By simonc8
      I have a script which executes sleep for a couple of hours then carries out instructions. Does the running AutoIt script prevent the computer from entering sleep mode during this time? If not, is there something I can add to the AutoIt script to keep the computer awake?
      Grateful for advice.
    • gahhon
      By gahhon
      Hi,
      I have a program that is read data from the .txt file, since the .txt file is only readable, viewable and editable for the admin user.
      But how could I lock it with password, or some other technique that can helps to achieve this?
      Thanks for the advanced information.
×