Sign in to follow this  
Followers 0
damian666

How to shorten this code?

10 posts in this topic

Func BUTTON2CLICK()
 GUICtrlSetData($ListView1_0, "")
 GUICtrlSetData($ListView1_0, "|" & "")
 GUICtrlSetData($ListView1_0, "|" & "|" & "")
 GUICtrlSetData($ListView1_1, "")
 GUICtrlSetData($ListView1_1, "|" & "")
 GUICtrlSetData($ListView1_1, "|" & "|" & "")
 GUICtrlSetData($ListView1_2, "")
 GUICtrlSetData($ListView1_2, "|" & "")
 GUICtrlSetData($ListView1_2, "|" & "|" & "")
 GUICtrlSetData($ListView1_3, "")
 GUICtrlSetData($ListView1_3, "|" & "")
 GUICtrlSetData($ListView1_3, "|" & "|" & "")
 GUICtrlSetData($ListView1_4, "")
 GUICtrlSetData($ListView1_4, "|" & "")
 GUICtrlSetData($ListView1_4, "|" & "|" & "")
 GUICtrlSetData($ListView1_5, "")
 GUICtrlSetData($ListView1_5, "|" & "")
 GUICtrlSetData($ListView1_5, "|" & "|" & "")
 GUICtrlSetData($ListView1_6, "")
 GUICtrlSetData($ListView1_6, "|" & "")
 GUICtrlSetData($ListView1_6, "|" & "|" & "")
 GUICtrlSetData($ListView1_7, "")
 GUICtrlSetData($ListView1_7, "|" & "")
 GUICtrlSetData($ListView1_7, "|" & "|" & "")
 GUICtrlSetData($ListView1_8, "")
 GUICtrlSetData($ListView1_8, "|" & "")
 GUICtrlSetData($ListView1_8, "|" & "|" & "")
 GUICtrlSetData($ListView1_9, "")
 GUICtrlSetData($ListView1_9, "|" & "")
 GUICtrlSetData($ListView1_9, "|" & "|" & "")
 Call("SET_GUI")
 GUICtrlSetData($Label1, "Done!!!")
EndFunc   ;==>BUTTON2CLICK

i want to know if there is a way to shorten the above piece of code, this seems like a waste of space to me.

any help will be apriciated ^^

Damian666


and proud of it!!!

Share this post


Link to post
Share on other sites



Here you are.

Func BUTTON2CLICK()
    For $x = 0 To 9
        GUICtrlSetData($ListView1[$x], "")
        GUICtrlSetData($ListView1[$x], "|" & "")
        GUICtrlSetData($ListView1[$x], "|" & "|" & "")
    Next
    SetGUI()
    GUICtrlSetData($Label1, "Done!!!")
EndFunc

As you can see, when you do something repetitive like this, it is beneficial to put the controls into an array.


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

nice ^^

i didnt knew those were allowed with $variables

thanx a lot, this saves a lot of coding :)

Damian666


and proud of it!!!

Share this post


Link to post
Share on other sites

You didn't know arrays were allowed to have variables? That is an important concept. Putting like variables or controls into an array can allow you to perform the same function on all of them much easier. Just think if you have 25 or 50 controls that had to be edited.


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

hmm... then what would cause this?

==> Subscript used with non-Array variable.:
GUICtrlSetData($ListView1[$x], "")
GUICtrlSetData($ListView1^ ERROR
->17:26:37 AutoIT3.exe ended.rc:1

oh, i know arrays use variables, just didnt know that would work on controls too >.<

Edited by damian666

and proud of it!!!

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Oh! sorry. Forgot to declare arrays. You need to declare the array at the beginning of the script. Use "Dim $ListView1[10]" because there are 10 elements in the array.

Edited by dantay9

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

oh yeah >.< sheesh...

that i myself didnt notice that Posted Image

but should that not be "Dim $ListView1_[10]" ??

notice the underscore?

yeah, that fixed it, thank you for your time :)

Edited by damian666

and proud of it!!!

Share this post


Link to post
Share on other sites

ok, seems like i still dont get it, the above works, but this wont ???

For $x = 0 To 9
  $string1 = IniRead($lic, $number, "info1", "")
  $string2 = IniRead($lic, $number, "info2", "")
  $status = IniRead($lic, $number, "Status", "")

    If Not @error Then
        GUICtrlSetData($ListView1_[$x], $string1)
        GUICtrlSetData($ListView1_[$x], "|" & $string2)
        GUICtrlSetData($ListView1_[$x], "|" & "|" & $status)
  EndIf
  $number += 1
 Next

i mean, wtf... its the same principle right?

it does read the info correct, but wont insert it in the control...

Damian666


and proud of it!!!

Share this post


Link to post
Share on other sites

ooooh yeah... :)

who says you cant learn after a few years ^^

thank you both :)

Damian666


and proud of it!!!

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