[futurebasic] Re: [FB] PRINT#problem

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2002 : Group Archive : Group : All Groups

From: Alain Pastor <pixmix@...>
Date: Sun, 02 Jun 2002 23:46:11 +0200
barrie wrote:
> 
> I'm saving data to a file using PRINT#1 and reading it with INPUT#1.
> Some of the data are numbers, some are strings.
> 
> PRINT# 1, number
> PRINT# 1, String$(1)
> PRINT# 1, number2
> When read with
> INPUT# 1, number
> INPUT# 1, String$(1)
> INPUT# 1, number2
> Does not work. number reads OK but the string is empty and number2 is wrong.
> When I change it to
> PRINT# 1, number
> WRITE# 1, String$(1);50
> PRINT# 1, number2
> And read with
> INPUT# 1, number
> READ# 1, String$(1);50
> INPUT# 1, number2
> Everything works fine.
> Does anyone know why PRINT# does not work? I had no problems using PRINT#
> and INPUT# for strings on old versions of FB and ZB
> The strings are DIM'd as DYNAMIC arrays. A regular DIM does not solve the
> problem.
> Thanks

Barrie,

I'm not sure my answer will address your problem, but dynamic arrays
are special beasts (they are handles in disguise). This is probably
why there are specific FB statements for reading and writing dynamic
arrays. I don't know how FB handles dynamic arrays when an item is
used in an INPUT statement, but I would make sure first that my array
has been initialized and contains sufficient items.If that doesn't
work, I would try to lock the handle maintained for the dynamic array
before reading the items from disk, because file routines are prone to
move memory. 
However, my quick test seems to work below:

dynamic s$(_maxInt)
dim as integer n1, n2 
dim as FSSpec  f

f.name    = "test"
f.vRefNum = system(_aplVRefNum)
f.parID   = system(_aplParID)

s$(1) = "toto" : n1 = 5 : n2 = 100

open "o",1,@f
print #1, n1
print #1, s$(1)
print #1, n2
close 1

s$(1) = "" : n1 = 0 : n2 = 0

open "i",1,@f
input #1, n1
input #1, s$(1)
input #1, n2
close 1

window 1
print n1
print s$(1)
print n2

do
handleevents
until fn button



-- 
Cheers,

Alain