lautre Posted July 25, 2012 Share Posted July 25, 2012 (edited) hello there, i'm trying to load an variable from a file then use it in GUICtrlSetData but it don't work (it look like i can't use $array[1] in that place), any idea how i can bypass that ? thanks GUICreate("gui", 500, 500) $Label1 = GUICtrlCreateLabel("test1", 0, 0, 50, 12) $Label2 = GUICtrlCreateLabel("test2", 0, 30, 50, 12) _archaicmultilang() GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case -3 Exit EndSwitch WEnd Func _archaicmultilang() Local $file = FileOpen(@ScriptDir & "lang" & IniRead($ConfigFile, "CFG", "langfile",""), 0) While 1 Local $line = FileReadLine($file) If @error = -1 Then ExitLoop $array = StringSplit($line, "=", 1) GUICtrlSetData($array[1], $array[2]) ;~ MsgBox(0, "Line read:", $array[1] & ":" & $array[2]) WEnd FileClose($file) EndFunc ;==>_archaicmultilang the file $Label1=testfr1 $Label2=testfr2 Edited July 25, 2012 by lautre Link to comment Share on other sites More sharing options...
kaotkbliss Posted July 25, 2012 Share Posted July 25, 2012 You are trying to use a GUI Control (guictrlsetdata) to set the value of a variable 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
BartW Posted July 25, 2012 Share Posted July 25, 2012 (edited) HI, I think (corect me if i am worng)it not gone work this way. i made a simpeler test just reading direct form a variable. GUICreate("gui", 500, 500) Global $Label1 = GUICtrlCreateLabel("test1", 0, 0, 50, 12) Global $Label2 = GUICtrlCreateLabel("test2", 0, 30, 50, 12) GUISetState(@SW_SHOW) _archaicmultilang() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case -3 Exit EndSwitch WEnd Func _archaicmultilang() $array1 = "$label1" $array2 = "test123456" GUICtrlSetData($array1, $array2) MsgBox(0, "Line read:", $array1 & ":" & $array2) EndFunc ;==>_archaicmultilang ant it is not working. so i think that you have to fil in all the label name's Edited July 25, 2012 by BartW Link to comment Share on other sites More sharing options...
johnmcloud Posted July 25, 2012 Share Posted July 25, 2012 Is this what you want to do? GUICreate("gui", 500, 500) Global $Label1 = GUICtrlCreateLabel("test1", 0, 0, 50, 12) Global $Label2 = GUICtrlCreateLabel("test2", 0, 30, 50, 12) GUISetState(@SW_SHOW) _archaicmultilang() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case -3 Exit EndSwitch WEnd Func _archaicmultilang() $array1 = $label1 $array2 = "test123456" GUICtrlSetData($array1, $array2) MsgBox(0, "Line read:", GUICtrlRead($array1) & " : " & $array2) EndFunc ;==>_archaicmultilang Link to comment Share on other sites More sharing options...
Bowmore Posted July 25, 2012 Share Posted July 25, 2012 This is the correct way to use GUICtrlSetData() GUICreate("gui", 500, 500) $Label1 = GUICtrlCreateLabel("test1", 0, 0, 50, 12) $Label2 = GUICtrlCreateLabel("test2", 0, 30, 50, 12) _archaicmultilang() GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case -3 Exit EndSwitch WEnd Func _archaicmultilang() Local $file = FileOpen(@ScriptDir & "lang" & IniRead($ConfigFile, "CFG", "langfile",""), 0) While 1 Local $line = FileReadLine($file) If @error = -1 Then ExitLoop $array = StringSplit($line, "=", 1) GUICtrlSetData($Label1, $array[1]) ;<======= Set Label 1 to display the value in $array[1] GUICtrlSetData($Label2, $array[2]) ;<======= Set Label 2 to display the value in $array[2] ;~ MsgBox(0, "Line read:", $array[1] & ":" & $array[2]) WEnd FileClose($file) EndFunc ;==>_archaicmultilang "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
lautre Posted July 25, 2012 Author Share Posted July 25, 2012 (edited) Is this what you want to do? GUICreate("gui", 500, 500) Global $Label1 = GUICtrlCreateLabel("test1", 0, 0, 50, 12) Global $Label2 = GUICtrlCreateLabel("test2", 0, 30, 50, 12) GUISetState(@SW_SHOW) _archaicmultilang() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case -3 Exit EndSwitch WEnd Func _archaicmultilang() $array1 = $label1 $array2 = "test123456" GUICtrlSetData($array1, $array2) MsgBox(0, "Line read:", GUICtrlRead($array1) & " : " & $array2) EndFunc ;==>_archaicmultilang i tried adapted your code but i don't work too :/ $array = StringSplit($line, "=", 1) $array1 = $array[1] $array2 = $array[2] GUICtrlSetData($array1, $array2) MsgBox(0, "Line read:", GUICtrlRead($array1) & " : "& $array1 &":"& $array2) GUICtrlRead($array1) in the msgbox return 0 This is the correct way to use GUICtrlSetData() GUICreate("gui", 500, 500) $Label1 = GUICtrlCreateLabel("test1", 0, 0, 50, 12) $Label2 = GUICtrlCreateLabel("test2", 0, 30, 50, 12) _archaicmultilang() GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case -3 Exit EndSwitch WEnd Func _archaicmultilang() Local $file = FileOpen(@ScriptDir & "lang" & IniRead($ConfigFile, "CFG", "langfile",""), 0) While 1 Local $line = FileReadLine($file) If @error = -1 Then ExitLoop $array = StringSplit($line, "=", 1) GUICtrlSetData($Label1, $array[1]) ;<======= Set Label 1 to display the value in $array[1] GUICtrlSetData($Label2, $array[2]) ;<======= Set Label 2 to display the value in $array[2] ;~ MsgBox(0, "Line read:", $array[1] & ":" & $array[2]) WEnd FileClose($file) EndFunc ;==>_archaicmultilang yea but it mean i have to write every label , can't i load the the variable from my file like i'm trying to ? thanks you guys but I must express myself badly as it seem you do not understand me i have one language file filled like that : $Label1=testfr1 $thatvariable=blabla $anothervariable=ok etc.... my gui is in english by default. : $Label1 = GUICtrlCreateLabel("example", 0, 0, 50, 12) I'll open my language file and use stringplit : Local $file = FileOpen(@ScriptDir & "lang" & IniRead($ConfigFile, "CFG", "langfile",""), 0) Local $line = FileReadLine($file) $array = StringSplit($line, "=", 1) so for the first line $array[1] return $label1 and $array[2] return testfr1 now im trying to put my translated text in my label/ button or others by using : GUICtrlSetData($array[1], $array[2]) but i don't work the text don't change on the gui. do i need to do something special to get it working, any workaround? Edited July 25, 2012 by lautre Link to comment Share on other sites More sharing options...
BartW Posted July 26, 2012 Share Posted July 26, 2012 (edited) hi . maybe this helps you in the right direction. there are limits the arry only allow 64 items. GUICreate("gui", 500, 500) Global $label[3] $label[0] = UBound($label) $label[1] = GUICtrlCreateLabel("test1", 0, 0, 50, 12) $label[2] = GUICtrlCreateLabel("test2", 0, 30, 50, 12) _archaicmultilang() GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case -3 Exit EndSwitch WEnd Func _archaicmultilang() Local $multilanginput = StringSplit("$Label1=testfr1" & @CR & "$Label2=testfr2", @CR) Local $counter1 = 1 While 1 if $counter1 > $multilanginput[0] then ExitLoop Local $line = $multilanginput[$counter1] $array = StringSplit($line, "=") $label_number = StringRight($array[1], 1) GUICtrlSetData($label[$label_number], $array[2]) $counter1 += 1 WEnd EndFunc ;==>_archaicmultilang Edited July 26, 2012 by BartW 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