by James Olarte (8 Submissions)
Category: String Manipulation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 14th December 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)
NUMERIC CONVERTER! Have you ever encountered formatting numeric characters in to a specified length, sometimes they give you a hard time
API Declarations
'You only need a command button in a form to test this code.
'This code requires you to input the number to convert then specify the length.
'Feel free to use my code for ease of coding.
Dim Code$, Ctr%, I%, J%, ConcatenateZero$
Const ZeroSample$ = "000000000"
On Error GoTo ErrorHandler:
ConcatenateZero = "0"
Ctr = CodeLength
For I = 1 To CodeLength
If NumberToConvert <= Val(1 & Left(ZeroSample, CodeLength)) - 1 And NumberToConvert >= Val(1 & Left(ZeroSample, CodeLength - 1)) Then
Code = NumberToConvert
Exit For
ElseIf NumberToConvert < Val(1 & Left(ZeroSample, I)) Then
For J = 1 To Ctr - 2
ConcatenateZero = ConcatenateZero & "0"
Next J
Code = ConcatenateZero & NumberToConvert
Exit For
End If
Ctr = Ctr - 1
Next I
NumCodeConvert = Code
Exit Function
ErrorHandler:
MsgBox "Error: " & Err.Description, vbCritical + vbOKOnly, "Error " & Err.Number & " in NumCodeConvert!"
End Function
Private Sub Command1_Click()
MsgBox NumCodeConvert(15, 5)
End Sub
No comments have been posted about NUMERIC CONVERTER! Have you ever encountered formatting numeric characters in to a specified length. Why not be the first to post a comment about NUMERIC CONVERTER! Have you ever encountered formatting numeric characters in to a specified length.