Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format of texbox value

Status
Not open for further replies.

johnc83

Technical User
Jan 29, 2008
154
GB
Hi all,

I have a small problem which I'm hoping is easy to fix:

I have a textbox called JobNoTextBox.

The only format allowed in this box is 2 letters followed by 6 numbers. i.e "AB123456".

I need to automatically format the text if someone enters a value which is not in this format.

Example: Someone enters "AB12345" the code will automatically change it to "AB012345".

This is the code I have tried:
Code:
      JobNoTextBox.Text = Microsoft.VisualBasic.Left(JobNoTextBox.Text, 2) & Format(Microsoft.VisualBasic.Mid(JobNoTextBox.Text, 3, 6), "000000")
but it just changes the text to "AB000000" no matter what.

Can someone help please?

thanks

John

.NET 2.0, Visual Studio 2005, SQL Server 2005 Express
 
Dim Num As Integer = 123
Dim txt As String = "zzX"
MessageBox.Show(txt & Format(Num, "000000"))

Come on you reds.
 
'This assumes you have already validated the textbox value to AANNNNNN
Dim txt1 As String = Me.TextBox1.Text.Substring(0, 2)
Dim txt2 As Integer = CInt(Val(Me.TextBox1.Text.Substring(2)))
MessageBox.Show(txt1 & Format(txt2, "000000"))

Come on you reds.
 
Perfect, thanks very much.

Regards, John

.NET 2.0, Visual Studio 2005, SQL Server 2005 Express
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top