Trigger
08-09-04, 02:44 PM
A program I am working on has a series of listboxes. When I close the program down I wish to save the selections so that the next time I start the program up the selections are still in place. Please tell me how to do this so I can stop chasing my tail. ;) ;)
Hi,
I have a filestream example that would help you out further. Here is the code I used in it:
Private Sub btnReadFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, btnReadFile.Click
Const BLOCK_SIZE As Integer = 100
Dim FileToOpen As String
OpenFileDialog1.ShowDialog()
txtPathToFile.Text = OpenFileDialog1.FileName
Dim TestFile As BinaryReader
Dim BytesRead As Integer
Dim ByteValues(BLOCK_SIZE) As Byte
Dim StringValue As String
Dim ASCIIConverter As System.Text.ASCIIEncoding
Dim FilePath As String
txtMessage.Text = ""
' FilePath = Application.StartupPath & "\..\quotes.txt"
FilePath = txtPathToFile.Text
If Not File.Exists(FilePath) Then
MessageBox.Show("Cannot find file " & FilePath)
Exit Sub
End If
'Open a File for Reading
TestFile = New BinaryReader(File.Open(FilePath, IO.FileMode.Open, IO.FileAccess.Read))
'Read the file in byte blocks and build a string
BytesRead = TestFile.Read(ByteValues, 0, BLOCK_SIZE)
ASCIIConverter = New System.Text.ASCIIEncoding()
While BytesRead > 0
StringValue = ASCIIConverter.GetString(ByteValues, 0, BytesRead)
txtMessage.Text &= StringValue
Array.Clear(ByteValues, 0, BLOCK_SIZE)
BytesRead = TestFile.Read(ByteValues, 0, BLOCK_SIZE)
End While
'Display the resulting string in a text box
TestFile.Close()
End Sub
Here are all the source code to this script:
http://www.digioz.com/devry/CIS430/Lab/filestream/
And here is a working executable program of it. You will need to have the ".NET" platform installed on your computer to be able to run it. Here is the link to that:
http://www.digioz.com/devry/CIS430/Lab/filestream/bin/FileStream.exe
vBulletin® v3.6.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.