Sign in to follow this  
Followers 0
gerwim

Setting GUI dynamically

11 posts in this topic

#1 ·  Posted (edited)

Hi folks,

Im creating 2 labels as follow:

$Text_Server1 = GUICtrlCreateLabel("Offline", 144, 72, 34, 17)
$Text_Server2 = GUICtrlCreateLabel("Offline", 144, 104, 34, 17)

Now I want to change their contents, I'm trying with this:

For $i = 0 To ($vAantalServers-1) Step +1
    if ($aServerStatus[$i] = "0") Then
        GUICtrlSetData($Text_Server & $i, "Offline")
        GUICtrlSetColor($Text_Server & $i, 0xFF0000)
    Else
        GUICtrlSetData($Text_Server & $i, $aServerPing[$i])
    EndIf
Next

But, the contents are not updated now. Is there anyway todo this?

Thanks.

Edited by gerwim

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Well, you hardly gave any detail to the code snippet you posted.

But this is what I came up with, maybe it'll give you an idea how to solve this problem.

Tip: when handling arrays you should refer to the UBound command.

Your code with a short revision:

Dim $aServerStatus[1] ; Array example

For $i = 0 To UBound($aServerStatus)  ; The default increment of the For To loop is +1, no need to use the Step option.
    if ($aServerStatus[$i] = "0") Then
        ; GUICtrlSetData($Text_Server & $i, "Offline")
        ; GUICtrlSetColor($Text_Server & $i, 0xFF0000)
    Else
       ; GUICtrlSetData($Text_Server & $i, $aServerPing[$i])
    EndIf
Next

An example of what you probably need to do:

Dim $aServerStatus[1] ; Array declaration, 2 elements.

For $i = 0 To UBound($aServerStatus)  ; The default increment of the For To loop is +1, no need to use the Step option.
    MsgBox(0, "", $i)
Next
Edited by Kalin

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

-Oops, double post-

Edited by Kalin

Share this post


Link to post
Share on other sites

Hi folks,

Im creating 2 labels as follow:

$Text_Server1 = GUICtrlCreateLabel("Offline", 144, 72, 34, 17)
$Text_Server2 = GUICtrlCreateLabel("Offline", 144, 104, 34, 17)

Now I want to change their contents, I'm trying with this:

For $i = 0 To ($vAantalServers-1) Step +1
    if ($aServerStatus[$i] = "0") Then
        GUICtrlSetData($Text_Server & $i, "Offline")
        GUICtrlSetColor($Text_Server & $i, 0xFF0000)
    Else
        GUICtrlSetData($Text_Server & $i, $aServerPing[$i])
    EndIf
Next

But, the contents are not updated now. Is there anyway todo this?

Thanks.

Have a look at the variables you are setting the data to. Do you have any variables declared called $Text_Server?

If you do, shame on you for not letting us know :x

You told us the variables $Text_Server1 and $Text_Server2. They could just as easily be $asdf and $hjkl and the software would handle this program exactly the same.

You need to let the program know you want to change the data at $Text_Server1 & 2.

shanet


[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:
%programfiles%/AutoIt3/autoit3.chm

Share this post


Link to post
Share on other sites

You need to let the program know you want to change the data at $Text_Server1 & 2.

That's what
$Text_Server & $i
is for.

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

gerwim,

If you want to use individual variables for your labels then you need to use Eval to get the interpreter to correctly evaluate the concatenated string:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$Text_Server1 = GUICtrlCreateLabel("Offline", 144, 72, 34, 17)
$Text_Server2 = GUICtrlCreateLabel("Offline", 144, 104, 34, 17)

$hButton = GUICtrlCreateButton("Update", 10, 10, 80, 30)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            For $i = 1 To 2
                GUICtrlSetData(Eval("Text_Server" & $i), "Updated") ; <<<<<<<<<<<<<<<<<<<
            Next
    EndSwitch
WEnd

However, a more elegant solution would be to use an array to hold the label ControlIDs, like this:

#include <GUIConstantsEx.au3>

Global $aLabels[2]

$hGUI = GUICreate("Test", 500, 500)

$aLabels[0] = GUICtrlCreateLabel("Offline", 144, 72, 34, 17)
$aLabels[1] = GUICtrlCreateLabel("Offline", 144, 104, 34, 17)

$hButton = GUICtrlCreateButton("Update", 10, 10, 80, 30)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            For $i = 0 To UBound($aLabels) - 1
                GUICtrlSetData($aLabels[$i], "Updated")
            Next
    EndSwitch
WEnd

Please ask if you have any questions. :x

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

#include <GUIConstantsEx.au3>

Global $aLabels[2]

$hGUI = GUICreate("Test", 500, 500)

$aLabels[0] = GUICtrlCreateLabel("Offline", 144, 72, 34, 17)
$aLabels[1] = GUICtrlCreateLabel("Offline", 144, 104, 34, 17)

$hButton = GUICtrlCreateButton("Update", 10, 10, 80, 30)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            For $i = 0 To UBound($aLabels) - 1
                GUICtrlSetData($aLabels[$i], "Updated")
            Next
    EndSwitch
WEnd

Please ask if you have any questions. :x

M23

Awesome, worked =)

Share this post


Link to post
Share on other sites

Oops, I forgot about Eval. I just recently figured it out how to use it in code like this

$Input0 = GUICtrlCreateInput("Nick Name", 10, 135, 120, 24)
$Input1 = GUICtrlCreateInput("Name", 145, 135, 200, 24)
$Input2 = GUICtrlCreateInput("Parent, Sire", 225, 90, 185, 24)
$Input3 = GUICtrlCreateInput("Parent, Dam", 225, 185, 185, 24)
$Input4 = GUICtrlCreateInput("Sire Sire Parent", 350, 55, 225, 24)
$Input5 = GUICtrlCreateInput("Sire Dam Parent", 350, 120, 225, 24)
$Input6 = GUICtrlCreateInput("Dam Sire Parent", 350, 150, 225, 24)
$Input7 = GUICtrlCreateInput("Dam Dam Parent", 350, 215, 225, 24)
$Input8 = GUICtrlCreateInput("Date of Birth", 55, 245, 160, 24)
$Input9 = GUICtrlCreateInput("Med Info", 55, 305, 520, 24)
$Input10 = GUICtrlCreateInput("Comments", 55, 360, 520, 24)

; more code here...

For $i = 0 to 10
    ControlSend("Replace", "", "Edit2", GUICtrlRead(Eval("Input" & $i)))
Next

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

somdcomputerguy,

But arrays are far more elegant. :x

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

Mat,

I did not want to get too complicated...but I entirely agree! :x

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

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