Pook Posted April 26, 2010 Share Posted April 26, 2010 I'm Trying to update a List of labels from an INI File. But I can get the GUICtrlSetData to update multiple labels. (it's just blank every time) Am i doing this all wrong? $Form1 = GUICreate("Form1", 633, 447, 192, 124) $Group1 = GUICtrlCreateGroup("Group1", 32, 40, 545, 305) $Label1 = GUICtrlCreateLabel("", 72, 96, 82, 17) $Label2 = GUICtrlCreateLabel("", 64, 136, 82, 17) $Label3 = GUICtrlCreateLabel("", 64, 168, 82, 17) $Label4 = GUICtrlCreateLabel("", 72, 200, 82, 17) $Label5 = GUICtrlCreateLabel("", 72, 232, 82, 17) $Label6 = GUICtrlCreateLabel("", 232, 96, 82, 17) $Label7 = GUICtrlCreateLabel("", 232, 128, 82, 17) $Label8 = GUICtrlCreateLabel("", 232, 168, 82, 17) $Label9 = GUICtrlCreateLabel("", 232, 200, 82, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) Call ("_logon") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _logon() Dim $aRecords Dim $Label Dim $item If Not _FileReadToArray("Test.ini",$aRecords) Then EndIf $Y = 1 For $x = 1 to $aRecords[0] $NewStr = StringReplace($aRecords[$x],'"','') $item = $NewStr GUICtrlSetData($Label & $Y,$NewStr ) $Y= $Y + 1 Next EndFunc Link to comment Share on other sites More sharing options...
Fire Posted April 26, 2010 Share Posted April 26, 2010 expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> Dim $avarray If not FileExists(@ScriptDir&"\yourlangfilegoeshere.ini") Then For $i=1 To 9 FileWrite(@ScriptDir&"\yourlangfilegoeshere.ini","Label" & $i & @CRLF) Next EndIf _FileReadToArray(@ScriptDir&"\yourlangfilegoeshere.ini",$avarray) $Form1 = GUICreate("Form1", 633, 447, 192, 124) $Group1 = GUICtrlCreateGroup("Group", 32, 40, 545, 305) $Label1 = GUICtrlCreateLabel($avarray[1], 72, 96, 82, 17) $Label2 = GUICtrlCreateLabel($avarray[2], 64, 136, 82, 17) $Label3 = GUICtrlCreateLabel($avarray[3], 64, 168, 82, 17) $Label4 = GUICtrlCreateLabel($avarray[4], 72, 200, 82, 17) $Label5 = GUICtrlCreateLabel($avarray[5], 72, 232, 82, 17) $Label6 = GUICtrlCreateLabel($avarray[6], 232, 96, 82, 17) $Label7 = GUICtrlCreateLabel($avarray[7], 232, 128, 82, 17) $Label8 = GUICtrlCreateLabel($avarray[8], 232, 168, 82, 17) $Label9 = GUICtrlCreateLabel($avarray[9], 232, 200, 82, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Label1 MsgBox(64,"I`m Label1","I`m Label1",10) EndSwitch WEnd + In future you can use Fileinstall with this method. [size="5"] [/size] Link to comment Share on other sites More sharing options...
Spiff59 Posted April 26, 2010 Share Posted April 26, 2010 (edited) Your problem is in the parameters you've supplied to GUICtrlSetData(). Your line: GUICtrlSetData($Label & $Y,$NewStr ) ... has a flaw in it. The variable "$Label" had not been defined previously, so your reference to it creates a new variable of that name and assigns zero to it. Then you add the value of $Y to zero and use the result as the ctrl handle in the SetData statement. That will try to update the $Y'th control in your GUI, as control handles are assigned sequentially as they are created (one for the GUI itself, one for the group, the first label, etc). It will not line up with your intended label controls. This will likely do the trick, as it starts with the value already assigned to the first predefined label, and increments from there: $Y = 0 For $x = 1 to $aRecords[0] $NewStr = StringReplace($aRecords[$x],'"','') GUICtrlSetData($Label1 + $Y,$NewStr ) $Y= $Y + 1 Next Or you could use an array for your labels: Global $Label[10] = [9] $Label[1] = GUICtrlCreateLabel("1", 72, 96, 82, 17) $Label[2] = GUICtrlCreateLabel("2", 64, 136, 82, 17) $Label[3] = GUICtrlCreateLabel("3", 64, 168, 82, 17) For $x = 1 to $aRecords[0] $NewStr = StringReplace($aRecords[$x],'"','') GUICtrlSetData($Label[$x],$NewStr ) Next Or, another method that concatenates "Label" and $Y so they will be interpreted as a single variable: GUICtrlSetData(Eval("Label" & $Y),$NewStr ) Edited April 26, 2010 by Spiff59 Link to comment Share on other sites More sharing options...
Pook Posted April 26, 2010 Author Share Posted April 26, 2010 Thanks... one question. I have 9 labels showing but the INI file might have 5 items in it one time, then maybe 2 items the next time. (will be different each time you run it) My question is how to I keep the avarray from error-ing out and just leave the label blank if the INI file doesn't havethe same number of items to fill all 9 labels. (does that make sense?) Link to comment Share on other sites More sharing options...
Pook Posted April 26, 2010 Author Share Posted April 26, 2010 Thanks This code work!!!!! Solved both problems with it. Global $Label[10] = [9] $Label[1] = GUICtrlCreateLabel("1", 72, 96, 82, 17) $Label[2] = GUICtrlCreateLabel("2", 64, 136, 82, 17) $Label[3] = GUICtrlCreateLabel("3", 64, 168, 82, 17) For $x = 1 to $aRecords[0] $NewStr = StringReplace($aRecords[$x],'"','') GUICtrlSetData($Label[$x],$NewStr ) Next 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