Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Applying some formatting to a numeric field
Message
De
15/04/2006 19:45:08
 
 
À
14/04/2006 17:11:39
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01113801
Message ID:
01113904
Vues:
22
This message has been marked as the solution to the initial question of the thread.
Instead of trying to do macro substitution, all you need to do is figure out the format string. So, you'd have something like this instead:
        ' Obtain formatted value
        lcFormat = ""
        For lnCompteur = 1 To 10
            lcFormat = "#" + lcFormat
            If lnCompteur Mod 3 = 0 Then
                lcFormat = cSeparator + lcFormat
            End If
        Next

        lcValue = tnValue.ToString(lcFormat)

        ' If we have decimals
        If lnDecimal > 0 Then
            lcValue = lcValue + "."
            lcValue = lcValue.PadRight(lnDecimal, "0")
        End If

RETURN lcValue
>
>I have a numeric field which is holding a value such as 12.45. This value is passed into a GetTransform() function which is as follow:
>
>
>    ' Return a transformed value for formatting
>    ' expN1 Value
>    ' expC1 Number of decimal
>    Private Function GetTransform(ByVal tnValue As Integer, Optional ByVal tnDecimal As Integer = 0) As String
>        Dim lnValue As Integer
>        Dim lnDecimal As Integer
>        Dim lcValue As String
>        Dim lcFormat As String
>        Dim lnCompteur As Integer
>        lnDecimal = 0
>        If tnDecimal > 0 Then
>            lnDecimal = tnDecimal
>        End If
>
>        ' Obtain formatted value
>        lcValue = "TRIM(Format(tnValue,"""
>        lcFormat = ""
>        For lnCompteur = 1 To 10
>            lcFormat = "#" + lcFormat
>            If lnCompteur Mod 3 = 0 Then
>                lcFormat = cSeparator + lcFormat
>            End If
>        Next
>        lcValue = lcValue + lcFormat
>
>        ' If we have decimals
>        If lnDecimal > 0 Then
>            lcValue = lcValue + "." + "".PadRight(lnDecimal, "0")
>        End If
>
>        lcValue = lcValue + """))"
>RETURN &lcValue
>    End Function
>
>
>This function prepares a specific formatting based on the parameter passed and some other properties available in that function. The specific formatting is hold in the lcValue variable. However, this function should return the new formatted value and not the formatted string. So, this is why I need to adjust the last line, the RETURN, as there is no macro substition in VB.NET. How can I achieve that?
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform