mcapone888 Posted March 16, 2003 Posted March 16, 2003 Hi everyone, I am new to VB.net, and have only played around with VB6 as a hobby. I know this is not the best way to write and read from a file, but this is what I used in the past, and it worked great for me. I am trying to write some variables to a simple text file, and then be able to use load them again at a later time. In VB 6 I used: for saving (writing): Open App.Path & "\file.txt" For Output As #1 Write #1, String1, String2, Integer1 Close #1 for loading (reading): Open App.Path & "\file.txt" For Input As #1 Input #1, String1, String2, Integer1 Close #1 This wrote the three variables to a simple text file found in the same location as the startup path of the program. How can I recreate this same simple code for a VB.Net windows application? If possible, please let me know the easiest way to do this, even if it is not the correct or best method possible. Thanks!! Michael Quote
Leaders quwiltw Posted March 16, 2003 Leaders Posted March 16, 2003 Have you searched this forum for "write text file"? there are a number of good examples for this already. Quote --tim
mcapone888 Posted March 16, 2003 Author Posted March 16, 2003 (edited) Public Class frmReadWriteTest Inherits System.Windows.Forms.Form Dim Save1, Save2, Save3 As String Windows Form Designer generated code Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Save1 = txtOne.Text Save2 = txtTwo.Text Save3 = txtThree.Text FileOpen(1, "test.txt", OpenMode.Output) WriteLine(1, Save1, Save2, Save3) FileClose(1) End Sub Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click FileOpen(1, "test.txt", OpenMode.Input) Input(1, Save1) Input(1, Save2) Input(1, Save3) FileClose(1) txtFour.Text = Save1 txtFive.Text = Save2 txtSix.Text = Save3 End Sub End Class Edited March 16, 2003 by divil Quote
Leaders quwiltw Posted March 17, 2003 Leaders Posted March 17, 2003 I'm not sure what your point was behind posting your code. I asked if you'd searched the forum yet. There are a number of good examples for doing this the .NET-way posted. Quote --tim
bpayne111 Posted March 17, 2003 Posted March 17, 2003 Search MSDN for "Streams" that will show you the new cool way to write to files Quote i'm not lazy i'm just resting before i get tired.
spearchucker Posted March 20, 2003 Posted March 20, 2003 arbitrary I just wrote an arbitrary number of lines to my text file. Now, how can I read them in? I know what each line will contain, but I dont know how many lines. Is there some sort of a peek function to see if there are any more lines available to read? Quote
Leaders quwiltw Posted March 20, 2003 Leaders Posted March 20, 2003 See if this helps you get started... http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemiostreamreaderclassreadlinetopic.asp Quote --tim
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.