Solved

FORMAT NUMBER AT TEXTBOX WHILE INPUT

Posted on 2013-05-12
8
1,339 Views
Last Modified: 2013-05-14
Hi All,

I have below code to format number.

  Public Shared Sub Format_Editing_Number(ByRef txtData As TextBox, _
                                              Optional ByVal intNumberOfDecimal As Integer = 0)
        Dim intNumberOfDecimalPoint As Integer

        If InStr(txtData.Text, ERV_Global.Get_Decimal_Char()) > 0 Then
            If Right(txtData.Text, 1) = "0" Then
                intNumberOfDecimalPoint = Len(Trim(txtData.Text))
                intNumberOfDecimalPoint = intNumberOfDecimalPoint - InStr(txtData.Text, ERV_Global.Get_Decimal_Char())
                txtData.Text = ERV_Global.Format_Number(txtData.Text, intNumberOfDecimalPoint, True)
            End If
        Else
            If intNumberOfDecimal > 0 Then
                txtData.Text = ERV_Global.Format_Number(txtData.Text, intNumberOfDecimal, True)
            Else
                If IsNumeric(txtData.Text) Then
                    txtData.Text = ERV_Global.Format_Number(txtData.Text)
                End If
            End If
        End If

        txtData.SelectionStart = Len(Trim(txtData.Text))

    End Sub

 Public Shared Function Format_Number(ByVal dblNumber As Double, _
                                          Optional ByVal intDecimalPoint As Integer = 0, _
                                          Optional ByVal blnSetDecimalPoint As Boolean = False) As String
        Format_Number = ""

        Dim strDecPoint As String = ""

        For I As Integer = 1 To intDecimalPoint
            strDecPoint &= "0"
        Next

        Dim intDecimal As Integer
        intDecimal = Get_Decimal_Point(dblNumber)

        'If intDecimal = 1 Then intDecimal = 2

        If intDecimal = 0 Then
            If blnSetDecimalPoint Then
                Format_Number = Format(dblNumber, "#,##0." & strDecPoint)
            Else
                Format_Number = Format(dblNumber, "#,##0")
            End If
        Else
            If blnSetDecimalPoint Then
                Format_Number = Format(dblNumber, "#,##0." & strDecPoint)
            Else
                strDecPoint = ""

                For I As Integer = 1 To intDecimal
                    strDecPoint &= "0"
                Next

                Format_Number = Format(dblNumber, "#,##0." & strDecPoint)
            End If
        End If

    End Function

Is there anything I should do about it ?

Thank you.
0
Comment
Question by:emi_sastra
  • 4
  • 4
8 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 39159981
>>Is there anything I should do about it ?

what is the problem?
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 39160312
When I type decimal poin ("."), it does not work, the decimal point not show in textbox.

Thank you.
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 39160850
and what is calling these methods? Any other events? Maybe look at http://emoreau.com/Entries/Articles/2003/03/Creating-your-own-Windows-Custom-Control.aspx
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 39160874
This function is called when textbox text changed.
The function is doing formatting, add thousand separator while input.

Thank you.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 69

Expert Comment

by:Éric Moreau
ID: 39160883
since we cannot trace it, you will have to do it. what is returned by Get_Decimal_Point(dblNumber)? is blnSetDecimalPoint set to True? ... ?
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 39160939
Ok. I will check it.

Is there other way to do below code ?

Format(dblNumber, "#,##0." & strDecPoint)

Thank you.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 39161030
you can use the ToString method but it will give you the same result:

dblNumber.ToString( "#,##0." + strDecPoint)
0
 
LVL 1

Author Closing Comment

by:emi_sastra
ID: 39164200
Ok.

Thank you very much for your help.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now