Audax321 Posted October 31, 2002 Posted October 31, 2002 (edited) I'm completely lost... it was so easy in VB6 to read and write files. Couldn't they just leave that functionality as it was :( All I want to do is write to settings.ini (in installation folder where my app is) to save settings. And then load the settings from settings.ini when the program runs... Also is there anyway to bring a window to the front by clicking on the notification icon...NEVER MIND THIS QUESTION.. I FIGURED IT OUT!! :) Edited October 31, 2002 by Audax321 Quote
Moderators Robby Posted November 1, 2002 Moderators Posted November 1, 2002 There are many ways to read/write files, here's one. You need one List Box on your form. Private Function GetFromFile() As Boolean Try List1.Items.Clear() 'Clear the list before we can load from the text file Dim sr As StreamReader sr = File.OpenText(Application.StartupPath & "\Test.txt") Dim strItems As String 'loop through the text file While sr.Peek <> -1 strItems = sr.ReadLine() List1.Items.Add(strItems) 'add the contents to the list box End While sr.Close() 'close the file Return True 'file was there...with no errors Catch 'ignore errors Return False 'most likely we don't have file permission (to delete) End Try End Function Private Function SaveToFile() As Boolean Try Dim bFile As String = Dir(Application.StartupPath & "\Test.txt") If bFile.Length > 0 Then 'Check if the file exists and delete it Kill(Application.StartupPath & "\Test.txt") End If 'Create the file again or for the first time Dim sb As New FileStream(Application.StartupPath & "\Test.txt", FileMode.OpenOrCreate) Dim sw As New StreamWriter(sb) Dim nCounter As Integer 'loop through the list and save one line at a time For nCounter = 0 To List1.Items.Count - 1 sw.Write(List1.Items.Item(nCounter).ToString & vbCrLf) Next sw.Close() Return True Catch 'ignore errors Return False End Try End Function Quote Visit...Bassic Software
*Gurus* divil Posted November 1, 2002 *Gurus* Posted November 1, 2002 Audax321: If they had left file i/o the same as it was in vb6, I would have personally gone and found Bill Gates and whacked him upside the head with a rusty Input statement. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Audax321 Posted November 1, 2002 Author Posted November 1, 2002 LOL... well I mean have both functionality so you could use either... the code to read/write a simple ini file is so long now... Quote
*Gurus* divil Posted November 1, 2002 *Gurus* Posted November 1, 2002 I dunno, there's one line to open the file, one line to read a line from it, and one line to close it... not much difference really :) Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Moderators Robby Posted November 2, 2002 Moderators Posted November 2, 2002 Remove my error checking and comments, you're left with a few lines of code. As divil said, there's not much difference. Quote Visit...Bassic Software
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.