Restored from previous forum. Originally posted by Kale.
i just wanted to know if i could get the length so i could define 'for' loops to process data within dynamically created arrays. i.e. arrays that are created depending on the number of lines within a text file which are always different.
[snip]
Declare.l countLines(fileNumber.b, fileName.s)
Global maxDebits
maxDebits.l = countLines(#DEBIT_FILE, "debits.ini")/3
Dim debitArray.s(maxDebits,3)
If ReadFile(#DEBIT_FILE, "debits.ini")
For x=0 To maxDebits
If Eof(#DEBIT_FILE) = 0
debitArray(x,0)=ReadString()
debitArray(x,1)=ReadString()
debitArray(x,2)=ReadString()
EndIf
Next
CloseFile(#DEBIT_FILE)
EndIf
Restored from previous forum. Originally posted by PB.
> Global maxDebits
> maxDebits.l = countLines(#DEBIT_FILE, "debits.ini")/3
> Dim debitArray.s(maxDebits,3)
I still don't understand... you've got the number of elements above,
stored in the maxDebits variable, so why do you need to get the length
if you already have it? Is it because maxDebits will change the next
time you count the number of lines? If so, just dimming the array
again will auto-resize (and clear) it to that value... which is what
I think you want? Perhaps you didn't know you could re-dim an array
with a new maximum size?
Restored from previous forum. Originally posted by Kale.
oh yeah sorry that code was my little work around but i just wondered if there was a 'lazy' array length function so save a little brainpower as in python The #DEBIT_FILE is a dynamically changing file so i will have to re-dim the array. oh well, thanks anyway.
and yeah thanks Franco i tried SizeOF() but it is only for structures
BTW i am really begining to love PureBasic after recently purchasing it, I'm just adjusting to programming properly, instead of just scripting
Restored from previous forum. Originally posted by Franco.
Originally posted by Kale
oh yeah sorry that code was my little work around but i just wondered if there was a 'lazy' array length function so save a little brainpower as in python The #DEBIT_FILE is a dynamically changing file so i will have to re-dim the array. oh well, thanks anyway.
and yeah thanks Franco i tried SizeOF() but it is only for structures
BTW i am really begining to love PureBasic after recently purchasing it, I'm just adjusting to programming properly, instead of just scripting
Hi Kale, I also redim arrays, sometimes I need this without loosing the data.
What I always do is; if I have an array like:
Dim Array(34)
I use Array(1) till Array(34) for data and Array(0) is ALWAYS the holder for my Array size.
This said, I code always: