?
Solved

FORMAT NUMBER AT TEXTBOX WHILE INPUT

Posted on 2013-05-12
8
Medium Priority
?
1,391 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 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Technology Partners: 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!

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 …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

771 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