Sign in to follow this  
Followers 0
Dieuz

For Statement

25 posts in this topic

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

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

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,...]

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 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.

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by Dieuz

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

I'm getting:

WARNING: $Button_: possibly used before declaration.

Share this post


Link to post
Share on other sites

Wooot ! It work, does this will work everytime? I mean If I use Eval() to declare a group of control.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Fine, Thanks guys !

Edited by Dieuz

Share this post


Link to post
Share on other sites

#12 ·  Posted (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¥ ÀÌØíIÌ°ÄÄÄ°ÐÔÀ°ÌÔ°ÌÔ¤(ÀÌØí1±|ÐôÕ¥
Ñɱ
ÉÑA¥ ÀÌØíIаÄÐÔ°ÐÔÀ°ÌÔ°ÌÔ¤

How can I correct it?

Edited by Dieuz

Share this post


Link to post
Share on other sites

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¥ ÀÌØíIÌ°ÄÄÄ°ÐÔÀ°ÌÔ°ÌÔ¤(ÀÌØí1±|ÐôÕ¥
Ñɱ
ÉÑA¥ ÀÌØíIаÄÐÔ°ÐÔÀ°ÌÔ°ÌÔ¤

Share this post


Link to post
Share on other sites

It doesnt work :shocked:

Is your INI formated correctly?

Share this post


Link to post
Share on other sites

#16 ·  Posted (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 by Dieuz

Share this post


Link to post
Share on other sites

#17 ·  Posted (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[()¶¬ü¨¹Ú'ßÛ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. :shocked:

Edited by Saunders

Share this post


Link to post
Share on other sites

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?

:shocked:


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

Share this post


Link to post
Share on other sites

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.

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