Jump to content
Sign in to follow this  
Joel

Array Controls

Recommended Posts

Joel

Hi folks,

I'm very good at figuring things out once I see a creative example, so I would like to defer to those of you who know more about arrays than I do. I know very little about arrays.

As I'm creating a very large script and will have to chop it into smaller files, I'm hoping that I can use arrays for many of the controls. Here's an example of what the script looks like so far.

If someone more creative than me can look it over and perhaps offer some examples of how to use arrays with it to make the code cleaner and more functional, I would greatly appreciate it.

You can compile it to see what it looks like. Thanks,..

#include <GUIConstants.au3>

GUICreate ("Opti-Bot", 700, 600)

GUISetFont (9, 330)

Global $textcol = "0x253E5D"
Global $opts = 0; Options Default
Global $tab = GUICtrlCreateTab (0, 0, 700, 600)
;******** Tab Zero **************************************************************
Global $tab0 = GUICtrlCreateTabitem ("Start")
GUICtrlSetState (-1, $GUI_SHOW)
GUICtrlCreateGroup ("Create a new script", 10, 50, 430, 160)
GUICtrlCreateLabel ("If this is your first time using this utility, read the help file by pressing (F1) at", 20, 70, 410, 20)
GUICtrlCreateLabel ("anytime. Making a new script can be daunting, but with patience and ", 20, 85, 410, 20)
GUICtrlCreateLabel ("guidance you will be making new scripts with relative ease. In order to start", 20, 100, 410, 20)
GUICtrlCreateLabel ("creating a script, we need to take care of some basics first.", 20, 115, 410, 20)
GUICtrlCreateLabel ("With all scripts, you should input basic information that relates version,", 20, 145, 410, 20)
GUICtrlCreateLabel ("language, platform, author, and functional descriptions to tell the user", 20, 160, 410, 20)
GUICtrlCreateLabel ("what the script is being used for. So, let's do that now.", 20, 175, 410, 20)
;End Intro
GUICtrlCreateLabel ("AutoIt Version:", 120, 250, 100, 20)
Global $tab0infoinp = GUICtrlCreateInput ("Version Number", 260, 250, 250, 20)
GUICtrlCreateLabel ("Language:", 120, 270, 100, 20)
Global $tab0infoinp1 = GUICtrlCreateInput ("English", 260, 270, 250, 20)
GUICtrlCreateLabel ("Platform:", 120, 290, 100, 20)
Global $tab0infoinp2 = GUICtrlCreateInput ("Windows 2000", 260, 290, 250, 20)
GUICtrlCreateLabel ("Author:", 120, 310, 100, 20)
Global $tab0infoinp3 = GUICtrlCreateInput ("Your Name", 260, 310, 250, 20)
GUICtrlCreateLabel ("Email Address:", 120, 330, 100, 20)
Global $tab0infoinp4 = GUICtrlCreateInput ("email@address.com", 260, 330, 250, 20)
GUICtrlCreateLabel ("Script Function:", 120, 350, 100, 20)
Global $tab0infoinp5 = GUICtrlCreateInput ("Place script description here", 260, 350, 250, 70)
Global $tab0fileinp = GUICtrlCreateInput ("~filename.au3", 260, 430, 100, 20)
Global $tab0infosub = GUICtrlCreateButton ("Submit", 368, 430, 70, 20)
;******* Tab One *****************************************************************
Global $tab1 = GUICtrlCreateTabitem ("Options")
GUICtrlCreateGroup ("Autoit Default Options", 10, 50, 430, 520)
GUICtrlCreateLabel ("Include", 15, 80, 150, 15)
Global $tab1radopt1 = GUICtrlCreateRadio ("CaretCoordMode", 27, 100, 150, 20)
Global $tab1radinp1 = GUICtrlCreateInput ("1", 200, 100, 100, 17)
Global $tab1radbut1 = GUICtrlCreateButton ("Set", 330, 100, 40, 17)
Global $tab1radinfo1 = GUICtrlCreateButton ("Info", 390, 100, 40, 17)
Global $tab1radopt2 = GUICtrlCreateRadio ("ColorMode", 27, 117, 150, 20)
Global $tab1radinp2 = GUICtrlCreateInput ("0", 200, 117, 100, 17)
Global $tab1radbut2 = GUICtrlCreateButton ("Set", 330, 117, 40, 17)
Global $tab1radinfo2 = GUICtrlCreateButton ("Info", 390, 117, 40, 17)
Global $tab1radopt3 = GUICtrlCreateRadio ("ExpandEnvStrings", 27, 134, 150, 20)
Global $tab1radinp3 = GUICtrlCreateInput ("0", 200, 134, 100, 17)
Global $tab1radbut3 = GUICtrlCreateButton ("Set", 330, 134, 40, 17)
Global $tab1radinfo3 = GUICtrlCreateButton ("Info", 390, 134, 40, 17)
Global $tab1radopt4 = GUICtrlCreateRadio ("ExpandVarStrings", 27, 151, 150, 20)
Global $tab1radinp4 = GUICtrlCreateInput ("0", 200, 151, 100, 17)
Global $tab1radbut4 = GUICtrlCreateButton ("Set", 330, 151, 40, 17)
Global $tab1radinfo4 = GUICtrlCreateButton ("Info", 390, 151, 40, 17)
Global $tab1radopt5 = GUICtrlCreateRadio ("FtpBinaryMode", 27, 168, 150, 20)
Global $tab1radinp5 = GUICtrlCreateInput ("1", 200, 168, 100, 17)
Global $tab1radbut5 = GUICtrlCreateButton ("Set", 330, 168, 40, 17)
Global $tab1radinfo5 = GUICtrlCreateButton ("Info", 390, 168, 40, 17)
Global $tab1radopt6 = GUICtrlCreateRadio ("GUICoordMode", 27, 185, 150, 20)
Global $tab1radinp6 = GUICtrlCreateInput ("1", 200, 185, 100, 17)
Global $tab1radbut6 = GUICtrlCreateButton ("Set", 330, 185, 40, 17)
Global $tab1radinfo6 = GUICtrlCreateButton ("Info", 390, 185, 40, 17)
Global $tab1radopt7 = GUICtrlCreateRadio ("GUIOnEventMode", 27, 202, 150, 20)
Global $tab1radinp7 = GUICtrlCreateInput ("0", 200, 202, 100, 17)
Global $tab1radbut7 = GUICtrlCreateButton ("Set", 330, 202, 40, 17)
Global $tab1radinfo7 = GUICtrlCreateButton ("Info", 390, 202, 40, 17)
Global $tab1radopt8 = GUICtrlCreateRadio ("GUIResizeMode", 27, 219, 150, 20)
Global $tab1radinp8 = GUICtrlCreateInput ("0", 200, 219, 100, 17)
Global $tab1radbut8 = GUICtrlCreateButton ("Set", 330, 219, 40, 17)
Global $tab1radinfo8 = GUICtrlCreateButton ("Info", 390, 219, 40, 17)
Global $tab1radopt9 = GUICtrlCreateRadio ("MouseClickDelay", 27, 236, 150, 20)
Global $tab1radinp9 = GUICtrlCreateInput ("10", 200, 236, 100, 17)
Global $tab1radbut9 = GUICtrlCreateButton ("Set", 330, 236, 40, 17)
Global $tab1radinfo9 = GUICtrlCreateButton ("Info", 390, 236, 40, 17)
Global $tab1radopt10 = GUICtrlCreateRadio ("MouseClickDownDelay", 27, 253, 150, 20)
Global $tab1radinp10 = GUICtrlCreateInput ("10", 200, 253, 100, 17)
Global $tab1radbut10 = GUICtrlCreateButton ("Set", 330, 253, 40, 17)
Global $tab1radinfo10 = GUICtrlCreateButton ("Info", 390, 253, 40, 17)
Global $tab1radopt11 = GUICtrlCreateRadio ("MouseClickDragDelay", 27, 270, 150, 20)
Global $tab1radinp11 = GUICtrlCreateInput ("250", 200, 270, 100, 17)
Global $tab1radbut11 = GUICtrlCreateButton ("Set", 330, 270, 40, 17)
Global $tab1radinfo11 = GUICtrlCreateButton ("Info", 390, 270, 40, 17)
Global $tab1radopt12 = GUICtrlCreateRadio ("MouseCoordMode", 27, 287, 150, 20)
Global $tab1radinp12 = GUICtrlCreateInput ("1", 200, 287, 100, 17)
Global $tab1radbut12 = GUICtrlCreateButton ("Set", 330, 287, 40, 17)
Global $tab1radinfo12 = GUICtrlCreateButton ("Info", 390, 287, 40, 17)
Global $tab1radopt13 = GUICtrlCreateRadio ("MustDeclareVars", 27, 304, 150, 20)
Global $tab1radinp13 = GUICtrlCreateInput ("0", 200, 304, 100, 17)
Global $tab1radbut13 = GUICtrlCreateButton ("Set", 330, 304, 40, 17)
Global $tab1radinfo13 = GUICtrlCreateButton ("Info", 390, 304, 40, 17)
Global $tab1radopt14 = GUICtrlCreateRadio ("OnExitFunc", 27, 321, 150, 20)
Global $tab1radinp14 = GUICtrlCreateInput ("OnAutoItExit", 200, 321, 100, 17)
Global $tab1radbut14 = GUICtrlCreateButton ("Set", 330, 321, 40, 17)
Global $tab1radinfo14 = GUICtrlCreateButton ("Info", 390, 321, 40, 17)
Global $tab1radopt15 = GUICtrlCreateRadio ("PixelCoordMode", 27, 338, 150, 20)
Global $tab1radinp15 = GUICtrlCreateInput ("1", 200, 338, 100, 17)
Global $tab1radbut15 = GUICtrlCreateButton ("Set", 330, 338, 40, 17)
Global $tab1radinfo15 = GUICtrlCreateButton ("Info", 390, 338, 40, 17)
Global $tab1radopt16 = GUICtrlCreateRadio ("RunErrorsFatal", 27, 355, 150, 20)
Global $tab1radinp16 = GUICtrlCreateInput ("1", 200, 355, 100, 17)
Global $tab1radbut16 = GUICtrlCreateButton ("Set", 330, 355, 40, 17)
Global $tab1radinfo16 = GUICtrlCreateButton ("Info", 390, 355, 40, 17)
Global $tab1radopt17 = GUICtrlCreateRadio ("SendAttachMode", 27, 372, 150, 20)
Global $tab1radinp17 = GUICtrlCreateInput ("0", 200, 372, 100, 17)
Global $tab1radbut17 = GUICtrlCreateButton ("Set", 330, 372, 40, 17)
Global $tab1radinfo17 = GUICtrlCreateButton ("Info", 390, 372, 40, 17)
Global $tab1radopt18 = GUICtrlCreateRadio ("SendCapslockMode", 27, 389, 150, 20)
Global $tab1radinp18 = GUICtrlCreateInput ("1", 200, 389, 100, 17)
Global $tab1radbut18 = GUICtrlCreateButton ("Set", 330, 389, 40, 17)
Global $tab1radinfo18 = GUICtrlCreateButton ("Info", 390, 389, 40, 17)
Global $tab1radopt19 = GUICtrlCreateRadio ("SendKeyDelay", 27, 406, 150, 20)
Global $tab1radinp19 = GUICtrlCreateInput ("5", 200, 406, 100, 17)
Global $tab1radbut19 = GUICtrlCreateButton ("Set", 330, 406, 40, 17)
Global $tab1radinfo19 = GUICtrlCreateButton ("Info", 390, 406, 40, 17)
Global $tab1radopt20 = GUICtrlCreateRadio ("SendKeyDownDelay", 27, 423, 150, 20)
Global $tab1radinp20 = GUICtrlCreateInput ("1", 200, 423, 100, 17)
Global $tab1radbut20 = GUICtrlCreateButton ("Set", 330, 423, 40, 17)
Global $tab1radinfo20 = GUICtrlCreateButton ("Info", 390, 423, 40, 17)
Global $tab1radopt21 = GUICtrlCreateRadio ("TrayIconDebug", 27, 440, 150, 20)
Global $tab1radinp21 = GUICtrlCreateInput ("0", 200, 440, 100, 17)
Global $tab1radbut21 = GUICtrlCreateButton ("Set", 330, 440, 40, 17)
Global $tab1radinfo21 = GUICtrlCreateButton ("Info", 390, 440, 40, 17)
Global $tab1radopt22 = GUICtrlCreateRadio ("TrayIconHide", 27, 457, 150, 20)
Global $tab1radinp22 = GUICtrlCreateInput ("0", 200, 457, 100, 17)
Global $tab1radbut22 = GUICtrlCreateButton ("Set", 330, 457, 40, 17)
Global $tab1radinfo22 = GUICtrlCreateButton ("Info", 390, 457, 40, 17)
Global $tab1radopt23 = GUICtrlCreateRadio ("WinDetectHiddenText", 27, 474, 150, 20)
Global $tab1radinp23 = GUICtrlCreateInput ("0", 200, 474, 100, 17)
Global $tab1radbut23 = GUICtrlCreateButton ("Set", 330, 474, 40, 17)
Global $tab1radinfo23 = GUICtrlCreateButton ("Info", 390, 474, 40, 17)
Global $tab1radopt24 = GUICtrlCreateRadio ("WinSearchChildren", 27, 491, 150, 20)
Global $tab1radinp24 = GUICtrlCreateInput ("0", 200, 491, 100, 17)
Global $tab1radbut24 = GUICtrlCreateButton ("Set", 330, 491, 40, 17)
Global $tab1radinfo24 = GUICtrlCreateButton ("Info", 390, 491, 40, 17)
Global $tab1radopt25 = GUICtrlCreateRadio ("WinTextMatchMode", 27, 508, 150, 20)
Global $tab1radinp25 = GUICtrlCreateInput ("1", 200, 508, 100, 17)
Global $tab1radbut25 = GUICtrlCreateButton ("Set", 330, 508, 40, 17)
Global $tab1radinfo25 = GUICtrlCreateButton ("Info", 390, 508, 40, 17)
Global $tab1radopt26 = GUICtrlCreateRadio ("WinTitleMatchMode", 27, 525, 150, 20)
Global $tab1radinp26 = GUICtrlCreateInput ("1", 200, 525, 100, 17)
Global $tab1radbut26 = GUICtrlCreateButton ("Set", 330, 525, 40, 17)
Global $tab1radinfo26 = GUICtrlCreateButton ("Info", 390, 525, 40, 17)
Global $tab1radopt27 = GUICtrlCreateRadio ("WinWaitDelay", 27, 542, 150, 20)
Global $tab1radinp27 = GUICtrlCreateInput ("250", 200, 542, 100, 17)
Global $tab1radbut27 = GUICtrlCreateButton ("Set", 330, 542, 40, 17)
Global $tab1radinfo27 = GUICtrlCreateButton ("Info", 390, 542, 40, 17)
GUICtrlCreateGroup ("", -99, -99, 1, 1) ;close group
;******** Tab Two ****************************************************************
Global $tab3 = GUICtrlCreateTabitem ("Globals")
;******** Tab Three **************************************************************
Global $tab4 = GUICtrlCreateTabitem ("Functions")

GUICtrlCreateTabitem ("")   ; end tabitem definition
GuiSetState ()

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

Func _filewrite()
   Global $fw1 = GuiCtrlRead ($tab0fileinp)
   Dim $fw2 = GuiCtrlRead ($tab0infoinp)
   Dim $fw3 = GuiCtrlRead ($tab0infoinp1)
   Dim $fw4 = GuiCtrlRead ($tab0infoinp2)
   Dim $fw5 = GuiCtrlRead ($tab0infoinp3)
   Dim $fw6 = GuiCtrlRead ($tab0infoinp4)
   Dim $fw7 = GuiCtrlRead ($tab0infoinp5)
   If $fw1 = "~filename.au3" Or $fw1 = "" Then
      MsgBox(0, "Error: Missing File Information", "You need to specify a filename before submitting.")
   Else
      $opts = 1
      MsgBox(0, $fw1 & " created", "Created initial file format for " & $fw1 &". Continue working with your script.")
      FileOpen($fw1, 2)
      FileWrite($fw1, "; ----------------------------------------------------------------------------" & @CRLF)
      FileWrite($fw1, ";" & @CRLF)
      FileWrite($fw1, "; AutoIt Version: " & $fw2 & @CRLF)
      FileWrite($fw1, "; Language:     " & $fw3 & @CRLF)
      FileWrite($fw1, "; Platform:     " & $fw4 & @CRLF)
      FileWrite($fw1, "; Author:         " & $fw5 & " <" & $fw6 & ">" & @CRLF)
      FileWrite($fw1, ";" & @CRLF)
      FileWrite($fw1, "; Script Function:" & @CRLF)
      FileWrite($fw1, ";    " & $fw7 & @CRLF)
      FileWrite($fw1, ";" & @CRLF)
      FileWrite($fw1, "; ----------------------------------------------------------------------------" & @CRLF)
      FileWrite($fw1, "" & @CRLF)
      FileWrite($fw1, "" & @CRLF)
      FileWrite($fw1, "; ----------------------------------------------------------------------------" & @CRLF)
      FileWrite($fw1, "; Set up defaults listed below.." & @CRLF)
      FileWrite($fw1, "; ----------------------------------------------------------------------------" & @CRLF)
      FileWrite($fw1, "" & @CRLF)
   EndIf
EndFunc  ;==>_filewrite

Func _options()
   Dim $opt1 = "AutoItSetOption(""MustDeclareVars"", 1)"
   FileWrite($fw1, $opt1 & @CRLF)
EndFunc  ;==>_options
Edited by Joel

[font="Optima"]"Those who heed life with speculation and contemplation, are the ones stuck home with constipation." - Joel[/font]

Share this post


Link to post
Share on other sites
Lazycat

You thinking in right direction, arrays can shrink and simlify your code a lot. Not sure about first tab, but big massive of controls at second just asking for optimization... You, for example, can use two-dimentional array for keep their ID's, so they are will be linked together in row. Something like this (you also have to add default values to edits...):

$asLabels = StringSplit("CaretCoordMode,ColorMode,.....................", ",") 
Dim $hControl[27][4]
For $i = 0 To 26
    $hControl[$i][0] = GUICtrlCreateRadio ($asLabels[$i+1], 27, 100+$i*20, 150, 20)
    $hControl[$i][1] = GUICtrlCreateInput ("1", 200, 100+$i*20, 100, 17)
    $hControl[$i][2] = GUICtrlCreateButton ("Set", 330, 100+$i*20, 40, 17)
    $hControl[$i][3] = GUICtrlCreateButton ("Info", 390, 100+$i*20, 40, 17)
Next

Share this post


Link to post
Share on other sites
Joel

What a big difference that makes. You gave a very solid example Lazycat and I caught on to it very quickly. I changed a few things around and adjusted the 20, 17 numbers to the correct values, but here's what it looks like thus far.

It tests out fine. I'll be coming back to this thread periodically to see if I can use more arrays to clean up some code. Many many thanks!

#include <GUIConstants.au3>

GUICreate ("Opti-Bot", 700, 600)

GUISetFont (9, 330)

Global $textcol = "0x253E5D"
Global $opts = 0; Options Default
Global $tab = GUICtrlCreateTab (0, 0, 700, 600)
;******** Tab Zero **************************************************************
Global $tab0 = GUICtrlCreateTabitem ("Start")
GUICtrlSetState (-1, $GUI_SHOW)
GUICtrlCreateGroup ("Create a new script", 10, 50, 430, 160)
GUICtrlCreateLabel ("If this is your first time using this utility, read the help file by pressing (F1) at", 20, 70, 410, 20)
GUICtrlCreateLabel ("anytime. Making a new script can be daunting, but with patience and ", 20, 85, 410, 20)
GUICtrlCreateLabel ("guidance you will be making new scripts with relative ease. In order to start", 20, 100, 410, 20)
GUICtrlCreateLabel ("creating a script, we need to take care of some basics first.", 20, 115, 410, 20)
GUICtrlCreateLabel ("With all scripts, you should input basic information that relates version,", 20, 145, 410, 20)
GUICtrlCreateLabel ("language, platform, author, and functional descriptions to tell the user", 20, 160, 410, 20)
GUICtrlCreateLabel ("what the script is being used for. So, let's do that now.", 20, 175, 410, 20)
;End Intro
GUICtrlCreateLabel ("AutoIt Version:", 120, 250, 100, 20)
Global $tab0infoinp = GUICtrlCreateInput ("Version Number", 260, 250, 250, 20)
GUICtrlCreateLabel ("Language:", 120, 270, 100, 20)
Global $tab0infoinp1 = GUICtrlCreateInput ("English", 260, 270, 250, 20)
GUICtrlCreateLabel ("Platform:", 120, 290, 100, 20)
Global $tab0infoinp2 = GUICtrlCreateInput ("Windows 2000", 260, 290, 250, 20)
GUICtrlCreateLabel ("Author:", 120, 310, 100, 20)
Global $tab0infoinp3 = GUICtrlCreateInput ("Your Name", 260, 310, 250, 20)
GUICtrlCreateLabel ("Email Address:", 120, 330, 100, 20)
Global $tab0infoinp4 = GUICtrlCreateInput ("email@address.com", 260, 330, 250, 20)
GUICtrlCreateLabel ("Script Function:", 120, 350, 100, 20)
Global $tab0infoinp5 = GUICtrlCreateInput ("Place script description here", 260, 350, 250, 70)
Global $tab0fileinp = GUICtrlCreateInput ("~filename.au3", 260, 430, 100, 20)
Global $tab0infosub = GUICtrlCreateButton ("Submit", 368, 430, 70, 20)
;******* Tab One *****************************************************************
Global $tab1 = GUICtrlCreateTabitem ("Options")
GUICtrlCreateGroup ("Autoit Default Options", 10, 50, 430, 520)
GUICtrlCreateLabel ("Include", 15, 80, 150, 15)
$tab1Labels = StringSplit("CaretCoordMode,ColorMode,ExpandEnvStrings,ExpandVarStrings,FtpBinaryMode,GUICoordMode,GUIOnEvent


Mode,GUIResizeMode,MouseClickDelay,MouseClickDownDelay,MouseClickDragDelay,MouseCoordMode,MustDeclar


eVars,OnExitFunc,PixelCoordMode,RunErrorsFatal,SendAttachMode,SendCapslockMode,SendKeyDelay,SendKeyD


ownDelay,TrayIconDebug,TrayIconHide,WinDetectHiddenText,WinSearchChildren,WinTextMatchMode,WinTitleM


atchMode,WinWaitDelay", ",") 
$tab1Values = StringSplit("1,0,0,0,1,1,0,0,10,10,250,1,0,OnAutoItExit,1,1,0,1,5,1,0,0,0,0,1,1,250",",")
Dim $t1Control[27][4]
For $i = 0 To 26
    $t1Control[$i][0] = GUICtrlCreateRadio ($tab1Labels[$i+1], 27, 100+$i*17, 150, 20)
    $t1Control[$i][1] = GUICtrlCreateInput ($tab1Values[$i+1], 200, 100+$i*17, 100, 20)
    $t1Control[$i][2] = GUICtrlCreateButton ("Set", 330, 100+$i*17, 40, 20)
    $t1Control[$i][3] = GUICtrlCreateButton ("Info", 390, 100+$i*17, 40, 20)
Next
GUICtrlCreateGroup ("", -99, -99, 1, 1) ;close group
;******** Tab Two ****************************************************************
Global $tab3 = GUICtrlCreateTabitem ("Globals")
;******** Tab Three **************************************************************
Global $tab4 = GUICtrlCreateTabitem ("Functions")

GUICtrlCreateTabitem ("")   ; end tabitem definition
GuiSetState ()

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

Func _filewrite()
   Global $fw1 = GuiCtrlRead ($tab0fileinp)
   Dim $fw2 = GuiCtrlRead ($tab0infoinp)
   Dim $fw3 = GuiCtrlRead ($tab0infoinp1)
   Dim $fw4 = GuiCtrlRead ($tab0infoinp2)
   Dim $fw5 = GuiCtrlRead ($tab0infoinp3)
   Dim $fw6 = GuiCtrlRead ($tab0infoinp4)
   Dim $fw7 = GuiCtrlRead ($tab0infoinp5)
   If $fw1 = "~filename.au3" Or $fw1 = "" Then
      MsgBox(0, "Error: Missing File Information", "You need to specify a filename before submitting.")
   Else
      $opts = 1
      MsgBox(0, $fw1 & " created", "Created initial file format for " & $fw1 &". Continue working with your script.")
      FileOpen($fw1, 2)
      FileWrite($fw1, "; ----------------------------------------------------------------------------" & @CRLF)
      FileWrite($fw1, ";" & @CRLF)
      FileWrite($fw1, "; AutoIt Version: " & $fw2 & @CRLF)
      FileWrite($fw1, "; Language:     " & $fw3 & @CRLF)
      FileWrite($fw1, "; Platform:     " & $fw4 & @CRLF)
      FileWrite($fw1, "; Author:         " & $fw5 & " <" & $fw6 & ">" & @CRLF)
      FileWrite($fw1, ";" & @CRLF)
      FileWrite($fw1, "; Script Function:" & @CRLF)
      FileWrite($fw1, ";    " & $fw7 & @CRLF)
      FileWrite($fw1, ";" & @CRLF)
      FileWrite($fw1, "; ----------------------------------------------------------------------------" & @CRLF)
      FileWrite($fw1, "" & @CRLF)
      FileWrite($fw1, "" & @CRLF)
      FileWrite($fw1, "; ----------------------------------------------------------------------------" & @CRLF)
      FileWrite($fw1, "; Set up defaults listed below.." & @CRLF)
      FileWrite($fw1, "; ----------------------------------------------------------------------------" & @CRLF)
      FileWrite($fw1, "" & @CRLF)
   EndIf
EndFunc  ;==>_filewrite

Func _options()
   Dim $opt1 = "AutoItSetOption(""MustDeclareVars"", 1)"
   FileWrite($fw1, $opt1 & @CRLF)
EndFunc  ;==>_options

[font="Optima"]"Those who heed life with speculation and contemplation, are the ones stuck home with constipation." - Joel[/font]

Share this post


Link to post
Share on other sites
Joel

Okay, having problems matching $msg in the array I setup. Here's a new array that I created and what the message is showing:

If $msg >= $t1Control[0][2] And $msg <= $t1Control[26][2] Then _options()

^^ The code above is the msg event in the while loop. If the "Set" button is pushed then it trigged an event because it falls within this range. Afterwards, it should go to the function _options() and then match the event that was pressed and perform a file write. Here's that code.

Func _options()
   If $opts = 1 Then
      Dim $opt1Control[27]
      For $i = 0 To 26
         $opt1Control[$i] = GUICtrlRead($t1Control[$i][1])
         $i = $i +1
      Next
      $opts = 2
      FileWrite($fw1, $opt1Control[0] & @CRLF)
      FileWrite($fw1, $opt1Control[1] & @CRLF)
      FileWrite($fw1, $opt1Control[2] & @CRLF)
   Else
      MsgBox(0, "Options Error", "You must first being at Start and create your initial script file.")
   EndIf
EndFunc  ;==>_options

^^ As you can see, what I've basically done is created an array to make sure it can read all the values. In this case it can according to the test. But, what I want to do is just write one value only. For example:

FileWrite($fw1, $opt1Control[$i] & @CRLF)

^^ Where $i is the matched array control message. I don't want it to cycle through all of them because in the application, if a person wants to set an AutoitOption they should be able to push any of the set buttons after typing in a value and set the option. Also, the information in the GUICtrlInputs are the defaults anyways so there's no need for them to be written in the file. They should only be written if someone changes them and forceably wants to use a different value.

Again, I appreciate any help on this. I'm getting a hard crunch tutorial in arrays and it's a little like torture only for some strange reason, it's feeling good.


[font="Optima"]"Those who heed life with speculation and contemplation, are the ones stuck home with constipation." - Joel[/font]

Share this post


Link to post
Share on other sites
Joel

I still need assistance with the post above this one, where once a msg is found via the array, it acts upon that msg. I'm guessing this is going to require some type of case scenario. But, again, I'm not very good with arrays and am learning the process. I have a good understanding of how to create basic arrays now but do not know how to setup the case identifiers.

Thanks,


[font="Optima"]"Those who heed life with speculation and contemplation, are the ones stuck home with constipation." - Joel[/font]

Share this post


Link to post
Share on other sites
Joel

Here's what I have so far:

While 1
   $msg = GUIGetMsg()
   Select
      Case $msg >= $t1Control[0][2] And $msg <= $t1Control[26][2]
         global $selectedtab1inp = $msg
         _options()
     Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
     Case $msg = $tab0infosub 
         _filewrite()
   EndSelect
WEnd

But this only pulls up the ID code for the Set button. I need to affiliate the "set" button with the input box. I'm getting there but may still need some help.


[font="Optima"]"Those who heed life with speculation and contemplation, are the ones stuck home with constipation." - Joel[/font]

Share this post


Link to post
Share on other sites
Joel

Okay, I think I'm on the right track but I know I'm doing something incorrect here. Here is the snippet of code I need help with:

For $i = 0 To 26
   $t1Control[$i][0] = GUICtrlCreateRadio($tab1Labels[$i + 1], 27, 100 + $i * 17, 150, 20)
   $t1Control[$i][1] = GUICtrlCreateInput($tab1Values[$i + 1], 200, 100 + $i * 17, 100, 20)
   $t1Control[$i][2] = GUICtrlCreateButton("Set", 330, 100 + $i * 17, 40, 20)
   $t1Control[$i][3] = GUICtrlCreateButton("Info", 390, 100 + $i * 17, 40, 20)
Next
;
; This is the code that defines the initial controls.  Look at $t1Control[$i][1]
;
;
While 1
   $msg = GUIGetMsg()
   Select
      Case $msg >= $t1Control[0][2] And $msg <= $t1Control[26][2]
         global $selectedtab1inp = $msg
         _options()
     Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
     Case $msg = $tab0infosub 
         _filewrite()
   EndSelect
WEnd
;
; Again, reading the msg and defining the case scenarios.  The problem has to stem from how I define the global $selectedtab1inp.
;
;
Func _options()
   $t1Set = GUICtrlRead($t1Control[$selectedtab1inp][2])
   If $opts = 1 Then
      FileWrite($fw1, $t1Set & @CRLF)
   Else
      MsgBox(0, "Options Error", "You must first begin at Start and create your initial script file.")
   EndIf
EndFunc  ;==>_options
;
; As you can see, I want to read the input control based on the set button pushed. As each of the set buttons are right beside the input controls, it should be in the same numerical order.

Read the notes underneath each snippet.


[font="Optima"]"Those who heed life with speculation and contemplation, are the ones stuck home with constipation." - Joel[/font]

Share this post


Link to post
Share on other sites
Joel

I want to give more information to those that are trying to help me out.

$t1Control[0][0] to $t1Control[26][0] = The radio labels

$t1Control[$i][1] to $t1Control[26][1] = The input fields for the values.

$t1Control[$i][2] to $t1Control[26][2] = The set buttons to the right of input fields.

$t1Control[$i][3] to $t1Control[26][3] = The info buttons to the right of set buttons.

What should occur is that a user needs to check a radio button, set the input value and then hit the set button for it to be written to the .au3 file. If they don't have the radio checked when hitting the set button, it should message an error.

Also, the info button is going to write a label to the right of the gui tab that shows the information about the control. Again, if they don't have the correct radio button checked, it will error out.

What I'm having problems with is that I don't know how to associate the Set button with the correct input field it is next to, based off an array msg result.

In otherwords, I click the Set button to the right of $t1Control[3][1]. The msg is noticed because it's stored in the array. How do I associate the msg stored in the array with the input line to the left of it? I know I need to use GUICtrlRead but I'm not sure how to use it with an array.

Thanks.


[font="Optima"]"Those who heed life with speculation and contemplation, are the ones stuck home with constipation." - Joel[/font]

Share this post


Link to post
Share on other sites
Lazycat

This is an advantage of using arrays - all controls are linked by array first index. So, when user click button (for example with index 1) you have check other controls in row: $t1Control[1][0] and$t1Control[$i][1]. If thay are not satisfy your condition - raise error message. For example way to do that:

For $i = 0 to 26
    If $msg = $t1Control[$i][3] Then
        If not BitAnd(GUICtrlGetState($t1Control[1][0]), 1) and_
        not (GUICtrlRead($t1Control[$i][1])) = "" Then 
            MsgBox(0, "Error", "Error")
        Else
           ; <Do something usefull >
        Endif
    Exitloop
    Endif
Next

Share this post


Link to post
Share on other sites
Joel

Okay, I follow this logic. So, this allows me to put in error handling for whether or not they have checked a condition (like the radio) etc.

However, how do I retrieve the GuiCtrlRead for the input based on the array? Here's what I tried to do and what happened.

While 1
   $msg = GUIGetMsg()
   For $i = 0 to 26
    If $msg = $t1Control[$i][2] Then
        If not BitAnd(GUICtrlGetState($t1Control[1][0]), 1) and not (GUICtrlRead($t1Control[$i][1])) = "" Then 
            MsgBox(0, "Error", "Error")
        Else
           Global $tab1writeval = GUICtrlRead($t1Control[$i][1])
           _options()
        Endif
    Exitloop
    Endif
Next
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
   If $msg = $tab0infosub Then _filewrite()
WEnd

Here's the while loop. I used $t1Control[$i][2] because that's the "set" button.

Func _options()
   If $opts = 1 Then
      FileWrite($fw1, $tab1writeval & @CRLF)
      global $globals = 1
   Else
      MsgBox(0, "Options Error", "You must first begin at Start and create your initial script file.")
   EndIf
EndFunc  ;==>_options

Here's the function it calls.

When I use the application, I get an error on anything that is not a "0" by default in the input line. So if the option value is set to 10, 250, etc. it errors out. Also, I can click "set" on anything that isn't checked on the radio and it allows me to do so.

Any ideas, and thanks for the input.


[font="Optima"]"Those who heed life with speculation and contemplation, are the ones stuck home with constipation." - Joel[/font]

Share this post


Link to post
Share on other sites
Joel

bump.


[font="Optima"]"Those who heed life with speculation and contemplation, are the ones stuck home with constipation." - Joel[/font]

Share this post


Link to post
Share on other sites
Lazycat

I did couple mistakes in last example (yeah, it's bad to do something late evening...). Try this fixed one.

While 1
   $msg = GUIGetMsg()
   For $i = 0 to 26
    If $msg = $t1Control[$i][2] Then
        If not BitAnd(GUICtrlRead($t1Control[$i][0]), $GUI_CHECKED) Then
            MsgBox(0, "Error", "Radiobutton not selected")
        Else
           If not (GUICtrlRead($t1Control[$i][1]) = "") Then
               Global $tab1writeval = GUICtrlRead($t1Control[$i][1])
               _options()
           Else
               MsgBox(0, "Error", "Field is empty")
           Endif
        Endif
    Exitloop
    Endif
Next
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
   If $msg = $tab0infosub Then _filewrite()
WEnd

Share this post


Link to post
Share on other sites
Joel

Perfect, Lazycat and you have taught me many things over the past few days. Here's the working script with the first two tabs complete. Play with it and you'll see where it's going.

Right now, you can create any .au3 file and set the Autoitoptions.

#include <GUIConstants.au3>

GUICreate("Opti-Bot", 700, 600)

GUISetFont(9, 330)

Global $textcol = "0x253E5D"
Global $opts = 0; Options Default
Global $tab = GUICtrlCreateTab(0, 0, 700, 600)
;******** Tab Zero **************************************************************
Global $tab0 = GUICtrlCreateTabItem("Start")
GUICtrlSetState(-1, $GUI_SHOW)
GUICtrlCreateGroup("Create a new script", 10, 50, 430, 160)
GUICtrlCreateLabel("If this is your first time using this utility, read the help file by pressing (F1) at", 20, 70, 410, 20)
GUICtrlCreateLabel("anytime. Making a new script can be daunting, but with patience and ", 20, 85, 410, 20)
GUICtrlCreateLabel("guidance you will be making new scripts with relative ease. In order to start", 20, 100, 410, 20)
GUICtrlCreateLabel("creating a script, we need to take care of some basics first.", 20, 115, 410, 20)
GUICtrlCreateLabel("With all scripts, you should input basic information that relates version,", 20, 145, 410, 20)
GUICtrlCreateLabel("language, platform, author, and functional descriptions to tell the user", 20, 160, 410, 20)
GUICtrlCreateLabel("what the script is being used for. So, let's do that now.", 20, 175, 410, 20)
;End Intro
GUICtrlCreateLabel("AutoIt Version:", 120, 250, 100, 20)
Global $tab0infoinp = GUICtrlCreateInput("Version Number", 260, 250, 250, 20)
GUICtrlCreateLabel("Language:", 120, 270, 100, 20)
Global $tab0infoinp1 = GUICtrlCreateInput("English", 260, 270, 250, 20)
GUICtrlCreateLabel("Platform:", 120, 290, 100, 20)
Global $tab0infoinp2 = GUICtrlCreateInput("Windows 2000", 260, 290, 250, 20)
GUICtrlCreateLabel("Author:", 120, 310, 100, 20)
Global $tab0infoinp3 = GUICtrlCreateInput("Your Name", 260, 310, 250, 20)
GUICtrlCreateLabel("Email Address:", 120, 330, 100, 20)
Global $tab0infoinp4 = GUICtrlCreateInput("email@address.com", 260, 330, 250, 20)
GUICtrlCreateLabel("Script Function:", 120, 350, 100, 20)
Global $tab0infoinp5 = GUICtrlCreateInput("Place script description here", 260, 350, 250, 70)
Global $tab0fileinp = GUICtrlCreateInput("~filename.au3", 260, 430, 100, 20)
Global $tab0infosub = GUICtrlCreateButton("Submit", 368, 430, 70, 20)
;******* Tab One *****************************************************************
Global $tab1 = GUICtrlCreateTabItem("Options")
GUICtrlCreateGroup("Autoit Default Options", 10, 50, 430, 520)
GUICtrlCreateLabel("Include", 15, 80, 150, 15)
Global $tab1Labels = StringSplit("CaretCoordMode,ColorMode,ExpandEnvStrings,ExpandVarStrings,FtpBinaryMode,GUICoordMode,GUIOnEvent


Mode,GUIResizeMode,MouseClickDelay,MouseClickDownDelay,MouseClickDragDelay,MouseCoordMode,MustDeclar


eVars,OnExitFunc,PixelCoordMode,RunErrorsFatal,SendAttachMode,SendCapslockMode,SendKeyDelay,SendKeyD


ownDelay,TrayIconDebug,TrayIconHide,WinDetectHiddenText,WinSearchChildren,WinTextMatchMode,WinTitleM


atchMode,WinWaitDelay", ",")
Global $tab1Values = StringSplit("1,0,0,0,1,1,0,0,10,10,250,1,0,OnAutoItExit,1,1,0,1,5,1,0,0,0,0,1,1,250", ",")
Global $t1Control[27][4]
For $i = 0 To 26
   $t1Control[$i][0] = GUICtrlCreateRadio($tab1Labels[$i + 1], 27, 100 + $i * 17, 150, 20)
   $t1Control[$i][1] = GUICtrlCreateInput($tab1Values[$i + 1], 200, 100 + $i * 17, 100, 20)
   $t1Control[$i][2] = GUICtrlCreateButton("Set", 330, 100 + $i * 17, 40, 20)
   $t1Control[$i][3] = GUICtrlCreateButton("Info", 390, 100 + $i * 17, 40, 20)
Next
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
;******** Tab Two ****************************************************************
Global $tab3 = GUICtrlCreateTabItem("Globals")
;******** Tab Three **************************************************************
Global $tab4 = GUICtrlCreateTabItem("Functions")

GUICtrlCreateTabItem("")   ; end tabitem definition
GUISetState()
Global $valEvent = 0
; Run the GUI until the dialog is closed
 
While 1
   $msg = GUIGetMsg()
   For $i = 0 to 26
    If $msg = $t1Control[$i][2] Then
        If not BitAnd(GUICtrlRead($t1Control[$i][0]), $GUI_CHECKED) Then
            MsgBox(0, "Error", "Radiobutton not selected")
        Else
           If not (GUICtrlRead($t1Control[$i][1]) = "") Then
               Global $tab1writeval = GUICtrlRead($t1Control[$i][1])
               Global $tab1labelval = $tab1Labels[$i + 1]
               _options()
           Else
               MsgBox(0, "Error", "Field is empty")
           Endif
        Endif
    Exitloop
    Endif
Next
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
   If $msg = $tab0infosub Then _filewrite()
WEnd

Func _filewrite()
   Global $fw1 = GUICtrlRead($tab0fileinp)
   Dim $fw2 = GUICtrlRead($tab0infoinp)
   Dim $fw3 = GUICtrlRead($tab0infoinp1)
   Dim $fw4 = GUICtrlRead($tab0infoinp2)
   Dim $fw5 = GUICtrlRead($tab0infoinp3)
   Dim $fw6 = GUICtrlRead($tab0infoinp4)
   Dim $fw7 = GUICtrlRead($tab0infoinp5)
   If $fw1 = "~filename.au3" Or $fw1 = "" Then
      MsgBox(0, "Error: Missing File Information", "You need to specify a filename before submitting.")
   Else
      $opts = 1
      MsgBox(0, $fw1 & " created", "Created initial file format for " & $fw1 & ". Continue working with your script.")
      FileOpen($fw1, 2)
      FileWrite($fw1, "; ----------------------------------------------------------------------------" & @CRLF)
      FileWrite($fw1, ";" & @CRLF)
      FileWrite($fw1, "; AutoIt Version: " & $fw2 & @CRLF)
      FileWrite($fw1, "; Language:     " & $fw3 & @CRLF)
      FileWrite($fw1, "; Platform:     " & $fw4 & @CRLF)
      FileWrite($fw1, "; Author:         " & $fw5 & " <" & $fw6 & ">" & @CRLF)
      FileWrite($fw1, ";" & @CRLF)
      FileWrite($fw1, "; Script Function:" & @CRLF)
      FileWrite($fw1, ";    " & $fw7 & @CRLF)
      FileWrite($fw1, ";" & @CRLF)
      FileWrite($fw1, "; ----------------------------------------------------------------------------" & @CRLF)
      FileWrite($fw1, "" & @CRLF)
      FileWrite($fw1, "" & @CRLF)
      FileWrite($fw1, "; ----------------------------------------------------------------------------" & @CRLF)
      FileWrite($fw1, "; Set up defaults listed below.." & @CRLF)
      FileWrite($fw1, "; ----------------------------------------------------------------------------" & @CRLF)
      FileWrite($fw1, "" & @CRLF)
   EndIf
EndFunc  ;==>_filewrite

Func _options()
   If $opts = 1 Then
      FileWrite($fw1, "AutoItSetOption(""" & $tab1labelval & """, " & $tab1writeval & ")" & @CRLF)
      MsgBox(0, "Option Set", $tab1labelval & " set to " & $tab1writeval & " value.")
      global $globals = 1
   Else
      MsgBox(0, "Options Error", "You must first begin at Start and create your initial script file.")
   EndIf
EndFunc  ;==>_options
Edited by Joel

[font="Optima"]"Those who heed life with speculation and contemplation, are the ones stuck home with constipation." - Joel[/font]

Share this post


Link to post
Share on other sites
Joel

Edited the code so that you now see a msg box with the set parameter when clicking set. I still need to add the "info" so that won't work yet.

Also, once you create the initial file and set some autoitoptions, go look at the new .au3 file you created and you will see how it looks.

Next up..

Working on the info section for options and then globals. Functions will be a tricky thing to work with but I have a good idea of how to get it started.

Thanks again for all your help Lazycat. I'll probably need some more advice soon.


[font="Optima"]"Those who heed life with speculation and contemplation, are the ones stuck home with constipation." - Joel[/font]

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.