Dieuz Posted April 9, 2007 Posted April 9, 2007 I was wondering why this is not working. I have 20 buttons and when I click on a certain one, I want that the images of each buttons become blank. My buttons are all named Button_1, Button_2, Button_3 etc.. Why this code is not working? Func Blank() For $a = 1 to 20 GuiCtrlSetImage($Button_[$a], @ScriptDir & "\Radio\blankitem.bmp) Next EndFunc
martin Posted April 9, 2007 Posted April 9, 2007 I was wondering why this is not working. I have 20 buttons and when I click on a certain one, I want that the images of each buttons become blank. My buttons are all named Button_1, Button_2, Button_3 etc.. Why this code is not working? Func Blank() For $a = 1 to 20 GuiCtrlSetImage($Button_[$a], @ScriptDir & "\Radio\blankitem.bmp) Next EndFunc missing closing quotes? Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Dieuz Posted April 9, 2007 Author Posted April 9, 2007 huh? I'm getting a variable error because I did not declare $Button_ but I want it so it's $Button_[1,2,3,4,5,6,7,8,9,...]
martin Posted April 10, 2007 Posted April 10, 2007 (edited) huh? I'm getting a variable error because I did not declare $Button_ but I want it so it's $Button_[1,2,3,4,5,6,7,8,9,...] If you want an array of buttons you will have to do something like this at the start of your script Dim $Button_[12]; assuming you know how many buttons you want For $n =0 to UBound($Button_) - 1 $Button_[$n] = guictrlcreateButton(....... next Edited April 10, 2007 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Dieuz Posted April 10, 2007 Author Posted April 10, 2007 (edited) but How could I do it if my buttons are already made? $Button_1 = GuiCtrlCreateButton("", 350, 30, 35, 35, $BS_BITMAP) $Button_2 = GuiCtrlCreateButton("", 100, 10, 35, 35, $BS_BITMAP) $Button_3 = GuiCtrlCreateButton("", 200, 20, 35, 35, $BS_BITMAP) $Button_4 = GuiCtrlCreateButton("", 300, 30, 35, 35, $BS_BITMAP) $Button_5 = GuiCtrlCreateButton("", 400, 40, 35, 35, $BS_BITMAP) $Button_6 = GuiCtrlCreateButton("", 500, 50, 35, 35, $BS_BITMAP) $Button_7 = GuiCtrlCreateButton("", 600, 60, 35, 35, $BS_BITMAP) ;... I just want the $n to be the numbers 1 to 20, so it will do it for buttons 1 to 20. Edited April 10, 2007 by Dieuz
BrettF Posted April 10, 2007 Posted April 10, 2007 but How could I do it if my buttons are already made? $Button_1 = GuiCtrlCreateButton("", 350, 30, 35, 35, $BS_BITMAP) $Button_2 = GuiCtrlCreateButton("", 100, 10, 35, 35, $BS_BITMAP) $Button_3 = GuiCtrlCreateButton("", 200, 20, 35, 35, $BS_BITMAP) $Button_4 = GuiCtrlCreateButton("", 300, 30, 35, 35, $BS_BITMAP) $Button_5 = GuiCtrlCreateButton("", 400, 40, 35, 35, $BS_BITMAP) $Button_6 = GuiCtrlCreateButton("", 500, 50, 35, 35, $BS_BITMAP) $Button_7 = GuiCtrlCreateButton("", 600, 60, 35, 35, $BS_BITMAP) ;... oÝ÷ Øî²ÜÛa{MúÚzØ^éz»5¶´²Â)ev~ÛºÛhÍm£m?ªê-xé»-¡ö¥Múëm¢x¬Zªëk!rî¶Ú'«-éî·«)¶¬Ó~ºÛh]7è¶öÒÊ2¢êߢ¹h¢(ºWe¢%GºÚ"µÍÛØ[ ÌÍØÛÝ[HBBQÜ ÌÍÛLHÈ ÌÍØÛÝ[BBQÝZPÝÙ][XYÙJ ÌÍÐ]ÛÉÌÍÛØÜ [È ][ÝÉÌLÔY[ÉÌLØ[Ú][K ][ÝÊBBS^ Try that and see how you go. Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
Dieuz Posted April 10, 2007 Author Posted April 10, 2007 I'm getting:WARNING: $Button_: possibly used before declaration.
xcal Posted April 10, 2007 Posted April 10, 2007 (edited) Func Blank () For $a = 1 To 20 GUICtrlSetImage(Eval('Button_' & $a), @ScriptDir & "\Radio\blankitem.bmp) Next EndFunc edit - oops, forgot a closing bracket. If you already tried it, try again. Edited April 10, 2007 by xcal How To Ask Questions The Smart Way
Dieuz Posted April 10, 2007 Author Posted April 10, 2007 Wooot ! It work, does this will work everytime? I mean If I use Eval() to declare a group of control.
McGod Posted April 10, 2007 Posted April 10, 2007 Well if $Button_ were an array $Button_[$a] would work. But when there each a seperate variable, you need to use Eval to grab the variable. [indent][center][u]Formerly Chip[/u][/center]~UDFs~[/indent][u]IRC.au3 - Allows you to connect to IRC ServersINetCon.au3 - Connects/Disconnects/Check Status of InternetHardware Key - Creates a unique hardware hashScriptComm - Allows you to communicate between scripts using WM_COPYDATA[/u][indent]~Programs~[/indent][indent]SimonAu3ForumsIRC Bot~Web Site~Web Autoit Example[/indent][indent][b][/b][/indent][u][/u]
Dieuz Posted April 10, 2007 Author Posted April 10, 2007 (edited) Fine, Thanks guys ! Edited April 10, 2007 by Dieuz
Dieuz Posted April 11, 2007 Author Posted April 11, 2007 (edited) Using Eval(), Im getting an error here: It read each values from my Ini file and write it for the path of each pictures. For $a = 0 to 4 Eval('Read' & $a) = IniRead(@ScriptDir & "\Radio.ini", "Pic", $a, "") Next $Pic_0 = GuiCtrlCreatePic(('Read' & $a), 9, 450, 35, 35) $Pic_1 = GuiCtrlCreatePic(('Read' & $a) 43, 450, 35, 35) $Pic_2 = GuiCtrlCreatePic(('Read' & $a), 77, 450, 35, 35) $Pic_3 = GuiCtrlCreatePic(('Read' & $a), 111, 450, 35, 35) $Pic_4 = GuiCtrlCreatePic(('Read' & $a), 145, 450, 35, 35) oÝ÷ ØýÚòx-¢È¦¦XÊØb±«¢+Ø(ÀÌØíIÀô%¹¥I¡MÉ¥ÁѥȵÀìÅÕ½ÐìÀäÈíI¥¼¹¥¹¤ÅÕ½Ðì°ÅÕ½ÐíA¥ÅÕ½Ðì°ÅÕ½ÐìÀÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì¤(ÀÌØíIÄô%¹¥I¡MÉ¥ÁѥȵÀìÅÕ½ÐìÀäÈíI¥¼¹¥¹¤ÅÕ½Ðì°ÅÕ½ÐíA¥ÅÕ½Ðì°ÅÕ½ÐìÄÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì¤(ÀÌØíIÈô%¹¥I¡MÉ¥ÁѥȵÀìÅÕ½ÐìÀäÈíI¥¼¹¥¹¤ÅÕ½Ðì°ÅÕ½ÐíA¥ÅÕ½Ðì°ÅÕ½ÐìÈÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì¤(ÀÌØíIÌô%¹¥I¡MÉ¥ÁѥȵÀìÅÕ½ÐìÀäÈíI¥¼¹¥¹¤ÅÕ½Ðì°ÅÕ½ÐíA¥ÅÕ½Ðì°ÅÕ½ÐìÌÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì¤(ÀÌØíIÐô%¹¥I¡MÉ¥ÁѥȵÀìÅÕ½ÐìÀäÈíI¥¼¹¥¹¤ÅÕ½Ðì°ÅÕ½ÐíA¥ÅÕ½Ðì°ÅÕ½ÐìÐÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì¤((ÀÌØí1±|ÀôÕ¥ Ñɱ ÉÑA¥ ÀÌØíIÀ°ä°ÐÔÀ°ÌÔ°ÌÔ¤(ÀÌØí1±|ÄôÕ¥ Ñɱ ÉÑA¥ ÀÌØíIİÐ̰ÐÔÀ°ÌÔ°ÌÔ¤(ÀÌØí1±|ÈôÕ¥ Ñɱ ÉÑA¥ ÀÌØíIȰÜܰÐÔÀ°ÌÔ°ÌÔ¤(ÀÌØí1±|ÌôÕ¥ Ñɱ ÉÑA¥ ÀÌØíḬÄÄİÐÔÀ°ÌÔ°ÌÔ¤(ÀÌØí1±|ÐôÕ¥ Ñɱ ÉÑA¥ ÀÌØíIаÄÐÔ°ÐÔÀ°ÌÔ°ÌÔ¤ How can I correct it? Edited April 11, 2007 by Dieuz
BrettF Posted April 11, 2007 Posted April 11, 2007 Using Eval(), Im getting an error here: It read each values from my Ini file and write it for the path of each pictures. For $a = 0 to 4 Eval('Read' & $a) = IniRead(@ScriptDir & "\Radio.ini", "Pic", $a, "") Next $Pic_0 = GuiCtrlCreatePic(('Read' & $a), 9, 450, 35, 35) $Pic_1 = GuiCtrlCreatePic(('Read' & $a) 43, 450, 35, 35) $Pic_2 = GuiCtrlCreatePic(('Read' & $a), 77, 450, 35, 35) $Pic_3 = GuiCtrlCreatePic(('Read' & $a), 111, 450, 35, 35) $Pic_4 = GuiCtrlCreatePic(('Read' & $a), 145, 450, 35, 35) oÝ÷ ØýÚòx-¢È¦¦XÊØb±«¢+Ø(ÀÌØíIÀô%¹¥I¡MÉ¥ÁѥȵÀìÅÕ½ÐìÀäÈíI¥¼¹¥¹¤ÅÕ½Ðì°ÅÕ½ÐíA¥ÅÕ½Ðì°ÅÕ½ÐìÀÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì¤(ÀÌØíIÄô%¹¥I¡MÉ¥ÁѥȵÀìÅÕ½ÐìÀäÈíI¥¼¹¥¹¤ÅÕ½Ðì°ÅÕ½ÐíA¥ÅÕ½Ðì°ÅÕ½ÐìÄÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì¤(ÀÌØíIÈô%¹¥I¡MÉ¥ÁѥȵÀìÅÕ½ÐìÀäÈíI¥¼¹¥¹¤ÅÕ½Ðì°ÅÕ½ÐíA¥ÅÕ½Ðì°ÅÕ½ÐìÈÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì¤(ÀÌØíIÌô%¹¥I¡MÉ¥ÁѥȵÀìÅÕ½ÐìÀäÈíI¥¼¹¥¹¤ÅÕ½Ðì°ÅÕ½ÐíA¥ÅÕ½Ðì°ÅÕ½ÐìÌÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì¤(ÀÌØíIÐô%¹¥I¡MÉ¥ÁѥȵÀìÅÕ½ÐìÀäÈíI¥¼¹¥¹¤ÅÕ½Ðì°ÅÕ½ÐíA¥ÅÕ½Ðì°ÅÕ½ÐìÐÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì¤((ÀÌØí1±|ÀôÕ¥ Ñɱ ÉÑA¥ ÀÌØíIÀ°ä°ÐÔÀ°ÌÔ°ÌÔ¤(ÀÌØí1±|ÄôÕ¥ Ñɱ ÉÑA¥ ÀÌØíIİÐ̰ÐÔÀ°ÌÔ°ÌÔ¤(ÀÌØí1±|ÈôÕ¥ Ñɱ ÉÑA¥ ÀÌØíIȰÜܰÐÔÀ°ÌÔ°ÌÔ¤(ÀÌØí1±|ÌôÕ¥ Ñɱ ÉÑA¥ ÀÌØíḬÄÄİÐÔÀ°ÌÔ°ÌÔ¤(ÀÌØí1±|ÐôÕ¥ Ñɱ ÉÑA¥ ÀÌØíIаÄÐÔ°ÐÔÀ°ÌÔ°ÌÔ¤ Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
Dieuz Posted April 11, 2007 Author Posted April 11, 2007 Untested: For $a = 0 To 4 Assign('Read' & $a, IniRead(@ScriptDir & "\Radio.ini", "Pic", $a, "")) Next It doesnt work
Dieuz Posted April 11, 2007 Author Posted April 11, 2007 (edited) Is your INI formated correctly? Yes on that point , Im 100% sure. Ini File [Pic] 0=C:\Documents and Settings\Images\Radio.bmp 1=C:\Documents and Settings\Images\Radio1.bmp 2=C:\Documents and Settings\Images\Radio2.bmp 3=C:\Documents and Settings\Images\Radio3.bmp 4=C:\Documents and Settings\Images\Radio4.bmp My question was, how can I shorter this code: $Read0 = IniRead(@ScriptDir & "\Radio.ini", "Pic", "0", "") $Read1 = IniRead(@ScriptDir & "\Radio.ini", "Pic", "1", "") $Read2 = IniRead(@ScriptDir & "\Radio.ini", "Pic", "2", "") $Read3 = IniRead(@ScriptDir & "\Radio.ini", "Pic", "3", "") $Read4 = IniRead(@ScriptDir & "\Radio.ini", "Pic", "4", "") $Label_0 = GuiCtrlCreatePic($Read0, 9, 450, 35, 35) $Label_1 = GuiCtrlCreatePic($Read1, 43, 450, 35, 35) $Label_2 = GuiCtrlCreatePic($Read2, 77, 450, 35, 35) $Label_3 = GuiCtrlCreatePic($Read3, 111, 450, 35, 35) $Label_4 = GuiCtrlCreatePic($Read4, 145, 450, 35, 35) Edited April 11, 2007 by Dieuz
therks Posted April 12, 2007 Posted April 12, 2007 (edited) You weren't Eval()ing in your CreatePic functions. Using the code from your last post: For $i = 0 to 4 Assign('Read' & $i, IniRead(@ScriptDir & "\Radio.ini", "Pic", $i, "")) Assign('Label_' & $i, GuiCtrlCreatePic(Eval('Read' & $i), 9 + 35 * $i, 450, 35, 35)) NextoÝ÷ Ù:ò¶b¢é]j[(v)¶¬ü¨¹Ú'ßÛgyçmí7évö«¦åzÆ®¶sdf÷"b33c¶ÒFò@¢b33c·F×Òæ&VB67&DF"fײgV÷C²b3#µ&FòæægV÷C²ÂgV÷Cµ2gV÷C²Âb33c¶ÂgV÷C²gV÷C²¢76vâb33´Æ&VÅòb33²fײb33c¶ÂwV7G&Ä7&VFU2b33c·Fײ3R¢b33c¶ÂCSÂ3RÂ3R¤æW That would probably run a little faster (assuming that Assign()ing and Eval()ing is slower than using static variable names). *Edit: Messed up some brackets. *Edit 2: Missed some closing brackets. Edited April 14, 2007 by Saunders My AutoIt Stuff | My Github
Dieuz Posted April 12, 2007 Author Posted April 12, 2007 For $i = 0 to 4 $tmp = IniRead(@ScriptDir & "\Radio.ini", "Pic", $i, "") Assign('Label_' & $i, GuiCtrlCreatePic($tmp, 9 + 35 * $i, 450, 35, 35) Next
PsaltyDS Posted April 12, 2007 Posted April 12, 2007 Dump that mangled Assign/Eval stuff and learn to use arrays. The following creates a GUI with twenty buttons, and the control ids of the buttons are in an array called $avButtons: #include <guiconstants.au3> #include <array.au3> ; Create a GUI Opt("GuiOnEventMode", 1) $hGUI = GUICreate("20 Buttons", 190, 235) GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit") ; Twenty buttons, coming up... Dim $avButtons[1] = [0] Dim $Left = 10, $Top = 10 For $b = 1 To 20 _ArrayAdd($avButtons, GUICtrlCreateButton($b, $Left, $Top, 35, 35, $BS_BITMAP)) $Left += 45 If $Left > 155 Then $Left = 10 $Top += 45 EndIf Next $avButtons[0] = UBound($avButtons) - 1 GUISetState() While 1 Sleep(20) WEnd Func _Quit() Exit EndFunc ;==>_QuitoÝ÷ ØÚ-Ç«lw!ƧºÇ)¶"½ëazZjبÇè®Ø^nëm¢{-ç(uè¬ç!²+µêÀ)¶¶Ø^¶©'(ëÞ¯*'zíæî¶Ú'³ .Ùh¢IbëaÆ®¶sbb33c´&×fÆRÒgV÷C´3¢b3#µFV×b3#´×'WGFöâæ&×gV÷C°¤f÷"b33c¶"ÒFòb33c¶d'WGFöç5³Ð uT7G&Å6WDÖvRb33c¶d'WGFöç5²b33c¶%ÒÂb33c´&×fÆR¤æW See how much easier they are to work with, once you get them in an array? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Dieuz Posted April 13, 2007 Author Posted April 13, 2007 Yes an array shorter the code alot but it would be very hard to make an array with my pictures because they are almost randomly positioned. Well as I can see, the only things that I need to shorter is this: $Read0 = IniRead(@ScriptDir & "\Radio.ini", "Pic", "0", "") $Read1 = IniRead(@ScriptDir & "\Radio.ini", "Pic", "1", "") $Read2 = IniRead(@ScriptDir & "\Radio.ini", "Pic", "2", "") $Read3 = IniRead(@ScriptDir & "\Radio.ini", "Pic", "3", "") $Read4 = IniRead(@ScriptDir & "\Radio.ini", "Pic", "4", "") If im able to shorter this, I will be happy.
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