cmdolcet
asked on
VB 2005 how to get a new line of data each time I try to write to a file.
Currently the code give Datavalue1,Datavalue2,.... .
and I would like the saved text file to write:
DataValue1
DataValue2
and I would like the saved text file to write:
DataValue1
DataValue2
Private Sub mnuSaveOption_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSaveOption.Click
Dim Readings As New System.Text.StringBuilder()
dlgSaveLiveReadingsFile.Filter = "TXT Files (*.txt*)|*.txt"
Try
For Each number As Object In Me.lstLiveReadings.Items
Readings.Append(number)
Next
If dlgSaveLiveReadingsFile.ShowDialog = Windows.Forms.DialogResult.OK Then
My.Computer.FileSystem.WriteAllText(dlgSaveLiveReadingsFile.FileName, Readings.ToString, False)
End If
Catch ex As Exception
End Try
End Sub
ASKER
how would I get it to write an infinite number of readings.
ASKER
Shaun Vermaak,
How would this apply to data row that you dont have any number to so n data rows?
How would this apply to data row that you dont have any number to so n data rows?
Supose you have a string array values
Dim value() As String = {"Value1", _
"Value2", _
"Value3", _
"Value4"}
Private Sub mnuSaveOption_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSaveOption.Click
Dim Readings As New System.Text.StringBuilder()
dlgSaveLiveReadingsFile.Filter = "TXT Files (*.txt*)|*.txt"
Try
If dlgSaveLiveReadingsFile.ShowDialog = Windows.Forms.DialogResult.OK Then
For Each value As String In values
Readings.Append(value)
Next
My.Computer.FileSystem.WriteAllText(dlgSaveLiveReadingsFile.FileName, Readings.ToString, False)
End If
Catch ex As Exception
End Try
End Sub
ASKER
OK, How can I use it with the " Me.lstLiveReadings.Items" code?
Private Sub mnuSaveOption_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSaveOption.Click
Dim Readings As New System.Text.StringBuilder()
dlgSaveLiveReadingsFile.Filter = "TXT Files (*.txt*)|*.txt"
Try
If dlgSaveLiveReadingsFile.ShowDialog = Windows.Forms.DialogResult.OK Then
For Each item As ListViewItem In Me.lstLiveReadings.Items
Readings.Append(item.Text)
Next
My.Computer.FileSystem.WriteAllText(dlgSaveLiveReadingsFile.FileName, Readings.ToString, False)
End If
Catch ex As Exception
End Try
End Sub
ASKER
I get this after my code executes.
Error-Message.PNG
Error-Message.PNG
Private Sub mnuSaveOption_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSaveOption.Click
Dim Readings As New System.Text.StringBuilder()
dlgSaveLiveReadingsFile.Filter = "TXT Files (*.txt*)|*.txt"
Try
If dlgSaveLiveReadingsFile.ShowDialog = Windows.Forms.DialogResult.OK Then
For Each item As String In Me.lstLiveReadings.Items
Readings.Append(item)
Next
My.Computer.FileSystem.WriteAllText(dlgSaveLiveReadingsFile.FileName, Readings.ToString, False)
End If
Catch ex As Exception
End Try
End Sub
ASKER
So the code above I copied into me environment and ran it and it gives me:
-5.11,L00299-5.11,L00299-5 .11,L00299 -5.11,L002 99
I need it to be:
-5.11,L00299
-5.11,L00299
-5.11,L00299
-5.11,L00299
-5.11,L00299-5.11,L00299-5
I need it to be:
-5.11,L00299
-5.11,L00299
-5.11,L00299
-5.11,L00299
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window