Solved

FORMAT NUMBER AT TEXTBOX WHILE INPUT

Posted on 2013-05-12
8
1,362 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 70

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 70

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
LVL 70

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 70

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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