Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 have flexible 2d array, need to add element
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
r0ssar00




PostPosted: Thu Jan 26, 2006 8:09 am   Post subject: have flexible 2d array, need to add element

i need to add an element to my 2d array in my program, and it wont add
heres my code
code:

var file:int
var fileString:string
var tmpFile:flexible array 1..1, 1..1 of string
open : file, fileString, get
var i :string:= 1
loop
    exit when eof (file)
    get : file, tmpFile (1, i)
    new tmpFile, upper (tmpFile (0,1) + 1)
    i += 1
end loop

the one thing i really need to have happen is to add a new string value thingy to both dimensions
thanks
Sponsor
Sponsor
Sponsor
sponsor
MysticVegeta




PostPosted: Thu Jan 26, 2006 11:33 am   Post subject: (No subject)

You cannot add elements to a 2D flex array. How ever I think someone did it, not sure who it was but it must be somewhere around here.
r0ssar00




PostPosted: Thu Jan 26, 2006 11:37 am   Post subject: (No subject)

so, essentially, i need to have a superhuge 2d array to encompass all ill need to do, in the range of 32000, fun use of memory, sorry for the sarcasm
MysticVegeta




PostPosted: Thu Jan 26, 2006 11:44 am   Post subject: (No subject)

yes and dont forget to increment a counter variable every time you insert something into that array, cause if you are using that array and you go :

code:
for x : 1..10
put arra(x)
end for


All the 10 elements might not have been filled so it will give you an array of bounds error.
Andy




PostPosted: Thu Jan 26, 2006 12:56 pm   Post subject: (No subject)

for two d arrays, you can only change the first parameter.. ie if u have an 2x3 flexible array, you can only change the 2, not the 3
do_pete




PostPosted: Thu Jan 26, 2006 1:34 pm   Post subject: (No subject)

You can change it in Turing 4.1
Albrecd




PostPosted: Thu Jan 26, 2006 1:35 pm   Post subject: (No subject)

If you have Turing 4.1 or greater you can use a flexible multidimentional array and then use new arrayID, upperbound1, upperbound2... to resize it.
r0ssar00




PostPosted: Thu Jan 26, 2006 2:54 pm   Post subject: (No subject)

i just realized that i had been going about this all wrong, i dont need a 2d array, i just need two arrays, thanks anyway
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Thu Jan 26, 2006 4:33 pm   Post subject: (No subject)

Andy wrote:
for two d arrays, you can only change the first parameter.. ie if u have an 2x3 flexible array, you can only change the 2, not the 3


You can change the two, you just have to be quite tactful.
Cervantes, in the Flexible Arrays Tutorial wrote:


  • You can change any upper bounds from a 0 to x, or from x to 0.
  • If you change one upper bounds to a zero, you can do whatever you want with the other upper bounds.
  • In a 2D array, if you leave the second upper bounds alone, you can change the first upper bounds


You could do it by changing the first bounds to zero, then to whatever you want. Or you could do it by changing the second bounds to 0 and the first to whatever you want, then changing the second back to 3. However, storing the data in the array while you're doing all this would be an even bigger pain.
r0ssar00




PostPosted: Fri Jan 27, 2006 1:10 pm   Post subject: (No subject)

so ur saying i could do this
code:

var tmpData:flexible array 1..1, 1..1 of string
new tmpData, upper(tmpData) + 1, upper(tmpData)
new tmpData, upper(tmpData), upper(tmpData)+1


but not this

code:

var tmpData:flexible array 1..1, 1..1 of string
new tmpData, upper(tmpData) + 1, upper(tmpData) + 1


right?
Cervantes




PostPosted: Fri Jan 27, 2006 4:41 pm   Post subject: (No subject)

Almost, I think.

r0ssar00 wrote:
so ur saying i could do this
code:
...
new tmpData, upper(tmpData), upper(tmpData)+1


That line violates the rules. But if it works (in a non-4.1 version), then the rules are wrong. Did it work for you?
[Gandalf]




PostPosted: Fri Jan 27, 2006 8:12 pm   Post subject: (No subject)

Albrecd wrote:
If you have Turing 4.1 or greater you can use a flexible multidimentional array and then use new arrayID, upperbound1, upperbound2... to resize it.

Really? Shocked Dang, this is finally a useful update (either than gif support). Too bad they didn't update the help file.

Thanks for the info!
*tries it out*
r0ssar00




PostPosted: Sat Jan 28, 2006 1:56 pm   Post subject: (No subject)

it didnt work, thanks anyway
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: