Get the ASCII value for a number

I am looking for a way to get the ASCII value for a passed number.  Meaning i need to know what the ASCII value of "375" would be.

I think that it would mean getting the value for each number and then adding them together.  Do anybody have any examples of how to do this with visual basic?


Mike_StevensAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bkthompson2112Commented:
Hi Mike_Stevens,

"375" does not have an ASCII value.  
Each character of the string ('3', '7', and '5') has an ASCII value.
They are 51, 55, and 53, respectively.

Adding those number does not give the ASCII value of "375".

What are you trying to accomplish?

You can get the ASCII value of any character by using the Asc() function.
e.g.  debug.print asc("3")
prints 51

bkt
0
kevinsreaCommented:
how about this ?

MsgBox Asc("ascii number")


kevin rea
0
David LeeCommented:
I agree with what bkt said.  Still, if you want to add up ASCII values of each character position, then here's a way:

    strnumber = "375"
    For intPosition = 1 To Len(strnumber)
        intValue = intValue + Asc(Mid(strnumber, intPosition, 1))
    Next
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Mike_StevensAuthor Commented:
I am trying to beat the sorting a recordset by a number value problem.  When i sort the recordset on the existing number value it is sorted as follows:

100
110
125
150
2
25
250
300
35
....and so on

I thought by getting the ascii value for the number is could sort the recordset based on that.  However, getting the ascii value for each number position on "375" does not work like i had hoped.  Any ideas on sorting a recordset on a number value that will sort correctly?


0
bkthompson2112Commented:
Is the number saved in a text field?

If so, in your SQL statement, you should be able to convert the string number to
an actual number.  Then the sorting would work properly.

In SQL Server, I'd do something like this:

SELECT CAST(SortField AS int) as SortFieldNum
FROM tablename
ORDER BY SortFieldNum
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David LeeCommented:
I don't know that this'll work with sorting a recordset, but when working with numbers it's always handy to make them all the same length by padding them with zeros to a certain length.  Here's a function that'll do that.  

Private Function StringZero(strValue As String, intPadLength As Integer) As String
    Dim intValLength As Integer
    strValue = Trim(strValue)
    intValLength = Len(strValue)
    If intValLength > intPadLength Then
        StringZero = strValue
    Else
        StringZero = String(intPadLength - intValLength, "0") & strValue
    End If
End Function
0
EDDYKTCommented:
you can do something like


select number from yourtable order by val(number)
0
dpalmeCommented:
You need to have your values stores as numbers, integers, double, long, etc.  Then it will sort correctly.

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.