7 Replies - 785 Views - Last Post: 27 January 2013 - 05:04 AM Rate Topic: -----

#1 MafiaAndre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 18-January 13

1000 Separator

Posted 25 January 2013 - 08:38 AM

Hi all.

I made a project for accounting purposes and I would like to know, how can I code my TextBox to have a 1000's separator.
Like for example, when the user types in 5336, I want it to be displayed as 5 336.
I would even like to have it to the millions, e.g: 1 259 966
How do i do this??
Is This A Good Question/Topic? 0
  • +

Replies To: 1000 Separator

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9197
  • View blog
  • Posts: 34,551
  • Joined: 12-June 08

Re: 1000 Separator

Posted 25 January 2013 - 08:44 AM

Don't use a textbox but use the MASKEDtextbox... and then just set the mask right!

http://msdn.microsof...y/kkx4h3az.aspx
http://msdn.microsof...kedtextbox.aspx
Was This Post Helpful? 1
  • +
  • -

#3 LilGhost  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 98
  • Joined: 12-October 12

Re: 1000 Separator

Posted 25 January 2013 - 01:08 PM

I haven't tested this to make sure it works, but i believe saying:
dim variableStr as string = textbox1.text.tostring("### ##0")


would convert it to the thousands place and put a space in it. The "0" can be changed to a "#" if you'd like, but changing it to "#" would mean if the user types "0" into textbox1, the variableStr will be set equal to an empty string.
Was This Post Helpful? 0
  • +
  • -

#4 ybadragon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 201
  • View blog
  • Posts: 1,250
  • Joined: 11-May 12

Re: 1000 Separator

Posted 25 January 2013 - 01:23 PM

You should look into String.Format

That is how I always do my formatting.
Was This Post Helpful? 0
  • +
  • -

#5 MafiaAndre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 18-January 13

Re: 1000 Separator

Posted 26 January 2013 - 11:05 AM

View PostLilGhost, on 25 January 2013 - 01:08 PM, said:

I haven't tested this to make sure it works, but i believe saying:
dim variableStr as string = textbox1.text.tostring("### ##0")


would convert it to the thousands place and put a space in it. The "0" can be changed to a "#" if you'd like, but changing it to "#" would mean if the user types "0" into textbox1, the variableStr will be set equal to an empty string.


This does not seem to work... I tested, but the numbers are still in the form of 000000 and not 000 000
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3467
  • View blog
  • Posts: 11,768
  • Joined: 12-December 12

Re: 1000 Separator

Posted 26 January 2013 - 11:24 AM

I advise you to use the MaskedTextBox mentioned earlier: this is what it is designed for.

You could use, perhaps the LostFocus event to change the actual text in the textbox:

    Private Sub TextBox1_LostFocus(sender As Object, e As EventArgs) Handles TextBox1.LostFocus
        If IsNumeric(TextBox1.Text) Then
            TextBox1.Text = String.Format("{0:### ##0}", CInt(TextBox1.Text))
        End If

    End Sub


But this changes the actual data in the textbox by inserting spaces. You would need to use perhaps GotFocus to remove the spaces and, similarly, when you make use of the value you would need to remove the spaces again before converting it to a numeric value.

This post has been edited by andrewsw: 26 January 2013 - 11:35 AM

Was This Post Helpful? 0
  • +
  • -

#7 MafiaAndre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 18-January 13

Re: 1000 Separator

Posted 27 January 2013 - 04:28 AM

View Postandrewsw, on 26 January 2013 - 11:24 AM, said:

I advise you to use the MaskedTextBox mentioned earlier: this is what it is designed for.

You could use, perhaps the LostFocus event to change the actual text in the textbox:

    Private Sub TextBox1_LostFocus(sender As Object, e As EventArgs) Handles TextBox1.LostFocus
        If IsNumeric(TextBox1.Text) Then
            TextBox1.Text = String.Format("{0:### ##0}", CInt(TextBox1.Text))
        End If

    End Sub


But this changes the actual data in the textbox by inserting spaces. You would need to use perhaps GotFocus to remove the spaces and, similarly, when you make use of the value you would need to remove the spaces again before converting it to a numeric value.


I am not sure how to use the maskedtextbox. What must I enter in the custom part of the MaskedTextbox?
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3467
  • View blog
  • Posts: 11,768
  • Joined: 12-December 12

Re: 1000 Separator

Posted 27 January 2013 - 05:04 AM

View PostMafiaAndre, on 27 January 2013 - 04:28 AM, said:

I am not sure how to use the maskedtextbox. What must I enter in the custom part of the MaskedTextbox?


There is a summary of the various symbols here. However, on reflection, I don't think it is suitable for your post. It is ideal where there a set number of characters required and, ideally, for text rather than a numeric value.

The problem is that it won't fill from right to left. There is a property RightToLeft but it fills in reverse order.

You could try playing with the Culture property as well. (There is supposed to be a NumberGroupSeparator property that you can set in programming but it wasn't recognised for me.)

Sorry I can't be more helpful. Andy.

This post has been edited by andrewsw: 27 January 2013 - 05:08 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1