[futurebasic] Re: [FB] File saving problem

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

From: AlStaff@...
Date: Mon, 4 Jun 2001 06:49:30 EDT
>Can someone explain why this file saving function adds a few garbage 
>characters on the front and back of the text document? I thought that 
>is why you use WRITE FILE instead of WRITE FIELD, to avoid picking up 
>the 4-byte length indicator.

The handle still contains the 2 bytes from GET FIELD so it's going to be 
written to the file. Just skip 2 bytes when you write to the file by using a 
WRITE FILE line like this:
WRITE FILE #2, [zTextH] + 2, bytes - 2

Here's the full code:

LOCAL FN saveTable
DIM @fileNameStr AS STR255
DIM @volRefnum   AS LONG
DIM @zTextH      AS HANDLE
DIM bytes        AS LONG

GET FIELD zTextH, 100

LONG IF zTextH
DEF OPEN "TEXTttxt"
fileNameStr = FILES$(_fSave,"Save file as...","Untitled",volRefNum)
LONG IF fileNameStr <> 0
OPEN "R",#2, fileNameStr,,volRefnum
bytes = FN GETHANDLESIZE( zTextH )
WRITE FILE #2, [zTextH] + 2, bytes - 2
DEF DISPOSEH( zTextH )
CLOSE #2
END IF
END IF
END FN


Al Staffieri Jr.

AlStaff@...
http://members.aol.com/AlStaff/index.html