Results 1 to 14 of 14

Thread: Saving Textbox value

  1. #1

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Saving Textbox value

    Hi! Currently I have 12 textboxes which the user will enter the name and age. 6 textboxes for names and 6 for ages.

    I want to use only one textbox instead of 12 textboxes. I'll use the multi-line line of the textbox and want to user to just input the name and beside it, is the corresponding age of the name so that i will not be limited to just 6 names.
    Example:
    John Doe 12
    Carl Vincent 13
    Mary Tuesday 12
    etc..

    My Problem is, how do I save the values in my table but split the name in one namefield and the other to agefield?

    I want also to let the user to query my table and display the names and ages in the same textbox the user used to enter those values.

    How do I do this? Any sample code will be of great help. Thanks!
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  2. #2
    Frenzied Member Icyculyr's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    1,934

    Re: Saving Textbox value

    Erm, I don't know much about what your doing, but I saw the word 'split',
    Dim sSplit() As String = tbNames.Text.Split(" ") 'Split by the space, then each item is in sSplit etc...

    Cheers

  3. #3
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: Saving Textbox value

    In textBox means, you can use split option and find each line.

    For trying this in textBox, better you can use datagridview,

    You can easily pick the value from it.
    Visual Studio.net 2010
    If this post is useful, rate it


  4. #4
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: Saving Textbox value

    @ICyculr.

    If splitted with space means, there is one problem.

    If the name in this pattern means "John Williams", it will split as "John" in an index, and "Williams" in another index
    Visual Studio.net 2010
    If this post is useful, rate it


  5. #5
    Frenzied Member Icyculyr's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    1,934

    Re: Saving Textbox value

    I see, give me an example of how you would store the names?

    If it's like this:

    John Williams Frank Marat Micheal Bovea

    There is nothing you can do, if you don't mind using a separator such as a comma, or semicolon after each name, then you can just use split,

    Cheers

  6. #6

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Saving Textbox value

    i just would like to use textbox with multi-line.
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  7. #7
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: Saving Textbox value

    Here you can get the value from the textbox,
    The first messageBox throw the age and second one give the names,
    Paste it on an buuton click event.

    Imports System.Text.RegularExpressions
    Get value from textbox Code:
    1. Dim sTest() As String = TextBox1.Text.Split(Environment.NewLine.ToCharArray)
    2.         Dim sName, sAge As String
    3.         For i As Integer = 0 To sTest.Length - 1
    4.             Dim txt() As String = sTest(i).Split(" ".ToCharArray)
    5.             sName = ""
    6.             sAge = ""
    7.             For j As Integer = 0 To txt.Length - 1
    8.                 Dim txtOnly As Regex = New Regex("[0-9*]")
    9.                 Dim m As Match = txtOnly.Match(txt(j))
    10.                 If m.Success = False Then
    11.                     sName += txt(j) & " "
    12.                 Else
    13.                     sAge = txt(j)
    14.                     MessageBox.Show(txt(j))
    15.                 End If
    16.             Next
    17.             If sName <> "" And sAge <> "" Then
    18.                 MessageBox.Show(sName)
    19.             End If
    20.         Next

    Cheers...
    Visual Studio.net 2010
    If this post is useful, rate it


  8. #8

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Saving Textbox value

    What is Regex and Match? Im getting error "type Regex not defined".

    and what about if the name is like what Icyculyr said?
    John Williams Frank Marat Micheal Bovea
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  9. #9

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Saving Textbox value

    Ah Regex is Regular Expression....

    Its already working. I forgot to put this "Imports System.Text.RegularExpressions"

    Now, how do i insert that in my table at then how do i display it back to textbox?
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  10. #10

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Saving Textbox value

    How would I use the code to insert the values in a table?
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  11. #11
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: Saving Textbox value

    Inside the code i put a command, there u write the query to fill in the table.

    Code:
      Dim sTest() As String = TextBox1.Text.Split(Environment.NewLine.ToCharArray)
            Dim sName, sAge As String
            For i As Integer = 0 To sTest.Length - 1
                Dim txt() As String = sTest(i).Split(" ".ToCharArray)
                sName = ""
                sAge = ""
                For j As Integer = 0 To txt.Length - 1
                    Dim txtOnly As Regex = New Regex("[0-9*]")
                    Dim m As Match = txtOnly.Match(txt(j))
                    If m.Success = False Then
                        sName += txt(j) & " "
                    Else
                        sAge = txt(j)
                        ' MessageBox.Show(txt(j))
                    End If
                Next
                If sName <> "" And sAge <> "" Then
                    MessageBox.Show(sAge)
                    MessageBox.Show(sName)
                    ' Here u can get the Name and age,
                    'Write insert query in this, 
                End If
            Next
    Next, if you want to read the stored value in the table means, simple keep a primary key, then display it in the textbox using select query./
    Last edited by vijy; Apr 4th, 2008 at 05:39 AM.
    Visual Studio.net 2010
    If this post is useful, rate it


  12. #12

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Saving Textbox value

    Thanks vijy. I follow up question. How about limiting the user to just enter the name and a two digit age value every line of the multi-line textbox?
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  13. #13
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: Saving Textbox value

    Quote Originally Posted by Simply Me
    How about limiting the user to just enter the name and a two digit age value every line of the multi-line textbox?
    ya we can try to restrict the user to type,

    Tell me, if there is an possibility to have morethan two digit for age.

    Because i will try to validate like this,
    In a line,if the user typed two digits continiously, then i wont allow the user to type next...

    Also, why you trying in the textbox, Why can't you use datagridview?
    Visual Studio.net 2010
    If this post is useful, rate it


  14. #14

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Saving Textbox value

    Quote Originally Posted by vijy
    ya we can try to restrict the user to type,

    Tell me, if there is an possibility to have morethan two digit for age.

    Because i will try to validate like this,
    In a line,if the user typed two digits continiously, then i wont allow the user to type next...

    Also, why you trying in the textbox, Why can't you use datagridview?
    The user might type more than 2 digits.
    I have a long list of information to be saved in my database and using datagridview is not an option.
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

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