gerwim Posted January 9, 2011 Share Posted January 9, 2011 (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 January 9, 2011 by gerwim Link to comment Share on other sites More sharing options...
Kalin Posted January 9, 2011 Share Posted January 9, 2011 (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 January 9, 2011 by Kalin Link to comment Share on other sites More sharing options...
Kalin Posted January 9, 2011 Share Posted January 9, 2011 (edited) -Oops, double post- Edited January 9, 2011 by Kalin Link to comment Share on other sites More sharing options...
shanet Posted January 9, 2011 Share Posted January 9, 2011 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 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 Link to comment Share on other sites More sharing options...
somdcomputerguy Posted January 9, 2011 Share Posted January 9, 2011 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. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 9, 2011 Moderators Share Posted January 9, 2011 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 WEndHowever, 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 WEndPlease ask if you have any questions. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
gerwim Posted January 9, 2011 Author Share Posted January 9, 2011 #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. M23 Awesome, worked =) Link to comment Share on other sites More sharing options...
somdcomputerguy Posted January 9, 2011 Share Posted January 9, 2011 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. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 9, 2011 Moderators Share Posted January 9, 2011 somdcomputerguy, But arrays are far more elegant. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Mat Posted January 9, 2011 Share Posted January 9, 2011 And make it through obfuscator... AutoIt Project Listing Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 9, 2011 Moderators Share Posted January 9, 2011 Mat, I did not want to get too complicated...but I entirely agree! M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now