Jump to content

REDIM help


BALA
 Share

Recommended Posts

I want to resize my array after every loop:

Dim $x[1] ; declare array

For $y = 1 to 5 ; 5 loops
    $x[$y] = $y ; sets each element the value of $y
    $a = $y + 1 ; increments $a
    REDIM $x[$a] ; re-dimensions array
Next

MSGBOX(0, "test", $x[5]) ; want this to display 5

I want the window to display 5, but the script just gives me an error. I'm pretty sure I am doing something wrong with REDIM command. How would I use the REDIM command in such a way; the help file was a bit complex?

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com
Link to comment
Share on other sites

  • Moderators

Go down your math on each line, and think about this logically, you start out with a Dim [1], but you start you For/Next loop at 1 :whistle:

Dim $x[2] ; declare array
Dim $a = 2

For $y = 1 to 5 ; 5 loops
    $x[$y] = $y ; sets each element the value of $y
    $a += 1 ; increments $a
    REDIM $x[$a] ; re-dimensions array
Next

MSGBOX(0, "test", $x[5]) ; want this to display 5

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

It works! :whistle:

But why wouldn't starting it with Dim [1] work; wouldn't $x[$y] = $x[1] thus allowing the element to be set?

Edited by BALA
[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com
Link to comment
Share on other sites

  • Moderators

It works! :whistle:

But why wouldn't starting it with Dim [1] work; wouldn't $x[$y] = $x[1] thus allowing the element to be set?

Do you understand arrays? ... if so, Dim $array[1] = only 1 element [0] is the only element available to write to, you started at 1, and tried to declare it's value $array[$y] = $y when it didn't have enough elements to even write there, thus you get an error, not enough subscripts.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Ah I get it now; and no I didn't know how to use arrays. I thought when you declare it $x[1] it's like saying the elements are $x[0], $x[1], similar: $x[2] is like saying the elements are $x[0], $x[1], $x[2]. The truth is I have problems with arrays in just about every language I have tried, which is odd at some level considering how simple they are in some respect. Thanks for the help.

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com
Link to comment
Share on other sites

Go down your math on each line, and think about this logically, you start out with a Dim [1], but you start you For/Next loop at 1 :whistle:

Dim $x[2] ; declare array
Dim $a = 2

For $y = 1 to 5 ; 5 loops
    $x[$y] = $y ; sets each element the value of $y
    $a += 1 ; increments $a
    REDIM $x[$a] ; re-dimensions array
Next

MSGBOX(0, "test", $x[5]) ; want this to display 5
How would you redim if you wanted to use a variable with the FileSelectFolder("Choose a folder.", "") option? So if I were to chose a folder and then go back and chose another one it would add to what is already stored
EndFuncAutoIt is the shiznit. I love it.
Link to comment
Share on other sites

  • Moderators

How would you redim if you wanted to use a variable with the FileSelectFolder("Choose a folder.", "") option? So if I were to chose a folder and then go back and chose another one it would add to what is already stored

Good question, if you are using the Array option of FSF of that... you'd do something like

pseudo:

Dim $aOriginal[3] = ['some value', 'some other', 'and again']
Dim $aFSF = FileSelectFolder(etc...)

ReDim $aOrginal[(Ubound($aOriginal) + Ubound($aFSF)) - 1];I believe it's -1

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Good question, if you are using the Array option of FSF of that... you'd do something like

pseudo:

Dim $aOriginal[3] = ['some value', 'some other', 'and again']
Dim $aFSF = FileSelectFolder(etc...)

ReDim $aOrginal[(Ubound($aOriginal) + Ubound($aFSF)) - 1];I believe it's -1
I guess I'm still not following and with arrays I run into trouble :whistle:, but If I don't have a value to set already how can I declare them in an array. More or less use the FSF so if I did a Dim $aFSF = FileSelectFolder(etc...) do I need to use an array to redim and add to it? I'm assuming so but quite unsure of the syntax. Thanks for the help.
EndFuncAutoIt is the shiznit. I love it.
Link to comment
Share on other sites

  • Moderators

I guess I'm still not following and with arrays I run into trouble :whistle:, but If I don't have a value to set already how can I declare them in an array. More or less use the FSF so if I did a Dim $aFSF = FileSelectFolder(etc...) do I need to use an array to redim and add to it? I'm assuming so but quite unsure of the syntax. Thanks for the help.

If I'm understanding your question... FileSelectFolder will return an array if they end user is allowed to pick multiple folders and does so, so the variable that would normally contain just 1 value in a regular variable, now becomes an array itself.

So...

User Picks 1 folder:

$aFSF = FileSelectFolder()
MsgBox(64, 'Info', $aFSF);will show the value...oÝ÷ ØÚ0¶®±êéÉ,Þ¶§¢wW´ß¦HVÞr±©Ú®¶²Â«{Kh½êæj|W¬¦'$yÜ"XhÛayú%uêéjØl×g­q«­¢+ØÀÌØíMô¥±M±Ñ½±È ¤)%%ÍÉÉä ÀÌØíM¤Q¡¸í1Ñ̵­ÍÕÉÑ¡äÁ¥­µ½ÉÑ¡¸½¹¥±(5Í  ½à ØаÌäí%¹¼Ìäì°ÌäíUÍÈ¡½ÍèÌäìµÀìU  ½Õ¹ ÀÌØíM¤´ÄµÀìÌä쥱̸Ìäì¤(}ÉÉå¥ÍÁ±ä ÀÌØíM°Ìäí±°¥±Ì
¡½ÍÌäì¤)±Í(5Í ½à ØаÌäí%¹¼Ìäì°Ìäí=¹±äÄ¥±¡½ÍèÌäìµÀì
I1ÀÌØíM¤)¹%

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

If I'm understanding your question... FileSelectFolder will return an array if they end user is allowed to pick multiple folders and does so, so the variable that would normally contain just 1 value in a regular variable, now becomes an array itself.

So...

User Picks 1 folder:

$aFSF = FileSelectFolder()
MsgBox(64, 'Info', $aFSF);will show the value...oÝ÷ ØÚ0¶®±êéÉ,Þ¶§¢wW´ß¦HVÞr±©Ú®¶²Â«{Kh½êæj|W¬¦'$yÜ"XhÛayú%uêéjØl×g­q«­¢+ØÀÌØíMô¥±M±Ñ½±È ¤)%%ÍÉÉä ÀÌØíM¤Q¡¸í1Ñ̵­ÍÕÉÑ¡äÁ¥­µ½ÉÑ¡¸½¹¥±(5Í  ½à ØаÌäí%¹¼Ìäì°ÌäíUÍÈ¡½ÍèÌäìµÀìU  ½Õ¹ ÀÌØíM¤´ÄµÀìÌä쥱̸Ìäì¤(}ÉÉå¥ÍÁ±ä ÀÌØíM°Ìäí±°¥±Ì
¡½ÍÌäì¤)±Í(5Í ½à ØаÌäí%¹¼Ìäì°Ìäí=¹±äÄ¥±¡½ÍèÌäìµÀì
I1ÀÌØíM¤)¹%
Now, that seems to work thanks, but the FileSelectFolder() will only let you chose one folder at a time so if I go back and select another folder it clears the variable and only displays the most recent folder I seleceted instead both. I am trying to see if I can get that to work but any more suggestions on that? Thanks
EndFuncAutoIt is the shiznit. I love it.
Link to comment
Share on other sites

  • Moderators

Now, that seems to work thanks, but the FileSelectFolder() will only let you chose one folder at a time so if I go back and select another folder it clears the variable and only displays the most recent folder I seleceted instead both. I am trying to see if I can get that to work but any more suggestions on that? Thanks

I was thinking FileOpenDialog() when I was speaking before... :whistle:

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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