Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3323242
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:16:42+00:00 2026-05-17T23:16:42+00:00

Hey guys, just another little problem here! Trying to write a quiz for a

  • 0

Hey guys, just another little problem here! Trying to write a quiz for a college portfolio and having trouble with writing to a .txt textfile. On one form(form4.vb), I have a listbox that picks up the information held within a notepad textfile called “usernames” which contains names of quiz users. When written in manually to this textfile, my listbox picks it up fine, however, on a different form(form3.vb), I have a textbox where a user inputs their name, this is supposed to go to the “usernames.txt” textfile to be picked up by the listbox on the other form but instead, it does not write anything at all and if there is already text on this textfile, it wipes it all out.
I also have to use the application.startup path instead of the usual C:\my documentents\ etc so i would have to begin with something like this: (Note: code is a little mixed up due to messing around with different variations but this is just a example)

    'Try
    '    Dim appPath As String
    '    Dim fileName As String

    '    appPath = Application.StartupPath
    '    fileName = appPath & "\usernames.txt"
    '    sWriter = New System.IO.StreamWriter(fileName)

    '    sWriter.Close()
    '    MessageBox.Show("Writing file to disk")

    'Catch ex As Exception
    '    MessageBox.Show("File Access Error", "Error")

    'End Try
    'MessageBox.Show("Program terminating")

    'Application.Exit()

Hope someone can help! =)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:16:43+00:00Added an answer on May 17, 2026 at 11:16 pm

    You want something more like this:

    Dim appPath As String = Application.StartupPath
    Dim fileName As String = IO.Path.Combine(appPath, "usernames.txt")
    
    Try
        IO.File.AppendAllText(fileName, TextBox1.Text & Environment.NewLine)
    Catch ex As Exception
        MessageBox.Show("File Access Error", "Error")
    End Try
    MessageBox.Show("Program terminating")
    
    Environment.Exit()
    

    Some things worth noting in this code:

    • Path.Combine() as the correct way to add the separator character
    • File.AppendAllText() is much easier for simple things than messing with streamreader/writer. Pair it with File.ReadAllText() or File.ReadAllLines() in the other direction.
    • Environment.Exit() vs Application.Exit()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey guys, just having a bit of difficulty with a query, i'm trying to
Hey guys I am having a lot of trouble trying to understand this and
Hey guys I can't seem to get the syntax here right, I'm just trying
Hey guys, I am just trying to pull all the records from my database
Hey guys, I'm working on a status-Updater. It works, there is just one problem,
hey guys having this really simple problem but cant seem to figure out have
Hey guys (and gals) I'm having a problem using Assembly GetExportedTypes() in .NET 4.0.
Hey guys, I have another really annoying problem in IE. I am using a
hey guys I just started trying to convert my query structure to PDO and
Hey guys I just noticed that my join statement here SELECT * FROM reports

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.