How to create text file with VB?

what are command in vb that use for create text file?
VB_SoftManAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

supunrCommented:

Dim FileNum as Long
Dim FileName as String
 
FileName = "C:\Test.txt"
FileNum = FreeFile

' Create and open file
Open FileName For Output as #FileNum

'Print to file
Print #FileNum, "Hello World!"

' close the file
Close #FileNum

' Good Luck!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VB_SoftManAuthor Commented:
that' s helpfull. thank you. please explain me more, what each variable is. I know only FileName, but i don' t know that FileNum, FreeFilem, #FileNum used for what. thank you very much, supunr
0
supunrCommented:
Dim FileNum as Long ' this number uniquely identify the open file
Dim FileName as String ' name of the file including the full path

FileName = "C:\Test.txt" ' just hard coded the filename, you can either pass this to the function or ask use to input using common dialog control
FileNum = FreeFile ' FreeFile command automatically finds the next aviable number to uniquly identify the open file

' Create and open file
' Option output create the file always.
' if the file exist, it overwrite the existing file.
' other options are Input and Append
Open FileName For Output as #FileNum

'Print to file
Print #FileNum, "Hello World!"

' close the file
Close #FileNum
0
mr_visibleCommented:
Eh, I'm bored so I'll explian each variable for supunr....

the program could alternatevly be written like this:

' Create and open file
Open "C:\Test.text" For Output as #1

'Print to file
Print #1, "Hello World!"

' close the file
Close #1

The "1" is any number (1-255) that you allocate a file in VB. So once you allocate the file to a number, you can use that number to read (input #1, myVariable) or write (print #1, "Hello World!") to the file.

So that you don't have to choose a number for each file you open, VB has a "FreeFile" function which allocates this number for you (any file number which is not being used). Using the freeFile function is a better way of doing it....



0
mr_visibleCommented:
Sorry supunr, I wrote my comment a little slow (you got ther first) :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.