Jump to content

How to shorten this code?


Recommended Posts

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!!!
Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

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!!!
Link to comment
Share on other sites

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!!!
Link to comment
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!!!
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...