VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Returns a space delimited list of ASCII codes that would be needed to convert a number to its strin

by VB-Kung-Fu (19 Submissions)
Category: String Manipulation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 9th October 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Returns a space delimited list of ASCII codes that would be needed to convert a number to its string represtantion.

Rate Returns a space delimited list of ASCII codes that would be needed to convert a number to its strin



Dim Digit As Variant, div As Long
If IsNumeric(Num) = False Then Exit Function

div = 1000000000

'ensure num is positive before working but include negative sign
'if num is negative
If Num < 0 Then
    Num = Num * -1
    Dec2Ascii = CStr(Asc("-"))
ElseIf Num < 10 Then
    Dec2Ascii = CStr(Num Or 48)
    Exit Function
End If

'this following process extracts each individual digit
'in the number and produces its ascii code
Do While div > 0 And Num > 0
        If Num >= div Then
           'extract digit
           Digit = Num \ div
           
           'the ORing with 48 converts the binary values for 0 - 9 to their
           'ascii code. eg 5 or 48 = 53 which is the ascii code for 5
           Dec2Ascii = Dec2Ascii & " " & (Digit Or 48)
           
           If Num Mod div = 0 Then
           'if the number is a multiple of ten we have to use this method in
           'order to get the zeros in
               Do While Num > 10
                   Dec2Ascii = Dec2Ascii & " " & Asc("0")
                   Num = Num / 10
               Loop
               Exit Function
           End If
           
           Num = Num Mod div 'move to next digit
        End If
        div = div / 10 'decrease the divisor since number is too small
Loop

Dec2Ascii = RTrim(Dec2Ascii)
End Function



Download this snippet    Add to My Saved Code

Returns a space delimited list of ASCII codes that would be needed to convert a number to its strin Comments

No comments have been posted about Returns a space delimited list of ASCII codes that would be needed to convert a number to its strin. Why not be the first to post a comment about Returns a space delimited list of ASCII codes that would be needed to convert a number to its strin.

Post your comment

Subject:
Message:
0/1000 characters