In Visual Basic 6 with little effort you can save your data to
a .TXT FILE
The following is the syntax that is used to create and export
data to a .txt File
Open "FILE LOCATION" for Output as #1
Print #1,text
close #1
This is the general syntax for opening and printing text to
text file
LET US NOW USE A BUTTON THAT PRINTS THE DATA
TO A TEXT FILE ON BUTTON CLICK
NOTE - WE ALSO CAN PASS THE FILENAME TO TEXTBOX
Now, in the button_Click event write the following code
Open "C:\textFile.txt" For Output As #1
Print #1, Text1.Text
Close #1
MsgBox "Your File Has Been Saved"
So, your file has been saved
Now, lets expand it a little More.
We are going to change the file name at run time
For this we need to declare a String( That stores filename" and a TextBox
Your Layout Goes like this...
Declare a String
dim filename as String
Next, assign the filename as,
filename=text1.text
Finally, replace the value of directory in the open command
Open "C:\" + filename + ".txt" For Output As #2
Print #2, Text1.Text
Close #2
MsgBox "FILE " + filename + ".txt IS SUCCESSFULLY CREATED AT C:\ " + filename + ".txt"
Hence the final code will be...
SO, IF YOU HAVE ANY DOUBTS FEEL FREE TO CLEAR OUT YOUR DOUBTS IN COMMENT
a .TXT FILE
The following is the syntax that is used to create and export
data to a .txt File
Open "FILE LOCATION" for Output as #1
Print #1,text
close #1
This is the general syntax for opening and printing text to
text file
LET US NOW USE A BUTTON THAT PRINTS THE DATA
TO A TEXT FILE ON BUTTON CLICK
NOTE - WE ALSO CAN PASS THE FILENAME TO TEXTBOX
Now, in the button_Click event write the following code
Open "C:\textFile.txt" For Output As #1
Print #1, Text1.Text
Close #1
MsgBox "Your File Has Been Saved"
So, your file has been saved
Now, lets expand it a little More.
We are going to change the file name at run time
For this we need to declare a String( That stores filename" and a TextBox
Your Layout Goes like this...
Declare a String
dim filename as String
Next, assign the filename as,
filename=text1.text
Finally, replace the value of directory in the open command
Open "C:\" + filename + ".txt" For Output As #2
Print #2, Text1.Text
Close #2
MsgBox "FILE " + filename + ".txt IS SUCCESSFULLY CREATED AT C:\ " + filename + ".txt"
Hence the final code will be...
No comments:
Post a Comment