Sign in to follow this  
Followers 0
Starfighter

Many GUICtrlSetData and For Next

10 posts in this topic

Dear Autoit-Freaks :whistle:

I made a long Code:

Func IFSetData()

GUICtrlSetData($ListViewItem_A1,Chr(124) & $V_1)

GUICtrlSetData($ListViewItem_A2,Chr(124) & $V_2)

GUICtrlSetData($ListViewItem_A3,Chr(124) & $V_3)

GUICtrlSetData($ListViewItem_A4,Chr(124) & $V_4)

GUICtrlSetData($ListViewItem_A5,Chr(124) & $V_5)

GUICtrlSetData($ListViewItem_A6,Chr(124) & $V_6)

GUICtrlSetData($ListViewItem_A7,Chr(124) & $V_7)

GUICtrlSetData($ListViewItem_A8,Chr(124) & $V_8)

GUICtrlSetData($ListViewItem_A9,Chr(124) & $V_9)

GUICtrlSetData($ListViewItem_A10,Chr(124) & $V_10)

End Func

This code does work.

Then I made a shorter Code:

Func IFSetData()

For i$=1 to 10

GUICtrlSetData($ListViewItem_A & i$,Chr(124) & $V_ & i$)

Next

End Func

This code doesn't work.

What's wrong with this shorter code?

Please, help me. I'm a newbie.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Taking a quick look your variable i has a typo.

Func IFSetData()
    For $i=1 to 10
        GUICtrlSetData($ListViewItem_A & $i,Chr(124) & $V_ & $i)
    Next
End Func

as far as appending you commands like that I don't know if you can or can't do it that way.

chris

Edited by cshorey

...

Share this post


Link to post
Share on other sites

Sorry, I have a problem with an another code:

Long code:

_GUICtrlComboResetContent($ComboBoxControlGenre_1)

_GUICtrlComboResetContent($ComboBoxControlGenre_2)

_GUICtrlComboResetContent($ComboBoxControlGenre_3)

_GUICtrlComboResetContent($ComboBoxControlGenre_4)

_GUICtrlComboResetContent($ComboBoxControlGenre_5)

_GUICtrlComboResetContent($ComboBoxControlGenre_6)

_GUICtrlComboResetContent($ComboBoxControlGenre_7)

_GUICtrlComboResetContent($ComboBoxControlGenre_8)

_GUICtrlComboResetContent($ComboBoxControlGenre_9)

_GUICtrlComboResetContent($ComboBoxControlGenre_10)

This code does work.

Shorter code:

For $i=1 to 10

_GUICtrlComboResetContent(Eval("$ComboBoxControlGenre_" & $i))

Next

This code doesn't work!

I'm very confuse :whistle:

Share this post


Link to post
Share on other sites

Don't use $ in Eval.


"be smart, drink your wine"

Share this post


Link to post
Share on other sites

Sorry, I have a problem with an another code:

Long code:

_GUICtrlComboResetContent($ComboBoxControlGenre_1)

_GUICtrlComboResetContent($ComboBoxControlGenre_2)

_GUICtrlComboResetContent($ComboBoxControlGenre_3)

_GUICtrlComboResetContent($ComboBoxControlGenre_4)

_GUICtrlComboResetContent($ComboBoxControlGenre_5)

_GUICtrlComboResetContent($ComboBoxControlGenre_6)

_GUICtrlComboResetContent($ComboBoxControlGenre_7)

_GUICtrlComboResetContent($ComboBoxControlGenre_8)

_GUICtrlComboResetContent($ComboBoxControlGenre_9)

_GUICtrlComboResetContent($ComboBoxControlGenre_10)

This code does work.

Shorter code:

For $i=1 to 10

_GUICtrlComboResetContent(Eval("$ComboBoxControlGenre_" & $i))

Next

This code doesn't work!

I'm very confuse :whistle:

Your first Yoga chant: "Assign/Eval are evil... assign/eval are evil... assign/eval are evil..."

Now some code:

#include <guiconstants.au3>
#include <guicombo.au3>

Opt("GuiOnEventMode", 1)

; Arrays are zero-based, but you numbered from 1 so we create the array with 11 vice 10, and ignore [0]
Dim $avComboBoxes[11]

GUICreate("ComboBoxes", 200, 350)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
For $n = 1 To 10
    $avComboBoxes[$n] = GUICtrlCreateCombo("Combo: " & $n, 10, ($n * 30) - 20, 180, 20)
Next
GUICtrlCreateButton("Reset", 50, 310, 100, 30)
GUICtrlSetOnEvent(-1, "_Reset")
GUISetState()

While 1
    Sleep(20)
WEnd

Func _Quit()
    Exit
EndFunc   ;==>_Quit

Func _Reset()
    For $n = 1 To 10
        _GUICtrlComboResetContent($avComboBoxes[$n])
    Next
EndFunc   ;==>_Reset

Notice how easily the control IDs are stored when creating the GUI, and referenced in the _Reset() function.

Now for your second level mantra: "Arrays are our friends... arrays are our friends... arrays are our friends..."

:lmao:


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

Don't use $ in Eval.

Now, this code does work:

For $i=1 to 10

_GUICtrlComboResetContent(Eval("ComboBoxControlGenre_" & $i))

Next

Thank you very much.

Share this post


Link to post
Share on other sites

Now, this code does work:

For $i=1 to 10

_GUICtrlComboResetContent(Eval("ComboBoxControlGenre_" & $i))

Next

Thank you very much.

Use the arrays, Starfighter! Don't give in to the Dark Side!

Assign leads to Eval.

Eval leads to GOTO.

GOTO leads to suffering...

:whistle:


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

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