FileStream :)

DR00ME

Well-known member
Joined
Feb 6, 2004
Messages
169
Location
Finland
I got some items in my listbox:

1.222 323 323
555 222 2.124
3.12 12 244
324 54 367
244 0.232 0.212

I want to write them just like that in a file, how do I do it ? and How do I read from a specific row in a file....... ? the main thing I want to know is how to write in a specific row in a file.... yeah...using filestream not fileopen or whatever it was...I know this takes a bit of your time but if you got some old example I would be more than grateful...
 
Last edited by a moderator:
File I/O using a Stream is sequential... unless you know the exact location of the line in the file that you want to read from, you will have to read each line one by one until a counter that you make reaches the value that you want to look at. :)
For writing the contents of a listbox to file, it would seem that youd only have to use a For Loop on the ListBox.Items and use your Streams .WriteLine property to write that entry in the listbox to file. :)
 
You use the .WriteLine of your file stream in a For Loop.
Is that too complex?
What did you do based on what I mentioned?

Code:
For LV = 0 To LBx.Items.Count - 1
  SW.WriteLine(LBx.Items(LV))
 
blah, Ill try to play around with it.... this is what I got so far...

[Vb] Private Sub btnCalibrate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalibrate.Click

Dim CalibFile As FileStream
Dim i As Integer
Dim byteArray() As Byte
Dim dataString As String
Dim fileDataString As String
Dim FileHandle As File
Dim SR As StreamReader
Dim SW As StreamWriter



If lstHSL2.Items.Count > 0 Then
For i = 0 To lstHSL2.Items.Count() - 1

If dataString = Nothing Then
dataString = lstHSL2.Items(i)
Else
dataString = dataString + ";" + lstHSL2.Items(i)
End If

Next i


SR = FileHandle.OpenText("Calibration.ini")
fileDataString = SR.ReadToEnd
SR.Close()


byteArray = Encoding.Unicode.GetBytes(fileDataString + dataString)

CalibFile = New FileStream("Calibration.ini", FileMode.Create)
CalibFile.Write(byteArray, 0, byteArray.Length)
CalibFile.Close()
CalibFile = Nothing

End If

End Sub[/VB]
 
Last edited by a moderator:
Back
Top