Ad
Need Helping In Writing Text Files In VB
I am trying to write code to write text files in VB. So far, I have this and Visual Studio is coming up with some errors. I have 2 errors on my code and I have an "Else" must be proceeding by a matching "if" and a "end if" must be proceeding matching "if" error.
Private Sub btnload_Click(sender As System.Object, e As System.EventArgs) Handles btnload.Click
Dim FILE_NAME As String = "test.txt"
If System.IO.File.Exists(FILE_NAME) = True Then Dim objReader As New System.IO.StreamReader(FILE_NAME)
txtload.Text = objReader.ReadToEnd.objReader.Close()
objReader.Close()
Else
MsgBox("File Does Not Exist")
End If
End Sub
Ad
Answer
A couple things:
- your file needs a system path
- if you just want to write to a text file, add text to it -you don't need to read it in
Try writing directly to the file:
My.Computer.FileSystem.WriteAllText("C:\TestFolder1\test.txt",
"This is new text to be added.",True)
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → I can't do a foreign key, constraint error
- → Setting a default value on settings form return null in Octobercms
- → Eloquent Multitable query
- → "Laravel 5.1" add user and project with userId
- → Image does not go in database with file name only tmp name saved?
- → Database backup with custom code in laravel 5 and get the data upto 10 rows from per table in database
- → Trait 'IlluminateFoundationBusDispatchesJobs' not found
- → Setting the maxlength of text in an element that is displayed
- → laravel check between 2 integer from database
- → how to retrieve image from database in laravel 5.1?
- → relationship for database Column type object
- → Carousel in Laravel 4 does not show as expected
Ad