Results 1 to 3 of 3

Thread: [RESOLVED] Open/Saving textbox values

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2010
    Posts
    69

    Resolved [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:
    1. Private Sub SaveProfileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveProfileToolStripMenuItem.Click
    2.         SaveProfileDialog.ShowDialog()
    3.  
    4.         Dim sw As StreamWriter
    5.  
    6.         Try
    7.             With SaveProfileDialog
    8.                 .FileName = FileName
    9.                 .Filter = "CSV files (*.csv)|*.csv|" & "All files|*.*"
    10.                 If .ShowDialog() = DialogResult.OK Then
    11.                     FileName = .FileName
    12.  
    13.                     sw = New StreamWriter(FileName)
    14.  
    15.                     sw.Write(Position1.Text)
    16.                     sw.Write(Position2.Text)
    17.                     sw.Write(Position3.Text)
    18.                     sw.Write(Position4.Text)
    19.                     sw.Write(Position5.Text)
    20.                     sw.Write(Position6.Text)
    21.  
    22.                 End If
    23.             End With
    24.         Catch es As Exception
    25.             MessageBox.Show(es.Message)
    26.         Finally
    27.             If Not (sw Is Nothing) Then
    28.                 sw.Close()
    29.             End If
    30.         End Try
    31.  
    32.     End Sub
    33.  
    34.    
    35.  
    36.  
    37.     Private Sub OpenProfileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenProfileToolStripMenuItem.Click
    38.         Dim sr As StreamReader
    39.         Try
    40.             With OpenProfileDialog
    41.              
    42.                 .Filter = "CSV files (*.csv)|*.csv|" & "All files|*.*"
    43.                
    44.                 If .ShowDialog() = DialogResult.OK Then
    45.  
    46.                     FileName = .FileName
    47.                     sr = New StreamReader(.OpenFile)
    48.  
    49.                     Position1.Text = sr.Read
    50.  
    51.                 End If
    52.             End With
    53.         Catch es As Exception
    54.             MessageBox.Show(es.Message)
    55.         Finally
    56.             If Not (sr Is Nothing) Then
    57.                 sr.Close()
    58.             End If
    59.         End Try
    60.     End Sub

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jun 2010
    Posts
    69

    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:
    1. Private Sub OpenProfileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenProfileToolStripMenuItem.Click
    2.         Dim sr As StreamReader
    3.         Try
    4.             With OpenProfileDialog
    5.              
    6.                 .Filter = "CSV files (*.csv)|*.csv|" & "All files|*.*"
    7.                
    8.                 If .ShowDialog() = DialogResult.OK Then
    9.  
    10.                     FileName = .FileName
    11.                     sr = New StreamReader(.OpenFile)
    12.                     Dim str
    13.                     str = Split(Filename, ",")
    14.                     Dim i As Integer
    15.                     For i = 0 To UBound(str)
    16.                         Position1.Text = str(0)
    17.                         Position2.Text = str(1)
    18.                         Position3.Text = str(2)
    19.                         Position4.Text = str(3)
    20.                         Position5.Text = str(4)
    21.                         Position6.Text = str(5)
    22.  
    23.                     Next
    24.                 End If
    25.             End With
    26.         Catch es As Exception
    27.             MessageBox.Show(es.Message)
    28.         Finally
    29.             If Not (sr Is Nothing) Then
    30.                 sr.Close()
    31.             End If
    32.         End Try
    33.     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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2010
    Posts
    69

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width