IonicWind Software

IWBasic => Console Corner => Topic started by: dippy46 on December 22, 2006, 03:06:34 PM

Title: Newbie Question
Post by: dippy46 on December 22, 2006, 03:06:34 PM
openconsole
DEF hFILE01 AS BFILE
uint bcount
OPENFILE(hFILE01,"sample.txt","R")
bcount=len(hfile01)
' def bigstring[2000] as istring ' works OK.
def bigstring[bcount] as istring
' line above throws an error
' (7) duplicate definition of variable or label - istring
' can't see why ???

DO
'.......
'.......
UNTIL EOF(hFILE01)

DO:UNTIL INKEY$ <> ""
closefile hFILE01
closeconsole
end
Title: Re: Newbie Question
Post by: Bruce Peaslee on December 22, 2006, 03:59:20 PM
When the program is compiled, the time when the array is created, bcount has no value. You must use a literal or a constant. Arrays cannot be dimensioned at run time.
Title: Re: Newbie Question
Post by: dippy46 on December 22, 2006, 04:32:01 PM
@Peaslee,

Thankyou for your quick reply, I fully understand what you have said. Can you suggest a method therefore that can pass the bcount to the string, or do I need to be looking at the NEW directive or something.

Regards

Dave.
Title: Re: Newbie Question
Post by: Ionic Wind Support Team on December 22, 2006, 05:26:26 PM
Use NEW.

pointer pBigString
pBigString = NEW(CHAR, bcount)
#<string>pBigString = "whatever"

'when done with the big string just delete it
DELETE pBigString

Paul.
Title: Re: Newbie Question
Post by: dippy46 on December 23, 2006, 03:37:46 AM
@paul

Thanks very much, Peaslee obviously pushed my thinking in the right direction (for a change)ÂÃ,  ;D

Regards

Dave