Jump to content

Trying to learn Arrays--anyone a teacher?


russell
 Share

Recommended Posts

I started with one of my old piece of a code

Global $reportfile = "C:\Windows\Temp\"
Global $box[7]
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 492, 395, -903, 134)
$field1gui = GUICtrlCreateCombo("", 16, 32, 81, 25)
GUICtrlSetData(-1, "yes|no")
$field2gui = GUICtrlCreateCombo("", 16, 56, 81, 25)
GUICtrlSetData(-1, "yes|no")
$field3gui = GUICtrlCreateCombo("", 16, 80, 81, 25)
GUICtrlSetData(-1, "yes|no")
$field4gui = GUICtrlCreateCombo("", 16, 104, 81, 25)
GUICtrlSetData(-1, "yes|no")
$field5gui = GUICtrlCreateCombo("", 16, 128, 81, 25)
GUICtrlSetData(-1, "yes|no")
$field6gui = GUICtrlCreateCombo("", 16, 152, 81, 25)
GUICtrlSetData(-1, "yes|no")
$field7gui = GUICtrlCreateCombo("", 16, 176, 81, 25)
GUICtrlSetData(-1, "yes|no")
$field8gui = GUICtrlCreateCombo("", 16, 200, 81, 25)
GUICtrlSetData(-1, "yes|no")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
EndSwitch
Sleep (10000)
ExitLoop
WEnd
$box1=(GUICtrlRead($field1gui) )
$box2=(GUICtrlRead($field2gui) )
$box3=(GUICtrlRead($field3gui) )
$box4=(GUICtrlRead($field4gui) )
$box5=(GUICtrlRead($field5gui) )
$box6=(GUICtrlRead($field6gui) )
$box7=(GUICtrlRead($field7gui) )
$box8=(GUICtrlRead($field8gui) )
If $box1 = "yes" Then
FileWrite($reportfile & "acc1.txt", "account1")
EndIf

If $box2 = "yes" Then
FileWrite($reportfile & "acc2.txt", "account2")
EndIf

If $box3 = "yes" Then
FileWrite($reportfile & "acc3.txt", "account3")
EndIf

If $box4 = "yes" Then
FileWrite($reportfile & "acc4.txt", "account4")
EndIf

If $box5 = "yes" Then
FileWrite($reportfile & "acc5.txt", "account5")
EndIf

If $box6 = "yes" Then
FileWrite($reportfile & "acc6.txt", "account6")
EndIf

If $box7 = "yes" Then
FileWrite($reportfile & "acc7.txt", "account7" )
EndIf

If $box8= "yes" Then
FileWrite($reportfile & "acc8.txt", "account8")
EndIf

Now that seems to work but i wanted to learn arrays and clean it up so i made the below

Global $reportfile = "C:\Windows\Temp\"
Global $box[7]
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 492, 395, -903, 134)
$field1gui = GUICtrlCreateCombo("", 16, 32, 81, 25)
GUICtrlSetData(-1, "yes|no")
$field2gui = GUICtrlCreateCombo("", 16, 56, 81, 25)
GUICtrlSetData(-1, "yes|no")
$field3gui = GUICtrlCreateCombo("", 16, 80, 81, 25)
GUICtrlSetData(-1, "yes|no")
$field4gui = GUICtrlCreateCombo("", 16, 104, 81, 25)
GUICtrlSetData(-1, "yes|no")
$field5gui = GUICtrlCreateCombo("", 16, 128, 81, 25)
GUICtrlSetData(-1, "yes|no")
$field6gui = GUICtrlCreateCombo("", 16, 152, 81, 25)
GUICtrlSetData(-1, "yes|no")
$field7gui = GUICtrlCreateCombo("", 16, 176, 81, 25)
GUICtrlSetData(-1, "yes|no")
$field8gui = GUICtrlCreateCombo("", 16, 200, 81, 25)
GUICtrlSetData(-1, "yes|no")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
EndSwitch
Sleep (10000)
ExitLoop
WEnd
$box[0]=(GUICtrlRead($field1gui) )
$box[1]=(GUICtrlRead($field2gui) )
$box[2]=(GUICtrlRead($field3gui) )
$box[3]=(GUICtrlRead($field4gui) )
$box[4]=(GUICtrlRead($field5gui) )
$box[5]=(GUICtrlRead($field6gui) )
$box[6]=(GUICtrlRead($field7gui) )
;~ $box[7]=(GUICtrlRead($field8gui) )
If $box = "yes" Then
FileWrite($reportfile & "acc" & $box & ".txt", "account" & $box)
EndIf

Now the problem im having is somewhere on the $box[7] it has an error so i silenced it and exit code is 0...Hurray......but no output :D Am i structuring this wrong? I tried using the help but i think i get more lost than i start.

muppet hands are so soft :)

Link to comment
Share on other sites

  • Moderators

russell,

If you want to use arrays then you need to learn about loops too! :rip:

Take a look at this - I think it mirrors what you were trying to do, but with rather more compact code: :oops:

#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $reportfile = "C:WindowsTemp"
Global $box[8], $field[8]

#region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 492, 395, 903, 134)
    ; Use an array to hold the combo ControlIDs as well - then we can loop through them
    For $i = 0 To 7
        $field[$i] = GUICtrlCreateCombo("", 16, 32 + (24 * $i), 81, 25)
        GUICtrlSetData(-1, "yes|no")
    Next
    GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    Sleep(10000)
    ExitLoop
WEnd

; Now we can loop through the combos and read them
For $i = 0 To 7
    $box[$i] = GUICtrlRead($field[$i])
    If $box[$i] = "yes" Then
        ; Not quite sure what you wanted to write to the file - you should be able to see what the various options are from this.
        MsgBox(0, "Writing", $reportfile & "acc" & $i & ".txt" & @CRLF &  "account" & $box[$i])
    EndIf

Next

Please ask if you have any questions. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

How about this.

Global $reportfile = "C:\Temp\"
Global $box
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 492, 395)
$field1gui = GUICtrlCreateCombo("", 16, 32, 81, 25)
GUICtrlSetData(-1, "yes|no")
$field2gui = GUICtrlCreateCombo("", 16, 56, 81, 25)
GUICtrlSetData(-1, "yes|no")
$field3gui = GUICtrlCreateCombo("", 16, 80, 81, 25)
GUICtrlSetData(-1, "yes|no")
$field4gui = GUICtrlCreateCombo("", 16, 104, 81, 25)
GUICtrlSetData(-1, "yes|no")
$field5gui = GUICtrlCreateCombo("", 16, 128, 81, 25)
GUICtrlSetData(-1, "yes|no")
$field6gui = GUICtrlCreateCombo("", 16, 152, 81, 25)
GUICtrlSetData(-1, "yes|no")
$field7gui = GUICtrlCreateCombo("", 16, 176, 81, 25)
GUICtrlSetData(-1, "yes|no")
$field8gui = GUICtrlCreateCombo("", 16, 200, 81, 25)
GUICtrlSetData(-1, "yes|no")
$buttonGO = GUICtrlCreateButton("Go", 16, 230, 81, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $buttonGo
            Process()
    EndSwitch
WEnd

Func Process()
    $iIndex = 1
    For $field = $field1gui To $field8gui
        $box = (GUICtrlRead($field))
        If $box = "yes" Then FileWrite($reportfile & "acc" & $iIndex & ".txt", "account" & $iIndex)
        $iIndex += 1
    Next
EndFunc

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I love how you guys can do that so fast :D I cant look at your examples and to a degree understand through trial and errror how you did it but get lost quick when i take more advanced steps. I guess im thinking i don't have a foundation. I thought loops where (while,wend,exitloop) is that not the extent of loops? maybe i missed something there too :oops: If there a good place or tutorial for me to start?

muppet hands are so soft :)

Link to comment
Share on other sites

  • Moderators

russell,

If there a good place or tutorial for me to start?

How about the Help file under <Language Reference - Loop Statements>? :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Here you can find a bunch of tutorials. The Array tutorial is here.

After reading the turials you still can ask what you don't understand in our example scripts and we will do our very best to explain.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...