Adds the specific character to the left side of a value when the value is less than a comparison. Useful when converting a single-digit month or day to a string.
Function Pad (Value As Number, Comparison As Number, Padding As String) As String
dim SPACE_CHARACTER: SPACE_CHARACTER=ChrW(32)
If Value
Pad=Replace(Space(Len(CStr(Comparison,0))-Len(CStr(Value,0))), SPACE_CHARACTER, Padding) & CStr(Value,0)
Else
Pad=CStr(Value,0)
End If
End Function
Parameters
- Value
- value to be padded.
- Comparison
- value compared to this number.
- Padding
- character used to pad the value.
Return Value
A string.
Remarks
none
Example
'returns "09"
Pad (9, 10, "0")
‘returns “11”
Pad (11, 10, “0”)
Requirements
This function requires the use of Basic Syntax.
5 is the total length to show, replacing it with the desired
ReplicateString (“0”,5 – len(cstr(number,0)) ) + cstr(number,0)