Results 1 to 3 of 3

Thread: Saving Contents of TextBoxes

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    20

    Saving Contents of TextBoxes

    Hi guys,i'm currently writing an application that collects data from users through the use of textboxes.How do i save the data as a CSV file?
    Please help in anyway u can,i'm in real need of some help here.

  2. #2
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Re: Saving Contents of TextBoxes

    This code goes through all textboxes on the form and adds the text from each textbox to a line to be wrote to file. the line is appended to any previous lines in the csv file

    VB Code:
    1. Dim l_sWriter As New StreamWriter("myfile.csv", TRUE)
    2.         Dim l_csvLine As String
    3.  
    4.      
    5.         Try
    6.                Dim l_ctrl As Control
    7.                For each l_ctrl In me.Controls
    8.                    If Typeof(l_ctrl) is textbox Then
    9.                         l_csvLine &= l_ctrl.text & ","
    10.                   End IF
    11.                Next
    12.              
    13.  
    14.                 'Remove the trailing comma
    15.                 l_csvLine = Mid(l_csvLine, 1, l_csvLine.Length - 1)
    16.  
    17.                 'Write the data to the file
    18.                 l_sWriter.WriteLine(l_csvLine)
    19.                 l_csvLine = ""
    20.             End While
    21.  
    22.          
    23.         Catch ex As IOException
    24.             MsgBox(ex.Message, MsgBoxStyle.Information, "ManoWave")
    25.         Finally
    26.             l_sWriter.Close()
    27.         End Try
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    20

    Re: Saving Contents of TextBoxes

    Thank you for those lines of codes.I'll go work on it !!

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