Solved

FORMAT NUMBER AT TEXTBOX WHILE INPUT

Posted on 2013-05-12
8
1,357 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 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 
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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
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…

856 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