Solved

FORMAT NUMBER AT TEXTBOX WHILE INPUT

Posted on 2013-05-12
8
1,375 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
Industry Leaders: 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

729 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