Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP Function : ASCII to Integer

Status
Not open for further replies.

AkutaSame

Programmer
Oct 5, 2002
97
US
I know this will sound a bit newbish, but then again, I'm an ASP newbie. I know it can be done with other scripting languages. What I am looking for is an ASP function that will convert a string/ascii characters into integers.

Logic:

A text box contains a number. I want to submit this number to SQL through a query, but must modify the number using some sort of algorythm first. Thus, I need to be able to take the string, convert it to a number, modify the number accordingly and submit the new integer variable to SQL in a string.

I know how to submit variables to SQL in ASP, that's not the problem. It's just converting from the original string to an integer in order to do the modification before submission.

Any there that can help?

Akuta
 
<%
MyVariable = CInt(myVariable) 'Converts myVariable to Integer
MyVariagle = Clng(myVariable) 'Converts MyVariable to Long
MyVariable = CStr(MyVariable) 'Converts MyVariable to String
MyVariable = CBool(MyVariable) 'Converts MyVariable to Boolean
MyVariable = CDbl(MyVariable) 'Converts MyVariable to Double
MyVariable = CSng(MyVariable) 'Converts myVariable to Single
%>
etc.
 
In VB6, there is a function call CInt(expression) which return the an integer value. You can try that.

You can do something like:

intValue = request(&quot;textbox&quot;)

If CInt(intValue)= 1 then
'do something
else
'do something
end if
 
To convert characters to ASCII numeric: Asc(character)
To convert ASCII numeric to characters: Chr(integer)

So Asc(&quot;a&quot;) will return 97 and Chr(97) will return a

-Tarwn

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
minilogo.gif alt=tiernok.com
The never-completed website
 
Can I just add, that cINT(sExp) will fail with a Type mismatch error if sExp does not contain a string of only numeric characters.

i.e cInt(&quot;one&quot;) will fail
cInt(&quot;1one&quot;) will fail also
cInt(&quot;1&quot;) is fine though.

I always use the isNumeric function first, i.e

if isNumeric (sExp) then
vExp = cInt(sExp)
else
gracefulyFail....
end if

Is there a simpler way than this?


Digital Soma
 
p3t3:
not to mention that VBscript integers have a very low range.. the following will fail:
Code:
CInt(&quot;32800&quot;)

And yes I think using IsNumeric is a good way to fail gracefully :)


Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top