Visual basic app to create a text file

Status
Not open for further replies.

p dommi

Ars Legatus Legionis
12,467
The app idea is simple, but Im a bit lost as to one part.
I want to have option boxes that signify certain actions. Sleeping, eating drinking... I want to be able to click an option box then the app will create a text file or edit it with waht I am doing. Example: click the drinking option box - text file states "I am away at the moment drinking".
How do I create a text file from a visual basic app?
Can anyone help with this?

ng
 

wb

Ars Legatus Legionis
25,208
Subscriptor
There are two ways that I know of to create text from your VB app. Well, actually 3 I guess.

1. Use the old-style VB file statements to create and write.
e.g.
code:<HR>
Code:
dim myText as String
dim myTextFile as String
myText = "I am a text file"
myTextFile = "C:\StupidFile.txt"
open myTextFile For Output As #1
print #1, myText
close #1


2. Use the new-fangled [sic] FileSystemObject methods and objects:
[NOTE: use Tools->References to add "Microsoft Scripting Runtime" type libraries]

code:<HR>
Code:
   Dim myText As String
   Dim myTextFile As String
   Dim fso As FileSystemObject
   Dim ts As TextStream<P>   myText = "I am a text file"
   myTextFile = "C:\StupidFile.txt"
   
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set ts = fso.OpenTextFile(myTextFile, ForWriting, True)
   ts.WriteLine myText
   ts.Close

3. Create a "console" VB application (make it not have any forms, and use sub main() as the entry point), and redirect the stdout stream to a file. Use the plain 'ol print statement to print text to stdout.
 
Status
Not open for further replies.