|
-
Apr 3rd, 2008, 10:21 PM
#1
Thread Starter
PowerPoster
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!
-
Apr 3rd, 2008, 10:39 PM
#2
Frenzied Member
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
-
Apr 3rd, 2008, 10:44 PM
#3
Fanatic Member
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

-
Apr 3rd, 2008, 10:46 PM
#4
Fanatic Member
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

-
Apr 3rd, 2008, 10:53 PM
#5
Frenzied Member
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
-
Apr 4th, 2008, 12:09 AM
#6
Thread Starter
PowerPoster
Re: Saving Textbox value
i just would like to use textbox with multi-line.
-
Apr 4th, 2008, 12:10 AM
#7
Fanatic Member
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:
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(sName)
End If
Next
Cheers...
Visual Studio.net 2010
If this post is useful, rate it

-
Apr 4th, 2008, 12:20 AM
#8
Thread Starter
PowerPoster
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
-
Apr 4th, 2008, 12:33 AM
#9
Thread Starter
PowerPoster
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?
-
Apr 4th, 2008, 03:51 AM
#10
Thread Starter
PowerPoster
Re: Saving Textbox value
How would I use the code to insert the values in a table?
-
Apr 4th, 2008, 05:35 AM
#11
Fanatic Member
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

-
Apr 6th, 2008, 07:59 AM
#12
Thread Starter
PowerPoster
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?
-
Apr 6th, 2008, 11:27 PM
#13
Fanatic Member
Re: Saving Textbox value
 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

-
Apr 7th, 2008, 07:02 PM
#14
Thread Starter
PowerPoster
Re: Saving Textbox value
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|