Sign in to follow this  
Followers 0
NELyon

Array question

6 posts in this topic

Is it possible to create an array when you don't know how much data is in the array? I am creating an array with a LLLLOOOONNNNGGG list of things, and i don't know how much there is...

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Is it possible to create an array when you don't know how much data is in the array? I am creating an array with a LLLLOOOONNNNGGG list of things, and i don't know how much there is...

I believe you can accomplish this with _ArrayAdd, but I've never used it personally. You could also just make the array a lot bigger than you would possibly need, then resize it after it's as full as it's going to get, I've done that before.

Nomad :D

Edit: I've never used _ArrayAdd because the only situations like this I've encountered were already eating up a lot of time, so I didn't want to eat up more time by calling a function inside of the loop. It was faster to just make the array huge, like $Array[1000000], and use a variable in the loop which counted each time it looped, that way I could instantly determine the last index of the array which was written to, and make another loop based on that to transfer the array data to a new array which was exactly the right size. I hope that made sense. :wacko:

Edited by Nomad

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Is it possible to create an array when you don't know how much data is in the array? I am creating an array with a LLLLOOOONNNNGGG list of things, and i don't know how much there is...

I use _ArrayAdd() a lot, and that is just a UDF implementation of ReDim. For convienence and convention sake, keep the first index ($Array[0]) for the count. Mine generally look like this:

#include <array.au3>

Global $aAnimals[1] = [0]
While 1
     $NewAnimal = InputBox($aAnimals[0] & " Animals so far...", "Enter a new animal: ")
     If @error Then ExitLoop
     _ArrayAdd($aAnimals, $NewAnimal)
     $aAnimals = Ubound($aAnimals) - 1
Wend
_ArrayDisplay($aAnimals, "Your list of " & $aAnimals[0] & " animals:")oÝ÷ ØíêÞƧyçm¢Ë^¦Øk¢è!¶®¶²Ê¬¶)ev÷öÙÞyÛhz0jvíg¡£ h­Æ®¶­sb6æ6ÇVFRfÇC¶'&æS2fwC° ¤vÆö&Âb33c¶æÖÇ5³ÒҳХvÆR¢b33c´æWtæÖÂÒçWD&÷b33c¶æÖÇ5³ÒfײgV÷C²æÖÇ26òf"âââgV÷C²ÂgV÷C´VçFW"æWræÖâgV÷C²¢bW'&÷"FVâWDÆö÷¢ô'&FBb33c¶æÖÇ2Âb33c´æWtæÖ¢b33c¶æÖÇ5³ÒÒV&÷VæBb33c¶æÖÇ2Ò¥vVæ@¤f÷"b33c¶ÒFòb33c¶æÖÇ5³Ð¢×6t&÷cBÂgV÷C´æÖÂÆ7Fæw2gV÷C²ÂgV÷C´æÖÂgV÷C²fײb33c¶fײgV÷C²÷WBöbgV÷C²fײb33c¶æÖÇ5³ÒfײgV÷C²3¢gV÷C²fײb33c¶æÖÇ5²b33c¶ÒÂ"¤æW

:D

Edit: Tweaked a typo per AlanR, below...

Edited by PsaltyDS

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)

Just trawling through posts here, trying to pick up some tips. Shouldn't the line:

$aAnimals = Ubound($aAnimals) - 1
read as:
$aAnimals[0]= Ubound($aAnimals) - 1
?

Alan

Edited by AlanR

Share this post


Link to post
Share on other sites

Just trawling through posts here, trying to pick up some tips. Shouldn't the line:

$aAnimals = Ubound($aAnimals) - 1
read as:
$aAnimals[0]= Ubound($aAnimals) - 1
?

Alan

yep

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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