Formatting Currency :lol:

I would simply like to format a variable(WallboardCost) as currency.

What is the easiest way to to this in Visual Basic 6.

Thanks a lot.

Chris B

Well I don't trust the currency formatting of the 'format' call so I use:

Public Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPriviteProfileIntA" (ByVal lpApplicationname As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long

' GetRegionalCurrencySymbol(Function)
' String str
' Returns regional currency setting for the current PC
Public Function getRegionalCurrencySymbol() As String
  Const PROCEDURE_NAME As String = "GetRegionalCurrencySymbol"

  On Error GoTo errorHandler

    Dim strSecName As String
    Dim strRetString As String * 256
    Dim lngSuccess As Long
    strSecName = "Intl"
    getRegionalCurrencySymbol = ""
    lngSuccess = GetProfileString(strSecName, "sCurrency", "", strRetString, Len(strRetString))
    If lngSuccess <> 0 Then
        getRegionalCurrencySymbol = Left$(strRetString, InStr(strRetString, Chr$(0)) - 1)
    End If
    On Error Resume Next
    Exit Function
  frmErrorHandler.errorForm MODULE_NAME, PROCEDURE_NAME
  getRegionalCurrencySymbol = "$"
  Resume End_Tag
End Function

And then:

msgbox format(sngNumber,getRegionalCurrencySymbol & "#0.00")


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.