By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,327 Members | 2,661 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,327 IT Pros & Developers. It's quick & easy.

how do i format the text in my textbox

P: 1
i have a set of phone numbers loaded into my text-box and i want to format the record such that each phone number of 11 digits is separated by a comma. that is after every 11 digits a comma will be automatically placed. please what code do i use in
Feb 25 '15 #1
Share this Question
Share on Google+
2 Replies

P: 48
try this

Format(TextBoxName.Text, "00000000000,")
Sep 8 '15 #2

P: 299
Expand|Select|Wrap|Line Numbers
  1.         'Get the length of characters in the text box
  2.         Dim textBoxLength As Integer = TextBox1.Text.Length
  4.         'Format the textbox character length by dividing by 11 (phone number length) and subtracting 1 (total number of commas to add)
  5.         Dim textLength As Integer = textBoxLength / 11 - 1
  7.         'Make i an integer which is equal to the textLength variable.  This is not necessary, just pretty
  8.         Dim i As Integer = textLength
  10.         'Loop in reverse order, inserting a comma every 11th character
  11.         'We are looping backwards since the length of the textbox text changes with every insertion
  12.         Do Until i = 0
  13.             TextBox1.Text = TextBox1.Text.Insert(11 * i, ",")
  14.             i = i - 1
  15.         Loop
Sep 9 '15 #3

Post your reply

Sign in to post your reply or Sign up for a free account.