Sign in to follow this  
Followers 0
OmenSWE

Make my scrip smaller and smarter

6 posts in this topic

Hello trying to make my 314 line scrip smaller by doing it smarter.

CODE

Func _Save()

IniWrite("saved.ini", "Numpad", "text0", GUICtrlRead($input[0]))

IniWrite("saved.ini", "Numpad", "text1", GUICtrlRead($input[1]))

IniWrite("saved.ini", "Numpad", "text2", GUICtrlRead($input[2]))

IniWrite("saved.ini", "Numpad", "text3", GUICtrlRead($input[3]))

IniWrite("saved.ini", "Numpad", "text4", GUICtrlRead($input[4]))

IniWrite("saved.ini", "Numpad", "text5", GUICtrlRead($input[5]))

IniWrite("saved.ini", "Numpad", "text6", GUICtrlRead($input[6]))

IniWrite("saved.ini", "Numpad", "text7", GUICtrlRead($input[7]))

IniWrite("saved.ini", "Numpad", "text8", GUICtrlRead($input[8]))

IniWrite("saved.ini", "Numpad", "text9", GUICtrlRead($input[9]))

IniWrite("saved.ini", "CtrlNumpad", "text1", GUICtrlRead($input[10]))

IniWrite("saved.ini", "CtrlNumpad", "text2", GUICtrlRead($input[11]))

IniWrite("saved.ini", "CtrlNumpad", "text2", GUICtrlRead($input[12]))

IniWrite("saved.ini", "CtrlNumpad", "text3", GUICtrlRead($input[13]))

IniWrite("saved.ini", "CtrlNumpad", "text4", GUICtrlRead($input[14]))

IniWrite("saved.ini", "CtrlNumpad", "text5", GUICtrlRead($input[15]))

IniWrite("saved.ini", "CtrlNumpad", "text6", GUICtrlRead($input[16]))

IniWrite("saved.ini", "CtrlNumpad", "text7", GUICtrlRead($input[17]))

IniWrite("saved.ini", "CtrlNumpad", "text8", GUICtrlRead($input[18]))

IniWrite("saved.ini", "CtrlNumpad", "text9", GUICtrlRead($input[19]))

EndFunc

Func _Load()

GUICtrlSetData($input[0], IniRead("saved.ini", "Numpad", "text0", " "))

GUICtrlSetData($input[1], IniRead("saved.ini", "Numpad", "text1", " "))

GUICtrlSetData($input[2], IniRead("saved.ini", "Numpad", "text2", " "))

GUICtrlSetData($input[3], IniRead("saved.ini", "Numpad", "text3", " "))

GUICtrlSetData($input[4], IniRead("saved.ini", "Numpad", "text4", " "))

GUICtrlSetData($input[5], IniRead("saved.ini", "Numpad", "text5", " "))

GUICtrlSetData($input[6], IniRead("saved.ini", "Numpad", "text6", " "))

GUICtrlSetData($input[7], IniRead("saved.ini", "Numpad", "text7", " "))

GUICtrlSetData($input[8], IniRead("saved.ini", "Numpad", "text8", " "))

GUICtrlSetData($input[9], IniRead("saved.ini", "Numpad", "text9", " "))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Alt;;;;;;;;;;;;;;;;;;;;;;;;;;;;

GUICtrlSetData($input[10], IniRead("saved.ini", "CtrlNumpad", "text0", " "))

GUICtrlSetData($input[11], IniRead("saved.ini", "CtrlNumpad", "text1", " "))

GUICtrlSetData($input[12], IniRead("saved.ini", "CtrlNumpad", "text2", " "))

GUICtrlSetData($input[13], IniRead("saved.ini", "CtrlNumpad", "text3", " "))

GUICtrlSetData($input[14], IniRead("saved.ini", "CtrlNumpad", "text4", " "))

GUICtrlSetData($input[15], IniRead("saved.ini", "CtrlNumpad", "text5", " "))

GUICtrlSetData($input[16], IniRead("saved.ini", "CtrlNumpad", "text6", " "))

GUICtrlSetData($input[17], IniRead("saved.ini", "CtrlNumpad", "text7", " "))

GUICtrlSetData($input[18], IniRead("saved.ini", "CtrlNumpad", "text8", " "))

GUICtrlSetData($input[19], IniRead("saved.ini", "CtrlNumpad", "text9", " "))

EndFunc

To

CODE

Func _Save()

For $i = 0 To 9

IniWrite("saved.ini", "Numpad", "text"[$i]"", GUICtrlRead($input[$i]))

Next

For $i = 10 To 19

For $si = 1 To 9

IniWrite("saved.ini", "CtrlNumpad", "text"[$si]"", GUICtrlRead($input[$i]))

Next

Next

EndFunc

Func _Load()

For $i = 0 To 9

GUICtrlSetData($input[$i], IniRead("saved.ini", "Numpad", "text"[$i]"", " "))

Next

For $i = 10 To 19

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Alt;;;;;;;;;;;;;;;;;;;;;;;;;;;;

GUICtrlSetData($input[$i], IniRead("saved.ini", "CtrlNumpad", "text"[$i]"", " "))

Next

EndFunc

But i dont know how to do it right.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

An example on how to make it shorter.

Func _Save()
For $x = 0 To 19
    IniWrite("saved.ini", "Numpad", "text"&$x&"", GUICtrlRead($input[$x]))
    If $x > 9 Then
        $i +=1
        IniWrite("saved.ini", "CtrlNumpad", "text"&$i&"", GUICtrlRead($input[$x]))
    EndIf
Next
EndFunc
Edited by jokke

UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.

Share this post


Link to post
Share on other sites

Hello trying to make my 314 line scrip smaller by doing it smarter.

CODE

Func _Save()

IniWrite("saved.ini", "Numpad", "text0", GUICtrlRead($input[0]))

IniWrite("saved.ini", "Numpad", "text1", GUICtrlRead($input[1]))

IniWrite("saved.ini", "Numpad", "text2", GUICtrlRead($input[2]))

IniWrite("saved.ini", "Numpad", "text3", GUICtrlRead($input[3]))

IniWrite("saved.ini", "Numpad", "text4", GUICtrlRead($input[4]))

IniWrite("saved.ini", "Numpad", "text5", GUICtrlRead($input[5]))

IniWrite("saved.ini", "Numpad", "text6", GUICtrlRead($input[6]))

IniWrite("saved.ini", "Numpad", "text7", GUICtrlRead($input[7]))

IniWrite("saved.ini", "Numpad", "text8", GUICtrlRead($input[8]))

IniWrite("saved.ini", "Numpad", "text9", GUICtrlRead($input[9]))

IniWrite("saved.ini", "CtrlNumpad", "text1", GUICtrlRead($input[10]))

IniWrite("saved.ini", "CtrlNumpad", "text2", GUICtrlRead($input[11]))

IniWrite("saved.ini", "CtrlNumpad", "text2", GUICtrlRead($input[12]))

IniWrite("saved.ini", "CtrlNumpad", "text3", GUICtrlRead($input[13]))

IniWrite("saved.ini", "CtrlNumpad", "text4", GUICtrlRead($input[14]))

IniWrite("saved.ini", "CtrlNumpad", "text5", GUICtrlRead($input[15]))

IniWrite("saved.ini", "CtrlNumpad", "text6", GUICtrlRead($input[16]))

IniWrite("saved.ini", "CtrlNumpad", "text7", GUICtrlRead($input[17]))

IniWrite("saved.ini", "CtrlNumpad", "text8", GUICtrlRead($input[18]))

IniWrite("saved.ini", "CtrlNumpad", "text9", GUICtrlRead($input[19]))

EndFunc

Func _Load()

GUICtrlSetData($input[0], IniRead("saved.ini", "Numpad", "text0", " "))

GUICtrlSetData($input[1], IniRead("saved.ini", "Numpad", "text1", " "))

GUICtrlSetData($input[2], IniRead("saved.ini", "Numpad", "text2", " "))

GUICtrlSetData($input[3], IniRead("saved.ini", "Numpad", "text3", " "))

GUICtrlSetData($input[4], IniRead("saved.ini", "Numpad", "text4", " "))

GUICtrlSetData($input[5], IniRead("saved.ini", "Numpad", "text5", " "))

GUICtrlSetData($input[6], IniRead("saved.ini", "Numpad", "text6", " "))

GUICtrlSetData($input[7], IniRead("saved.ini", "Numpad", "text7", " "))

GUICtrlSetData($input[8], IniRead("saved.ini", "Numpad", "text8", " "))

GUICtrlSetData($input[9], IniRead("saved.ini", "Numpad", "text9", " "))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Alt;;;;;;;;;;;;;;;;;;;;;;;;;;;;

GUICtrlSetData($input[10], IniRead("saved.ini", "CtrlNumpad", "text0", " "))

GUICtrlSetData($input[11], IniRead("saved.ini", "CtrlNumpad", "text1", " "))

GUICtrlSetData($input[12], IniRead("saved.ini", "CtrlNumpad", "text2", " "))

GUICtrlSetData($input[13], IniRead("saved.ini", "CtrlNumpad", "text3", " "))

GUICtrlSetData($input[14], IniRead("saved.ini", "CtrlNumpad", "text4", " "))

GUICtrlSetData($input[15], IniRead("saved.ini", "CtrlNumpad", "text5", " "))

GUICtrlSetData($input[16], IniRead("saved.ini", "CtrlNumpad", "text6", " "))

GUICtrlSetData($input[17], IniRead("saved.ini", "CtrlNumpad", "text7", " "))

GUICtrlSetData($input[18], IniRead("saved.ini", "CtrlNumpad", "text8", " "))

GUICtrlSetData($input[19], IniRead("saved.ini", "CtrlNumpad", "text9", " "))

EndFunc

To

CODE

Func _Save()

For $i = 0 To 9

IniWrite("saved.ini", "Numpad", "text"[$i]"", GUICtrlRead($input[$i]))

Next

For $i = 10 To 19

For $si = 1 To 9

IniWrite("saved.ini", "CtrlNumpad", "text"[$si]"", GUICtrlRead($input[$i]))

Next

Next

EndFunc

Func _Load()

For $i = 0 To 9

GUICtrlSetData($input[$i], IniRead("saved.ini", "Numpad", "text"[$i]"", " "))

Next

For $i = 10 To 19

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Alt;;;;;;;;;;;;;;;;;;;;;;;;;;;;

GUICtrlSetData($input[$i], IniRead("saved.ini", "CtrlNumpad", "text"[$i]"", " "))

Next

EndFunc

But i dont know how to do it right.

In the manual i read ....

A For loop will execute zero times if:

start > stop and step > 0, or

start < stop and step is negative

This means work around text0 o assign or start lopping from 1 ... and it will work i guess !

For $i = 1 to 5 
    MsgBox(0, "Count down!", $i)
Next
MsgBox(0,"", "Blast Off!")

Share this post


Link to post
Share on other sites

I'm not sure what you are getting at. This is perfectly valid:

For $i = 0 To 9
     ; ...
Next

For $i = 10 To 19
     For $si = 1 To 9
          ; ...
     Next
NextoÝ÷ Ù8^¢yr¦ºé°jȧrëyËn±êjºÚÊ·z·§qì!zv©¥éÝx²Úâ²)ízw^u«­¢+Ù%¹¥]É¥Ñ ÅÕ½ÐíÍÙ¹¥¹¤ÅÕ½Ðì°ÅÕ½Ðí9ÕµÁÅÕ½Ðì°ÅÕ½ÐíÑáÐÅÕ½ÐìµÀìÀÌØí¤°U%
ÑɱI ÀÌØí¥¹ÁÕÑlÀÌØí¥t¤¤oÝ÷ Ù:¢ºÞrܨº·(º{]£   ìr¸©µ«­¢+Ù½ÈÀÌØí¤ôÔѼÀMÑÀ´Ä(5Í ½à À°ÅÕ½Ðí
½Õ¹Ð½Ý¸ÌÌìÅÕ½Ðì°ÀÌØí¤°Ä¤)9áÐ)5Í  ½à À°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½Ðí   ±ÍÐ=ÌÌìÅÕ½Ðì¤

:)


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

#5 ·  Posted (edited)

Forgot something within my code inn last reply.

Func _Save()
Dim $i = 0
For $x = 0 To 19
    If $x > 9 Then
        $i +=1
        IniWrite("saved.ini", "CtrlNumpad", "text"&$i&"", GUICtrlRead($input[$x]))
    else
        IniWrite("saved.ini", "Numpad", "text"&$x&"", GUICtrlRead($input[$x]))
    EndIf
Next
EndFunc

that should now work.

Edited by jokke

UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Couple of mistakes:

For $i = 0 To 9 
IniWrite("saved.ini", "Numpad", "text"[$i]"", GUICtrlRead($input[$i]))
NextoÝ÷ ÚwvËhmç!jxvÚºÚ"µÍÜ   ÌÍÚHHÈBB[UÜ]J  ][ÝÜØ]Y[I][ÝË  ][ÝÓ[Y    ][ÝË  ][ÝÝ^ ][ÝÉ[ÉÌÍÚKÕRPÝXY
    ÌÍÚ[]ÉÌÍÚWJJB^

and make this modification for each For-Next loop.

Your mistake is to try to use arrays ("text"[$i]"" - and the synthax is wrong also) when your first script shows "text01"

EDIT: oops - my post was meant to show 12 hours ago - sorry.

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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