Liberty BASIC Community Forum
« How to create a file from string value ? »

Welcome Guest. Please Login or Register.
Nov 17th, 2017, 10:36pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: How to create a file from string value ?  (Read 304 times)
Zabo
Full Member
ImageImageImage


member is offline

Avatar

Yes. It work's. ha


PM

Gender: Male
Posts: 125
xx How to create a file from string value ?
« Thread started on: May 29th, 2017, 06:01am »

Code:
'create a sample file
open "test.txt" for output as #1
print #1, "123 Sesame Street, New York, NY"
close #1

 


That is normal.

If i have a variable filename$ = "newfile"

How to create a file from that variable ?

Code:
filename$ = "newfile"
open filename$.txt for output as #1
print #1, "123 Sesame Street, New York, NY"
close #1

 



Code:

input "Gimme filename" ; A$      'user input is NAME1
A$ =                 ' here should be   "NAME1.txt"
OPEN A$ for OUTPUT as #1

 



Yeah. Still need to make the A$ name called NAME1.txt
anyway.
The fileextension is needed to create it.

otherwise a plain file is created. no extension


I don't know how.
« Last Edit: May 29th, 2017, 06:16am by Zabo » User IP Logged

tenochtitlanuk
Board Moderator

member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1169
xx Re: How to create a file from string value ?
« Reply #1 on: May 29th, 2017, 09:51am »

Try..
Code:
input "Gimme filename "; filename$      'user input is NAME1

open filename$ +".txt" for output as #1
    #1 "123 Sesame Street, New York, NY"
close #1

print "Done. Saved as "; filename$ +".txt"

end
 

See how to join together ( 'concatenate' the strings? And '#1' is shorthand for 'print #1,'.
User IP Logged

G. Rahman
Guru
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1146
xx Re: How to create a file from string value ?
« Reply #2 on: May 29th, 2017, 10:35am »




and first you have to test if the User already placed .txt at the end .... smiley


Gordon

p.s.
Moderator ..... this item should be in the Novice?
So shall I delete my response?
« Last Edit: May 29th, 2017, 11:09am by G. Rahman » User IP Logged

Gordon Rahman

http://www.libertybasic.nl
Zabo
Full Member
ImageImageImage


member is offline

Avatar

Yes. It work's. ha


PM

Gender: Male
Posts: 125
xx Re: How to create a file from string value ?
« Reply #3 on: May 29th, 2017, 11:07am »

The user sees a textbox only.

grin


for a = 1 to 100
print "hi"
print "emergency exit in peking"
a = a -1
next
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls