[AccessD] Using FreeFile

Stuart McLachlan stuart at lexacorp.com.pg
Mon Oct 17 17:04:48 CDT 2022


"#" in front of a file number has been present in many dialects of BASIC for many, many 
years. It is optional in SOME situations but not in others, so it's best to always use it

Consider:
LOCAL f AS LONG
f = FREEFILE
OPEN "test.txt" FOR OUTPUT AS  f  'OK
PRINT f, "test"   ' Not OK.
CLOSE (1)  'OK    

Assume freefile returned 2. Is that PRINT instruction supposed to mean output "2 test" to 
the console or write "test" to the file?   A compiler should choke on that line.

This is clear and unabiguous:
LOCAL f AS LONG
f = FREEFILE
OPEN "test.txt" FOR OUTPUT AS #f
PRINT #f, "test"
CLOSE (#1)        



On 17 Oct 2022 at 16:46, Arthur Fuller wrote:

> This is the puzzling line, which occurs inside a For loop where
> MyIndex is the counter. What I don't understand is the "#" sign in
> front of FileNumber. What does it signify?
> 
>         Open "TEST" & MyIndex For Output As #FileNumber    ' Create
>         file
> name.
> 
> On Mon, Oct 17, 2022 at 3:36 PM Arthur Fuller
> <fuller.artful at gmail.com> wrote:
> 
> > I'm still trying to get my head around using FreeFile. The basics
> > are simple enough: 1. call freefile, get an available filename 2.
> > open said file 3. write stuff to it 4. close said file
> >
> > In the demo I'm looking at (from MS Learn), it's all self-contained
> > in one sub. A couple of things puzzle me. First is step 3, Write.
> > Having performed steps 1 and 2, if I now move into another function,
> > is the opened file still available to write to? If I call another
> > function, and then return to the original file (which created and
> > opened the freefile), and then close the file, will that work?
> >
> > --
> > Arthur
> >
> >
> 
> -- 
> Arthur
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 




More information about the AccessD mailing list