
Originally Posted by
dilettante
What I haven't tracked down yet is an equivalent of Format$() that accepts an LCID argument.
Here you go (though not intensively tested yet)...
Code:
Private Declare Function VarTokenizeFormatString Lib "oleaut32.dll" (ByVal pstrFormat As Long, ByRef rgbTok As Any, ByVal cbTok As Long, ByVal iFirstDay As VbDayOfWeek, ByVal iFirstWeek As VbFirstWeekOfYear, ByVal LCID As Long, Optional ByVal pcbActual As Long) As Long
Private Declare Function VarFormatFromTokens Lib "oleaut32.dll" (ByRef pvarIn As Variant, ByVal pstrFormat As Long, ByRef pbTokCur As Any, ByVal dwFlags As Long, ByVal pbstrOut As Long, ByVal LCID As Long) As Long
Public Function FormatLA(Expression As Variant, Optional Format As String, Optional ByVal FirstDayOfWeek As VbDayOfWeek = vbUseSystemDayOfWeek, Optional ByVal FirstWeekOfYear As VbFirstWeekOfYear = vbUseSystem, Optional ByVal TargetLCID As Long, Optional ByVal PatternLCID As Long = 1033) As String
Static hRes As Long, B(0 To 4095) As Byte
hRes = VarTokenizeFormatString(StrPtr(Format), B(0), UBound(B) + 1, FirstDayOfWeek, FirstWeekOfYear, PatternLCID)
If hRes Then Err.Raise hRes
hRes = VarFormatFromTokens(Expression, StrPtr(Format), B(0), 0, ByVal VarPtr(FormatLA), TargetLCID)
If hRes Then Err.Raise hRes
End Function
Oh, and in your function above, the Variant-input-Param could be left at ByRef, to avoid unnecessary extra-allocations in case of e.g. String-content in this Param.
...Public Property Get Convert(ByVal Value As Variant, ...
The above Value-Param I mean.
Olaf