Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Fri Dec 14, 2018 1:23 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Initializing Arrays
PostPosted: Mon Oct 03, 2005 2:17 pm 
Offline

Joined: Fri Sep 30, 2005 8:47 am
Posts: 100
Is there any way to initialize arrays in code

i.e. can I say something akin to

Dim TestArray(3) as integer = { 0,2,45 }

Or should I file a feature request ?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Oct 03, 2005 2:25 pm 
Offline
User avatar

Joined: Wed Sep 28, 2005 3:23 pm
Posts: 61
Location: Austin, TX
Yep, try this:

Dim TestArray() as Integer = Array( 0, 2, 45 )


HTH,
Jon

_________________
Jonathan Johnson
Alacatia Labs, Inc.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Oct 03, 2005 2:26 pm 
Offline
User avatar

Joined: Wed Sep 28, 2005 8:39 am
Posts: 9341
Location: St Augusta, MN
You can do that using the Array keyword, like this:

Dim i(-1) as Integer = Array( 1, 2, 3, 4, 5 )


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Oct 03, 2005 2:59 pm 
Offline

Joined: Fri Sep 30, 2005 8:47 am
Posts: 100
Does this internally do a "new" operation ? If so, I assume that TestArray will be destroyed once it goes out of scope or is assigned nil ? Is it then possible to redim this array ?

Also are there any limits to the array length while initializing it ? (I have a 4096 integer lookup table)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Oct 03, 2005 3:01 pm 
Offline
User avatar

Joined: Wed Sep 28, 2005 8:39 am
Posts: 9341
Location: St Augusta, MN
Arrays are not objects in the same way classes are, so you don't need to "new" them. It's more like doing a bunch of .Append calls. :-)

And AFAIK, there's no limit (aside from obvious ones like RAM) to the number of elements in an array.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Oct 03, 2005 3:43 pm 
Offline

Joined: Wed Sep 28, 2005 6:06 pm
Posts: 292
Quote:
Does this internally do a "new" operation ?

Yes, basically.

Quote:
If so, I assume that TestArray will be destroyed once it goes out of scope or is assigned nil ? Is it then possible to redim this array ?

Array data buffers are reference-counted in the same way as objects or strings. The array data will be released when the last variable referring to it goes out of scope. You can redim an array regardless of where it came from.

Quote:
Also are there any limits to the array length while initializing it ? (I have a 4096 integer lookup table)

That's... a lot. I have no idea whether it will work. Why not load the data from a file instead?

Mars Saxman
REAL Software


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Oct 03, 2005 8:26 pm 
Offline

Joined: Fri Sep 30, 2005 8:47 am
Posts: 100
Since I didnt have much time to wait for confirmation, I put the array values (from C Code) into a string and split them and stored them into an integer array.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Oct 03, 2005 9:22 pm 
Offline

Joined: Fri Sep 30, 2005 10:37 am
Posts: 12
As far as array size, one of the project I had to take over had a (35,750,70) string array! 1,800,000+ elements! It worked! Since taking over I adjust the 750 dimension dynamically, but I didn't have time to do a more thorough rebuild. It works, except for debugging, there is no way to display that big of an array (understandably).


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group