[RESOLVED] Open/Saving textbox values
hey guys...My windows form as a bunch of textboxes on it that basically let the user put in different positions/forces that a test cycle then uses. I am trying to let the user save their profile settings/open the settings so they don't have to input the same values every time they want to run the same test. Here is my code so far. basically, when i save my csv file, and open it, all 6 textbox values are plopped in the first textbox instead of being distributed to their original boxes. I just read about a "split" function that I am going to read up on and see if that will help, but in the meantime, PLEASE HELP! Keep in mind i am a beginner and this is my first exposure with the save/openfileDialog classes...Thanks guys. I know you'll help out.
code Code:
Private Sub SaveProfileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveProfileToolStripMenuItem.Click
SaveProfileDialog.ShowDialog()
Dim sw As StreamWriter
Try
With SaveProfileDialog
.FileName = FileName
.Filter = "CSV files (*.csv)|*.csv|" & "All files|*.*"
If .ShowDialog() = DialogResult.OK Then
FileName = .FileName
sw = New StreamWriter(FileName)
sw.Write(Position1.Text)
sw.Write(Position2.Text)
sw.Write(Position3.Text)
sw.Write(Position4.Text)
sw.Write(Position5.Text)
sw.Write(Position6.Text)
End If
End With
Catch es As Exception
MessageBox.Show(es.Message)
Finally
If Not (sw Is Nothing) Then
sw.Close()
End If
End Try
End Sub
Private Sub OpenProfileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenProfileToolStripMenuItem.Click
Dim sr As StreamReader
Try
With OpenProfileDialog
.Filter = "CSV files (*.csv)|*.csv|" & "All files|*.*"
If .ShowDialog() = DialogResult.OK Then
FileName = .FileName
sr = New StreamReader(.OpenFile)
Position1.Text = sr.Read
End If
End With
Catch es As Exception
MessageBox.Show(es.Message)
Finally
If Not (sr Is Nothing) Then
sr.Close()
End If
End Try
End Sub
Re: Open/Saving textbox values
ok, i think the split function helped somewhat, but it still isn't quite working...see the code below.
vb Code:
Private Sub OpenProfileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenProfileToolStripMenuItem.Click
Dim sr As StreamReader
Try
With OpenProfileDialog
.Filter = "CSV files (*.csv)|*.csv|" & "All files|*.*"
If .ShowDialog() = DialogResult.OK Then
FileName = .FileName
sr = New StreamReader(.OpenFile)
Dim str
str = Split(Filename, ",")
Dim i As Integer
For i = 0 To UBound(str)
Position1.Text = str(0)
Position2.Text = str(1)
Position3.Text = str(2)
Position4.Text = str(3)
Position5.Text = str(4)
Position6.Text = str(5)
Next
End If
End With
Catch es As Exception
MessageBox.Show(es.Message)
Finally
If Not (sr Is Nothing) Then
sr.Close()
End If
End Try
End Sub
basically all I am getting is my filename as a string in the first textbox, which makes sense, but how do I split the contents of the file instead of the filename itself? Then my code will work.
Re: Open/Saving textbox values
nevermind guys. i think i got it. i just sent the data to another string and then split that string instead of trying to split the contents of the file directly.