Sign in to follow this  
Followers 0
rasim

ReDim: 2 way.

9 posts in this topic

Hello! First example of array ReDim:

#include <Array.au3>

Dim $aNewArray[1]

For $i = 1 To 2
    $aNewArray[0] += 1
    ReDim $aNewArray[$aNewArray[0] + 1]
    $aNewArray[$aNewArray[0]] = $i
Next
_ArrayDisplay($aNewArray)oÝ÷ Ùj+Ê+­ç-Úw^Å©©æ®¶­sb6æ6ÇVFRfÇC´'&æS2fwC° ¤FÒb33c¶æWt'&³Ð ¤f÷"b33c¶¢ÒFò  b33c¶æWt'&µT&÷VæBb33c¶æWt'&ÒÒ³Ò &TFÒb33c¶æWt'&²T&÷VæBb33c¶æWt'&ҲРb33c¶æWt'&µT&÷VæBb33c¶æWt'&ÒÒÒb33c¶ ¤æW@ ¥ô'&F7Æb33c¶æWt'&

Not work. Where wrong?

Share this post


Link to post
Share on other sites

randallc

Thanks for help, but i should like to know why 2-nd example don`t work correct.

Share this post


Link to post
Share on other sites

#include <Array.au3>

Dim $aNewArray[1]

For $j = 1 To 2
    $aNewArray[UBound($aNewArray) - 1] += 1 ;here it $aNewArray[1] not $aNewArray[0]
    ReDim $aNewArray[(UBound($aNewArray) - 1) + 1]
    $aNewArray[UBound($aNewArray) - 1] = $j;here it $aNewArray[1] not $aNewArray[0]
Next

_ArrayDisplay($aNewArray)

Share this post


Link to post
Share on other sites

athiwatc

You are tested yourself code before posting? Your example don`t work.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

This one work, and sorry for the upper one i thongh i got it so i didn't test it

#include <Array.au3>

Dim $aNewArray[1]

For $j = 1 To 2
    ReDim $aNewArray[UBound($aNewArray) + 1]
    $aNewArray[UBound($aNewArray) - 1] = $j
Next
$aNewArray[0] = UBound($aNewArray) - 1

_ArrayDisplay($aNewArray)oÝ÷ Ù«­¢+Ø¥¹±Õ±ÐíÉÉä¹ÔÌÐì()¥´ÀÌØí9ÝÉÉålÅt()½ÈÀÌØí¨ôÄQ¼È($ÀÌØí9ÝÉÉåmU   ½Õ¹ ÀÌØí9ÝÉÉ䤴ÀÌØí©tôU  ½Õ¹ ÀÌØí9ÝÉÉä¤(%I¥´ÀÌØí9ÝÉÉåmU    ½Õ¹ ÀÌØí9ÝÉÉ䤬Åt($ÀÌØí9ÝÉÉåmU    ½Õ¹ ÀÌØí9ÝÉÉ䤴ÅtôÀÌØí¨)9áÐ(()}ÉÉå¥ÍÁ±ä ÀÌØí9ÝÉÉä¤

The problem with your is UBound($aNewArray) - 1 Doesn't always make 0

Edited by athiwatc

Share this post


Link to post
Share on other sites

athiwatc

Thanks! :D

Share this post


Link to post
Share on other sites

I know this is resolved already, but I just had to mention I don't understand why you had

(UBound($aNewArray) - 1) + 1

Considering all you do is add and subtract 1 so it's the same number.

Share this post


Link to post
Share on other sites

Lets not forget the uselessness of this piece:

$aNewArray[uBound($aNewArray) - $j] = UBound($aNewArray)

Which is the same as:

$aNewArray[0] = UBound($aNewArray)

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