Results 1 to 6 of 6

Thread: How to Auto Generate Text File in vb.net

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    90

    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:


    Name:  asa1.PNG
Views: 676
Size:  53.7 KB

    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.

    Name:  asa.PNG
Views: 637
Size:  66.6 KB


    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.

  2. #2
    Member
    Join Date
    Jun 2018
    Posts
    46

    Re: How to Auto Generate Text File in vb.net

    Option A:

    vb.net Code:
    1. My.Computer.FileSystem.WriteAllText(txtPathLogFile.Text,"SerialNo|DateTime|Result|StationName|Model|",True)

    Option B:

    vb.net Code:
    1. Dim file As System.IO.StreamWriter
    2. file = My.Computer.FileSystem.OpenTextFileWriter(txtPathLogFile.Text, True)
    3. file.WriteLine("SerialNo|DateTime|Result|StationName|Model|")
    4. 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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    90

    Re: How to Auto Generate Text File in vb.net

    hi Sir i am getting error as below.
    Name:  asa2.PNG
Views: 391
Size:  123.6 KB

    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.

  4. #4
    Member
    Join Date
    Jun 2018
    Posts
    46

    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

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,399

    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

  6. #6
    Frenzied Member
    Join Date
    Oct 2012
    Location
    Tampa, FL
    Posts
    1,187

    Re: How to Auto Generate Text File in vb.net

    Quote Originally Posted by BONITO View Post
    hi Sir i am getting error as below.
    Name:  asa2.PNG
Views: 391
Size:  123.6 KB

    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
  •  



Click Here to Expand Forum to Full Width