how do i format the text in my textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chidachris
    New Member
    • Feb 2015
    • 1

    how do i format the text in my textbox

    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 VB.net
  • lillyehrhart
    New Member
    • Jun 2015
    • 48

    #2
    try this

    Format(TextBoxN ame.Text, "0000000000 0,")

    Comment

    • Luk3r
      Contributor
      • Jan 2014
      • 300

      #3
      Code:
              'Get the length of characters in the text box
              Dim textBoxLength As Integer = TextBox1.Text.Length
      
              'Format the textbox character length by dividing by 11 (phone number length) and subtracting 1 (total number of commas to add)
              Dim textLength As Integer = textBoxLength / 11 - 1
      
              'Make i an integer which is equal to the textLength variable.  This is not necessary, just pretty
              Dim i As Integer = textLength
      
              'Loop in reverse order, inserting a comma every 11th character
              'We are looping backwards since the length of the textbox text changes with every insertion
              Do Until i = 0
                  TextBox1.Text = TextBox1.Text.Insert(11 * i, ",")
                  i = i - 1
              Loop

      Comment

      Working...