Qbasicnews.com

Full Version: saving files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
how do i take user input and save a file as that? just wondering
you mean save the file with the file name being the inputed text? or with the data inside
save the file with the inputted text as the filename
OPEN can take a string variable as the filename, like so:
Code:
OPEN f$ FOR OUTPUT AS #1
Quote:save the file with the inputted text as the filename

Code:
INPUT a$
OPEN a$ FOR OUTPUT AS #1


tha opens the file wiith the inputed file name and if it doesn't exist then it makes one
thanks but thats not the exact answer i was looking for
here is an example

input a$
open "C:\a$.dat" for input as #1

i am trying to write a file to a specific location with the filename as the inputted text.

do you kind of see where i am going with this?
thanks
It's basicly there. If you want to add the path and file extension, you need to do it a little differently
Code:
INPUT,"Enter the name of the file you want to open", FileName$

FileName$ = "C:\"+FileName$+".dat"
Open FileName$ for input as #1

'The two lines above could be combined: Open "C:\"+FileName$+".dat" for input as #1

        'code
        'code
        'code

Close #1
In either case, what happens if the user includes a path or extension in the file name? Is there something you could do to prevent problems?
woah. that's cool, didn't know you could do that. spiffy. thanks.
Code:
ON ERROR GOSUB carryon
IF MID$(filename$, LEN(filename$) - 4, 1) = "." THEN ' .xxx file xtn
  filename$ = LEFT$(filename$, LEN(filename$) - 4)
END IF

carryon:
' Open file
RETURN

I think that'll work, but I don't know all the rules around GOSUB... will that code, without an error, move into the carryon sub?
thanks, i think i got it now
Pages: 1 2