-
Jun 22nd, 2018, 08:13 AM
#1
Thread Starter
Lively Member
How to Auto Generate Text File in vb.net
Hi Everyone,
I am making a program that will auto generate text file in vb.net 2010 , the data is from text box see image below:
every time user click Save button it will also generate 1 text file,data are : SerialNo|DateTime|Result|StationName|Model| ,
1 data = 1 text file. also the file name must be the serial number.
Please help me what function to use so that i can throw the data to the text file.
I already know how to select the path where to save the text file.
Code:
If FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
txtPathLogFile.Text = FolderBrowserDialog1.SelectedPath
End If
thank you in advance.
-
Jun 22nd, 2018, 08:26 AM
#2
Lively Member
Re: How to Auto Generate Text File in vb.net
Option A:
vb.net Code:
My.Computer.FileSystem.WriteAllText(txtPathLogFile.Text,"SerialNo|DateTime|Result|StationName|Model|",True)
Option B:
vb.net Code:
Dim file As System.IO.StreamWriter file = My.Computer.FileSystem.OpenTextFileWriter(txtPathLogFile.Text, True) file.WriteLine("SerialNo|DateTime|Result|StationName|Model|") file.Close()
Note: Option B allows much more than the first one, here's stuff to read.
https://docs.microsoft.com/en-us/dot...es/file-access
Good luck,
KBConsole
-
Jun 22nd, 2018, 08:47 AM
#3
Thread Starter
Lively Member
Re: How to Auto Generate Text File in vb.net
hi Sir i am getting error as below.
and what i want to write in text file is the data that the user will input in the text box,
please advice thank you.
-
Jun 22nd, 2018, 08:53 AM
#4
Lively Member
Re: How to Auto Generate Text File in vb.net
Says you don't have the rights to write to the file.
Either run it in admin or make sure to have writting rights for the file you try to write in.
As for the content to write, replace
"SerialNo|DateTime|Result|StationName|Model|"
With
YourTextBoxWithData.text
Hope this helps you out,
KBConsole
-
Jun 26th, 2018, 11:17 PM
#5
Re: How to Auto Generate Text File in vb.net
For the filename, you wouldn't use txtPathLogFile.Text
A proper filename would be txtPathLogFile.Text & "\your_text_filename.txt", where txtPathLogFile holds the correct path, and your_text_filename.txt is a unique txt filename
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 1st, 2018, 05:20 PM
#6
Re: How to Auto Generate Text File in vb.net
Originally Posted by BONITO
hi Sir i am getting error as below.
and what i want to write in text file is the data that the user will input in the text box,
please advice thank you.
The error is in your screenshot - your file name is not a valid file name. Look at it, it says "C:\Users\<<USER\Documents\p' which would be a directory.. Instead, it should be 'C:\Users\<<USER\Documents\p.txt'
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|