Sign in to follow this  
Followers 0
JohnOne

GuiCtrl Creation by Array

5 posts in this topic

#1 ·  Posted (edited)

Ive been trying to create a gui using an array and a counter.

The results I get are not expected by me, so I must be doing something wrong.

The simple gui will have 20 lables named 0-19, That works fine.

I expected the Array colums to contain the same data, 0 - 19, Wrong it contains 3 - 23

I cannot figure out why, but my guess is Im using ByRef incorrectly.

Any pointers to my problem, and/or bad habits in my code would be welcomed please.

#include <Array.au3>
#include <Guiconstants.au3>

Global $aGuiData[20]

Func _GuiCreate(ByRef $aGuiData)
$Gui = GUICreate("Test",400,400,500,100)
Local $a = 0
For $i = 5 To 290 Step 15
    $aGuiData[$a] = GUICtrlCreateLabel($a,5,$i,390,20)
    $a += 1
Next
GUISetState()
EndFunc

_GuiCreate($aGuiData)
_ArrayDisplay($aGuiData)

while 1
    Sleep(50)
    $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
        
                Exit
    EndSelect
Wend
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites



JohnOne,

You are setting the array elements to the ControlIDs of the labels. There are the internal numbers which AutoIt uses to keep track of the controls it creates. For reasons too complicated to go into here, these start at 3 - hence your array starts from 3.

These ControlIDs are what Autoit looks for in a GUIGetMsg loop and what you use to identify controls in many AutoIt commands.

Questions? :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks for the explaination Melba23, I had in in my head that they would just be 0 to 19 as displayed in the _ArrayDisplay().

I was looking for a minimalistic way to assign $variables to the control IDs for later use, without typing them all out.

Got My eye wiped eh.

Thanks again Mate.

Edit:

what threw me was first I was using a MsgBox() to display $aGuiData[19], and its output was what I expected .. 19. (after having read the label I mean)

wierd.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

JohnOne,

No, it is not wierd - it is exactly what should happen! :D

Think about it - you have set the [19] element of the array to the ControlID of the 19th label. So when you use

GUICtrlRead($aArray[19])

you are reading the control whose ControlID is in the [19] element - which is the 19th label. It matters little to you that the actual value of the [19] element is 22 (or whatever!). This is the clever bit about using the ControlIDs - as long as you know the variables in which you have stored them, the actual values are transparent to the user.

I hope that explains it better - do ask if not. That is why we are here after all! :huggles:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Yep, I think I get it.

Although I wish I had'nt used arrydisplay for testing now, cause its just something else Im thinking about while figuring out my script.

Appreciate the help mucker, you're like a knight in shining armour. :D


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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  
Followers 0