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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert String to Int

Status
Not open for further replies.

leppyk

MIS
Mar 24, 2005
8
IE
i have 3 text amounts and i need to create an int total of them. how can i convert the 3 amounts to long ints so i can get a total of these fields.
 
Take a look at the CLng function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
this function is to convert numerical values from one type to another. i need to convert a string to an int.
 
thanks for your help, i haven't used this before so i will show you what i have and could you explain how i can add that to the code you gave me?

txtPOVal1 = trim(Request.Form("txtPOVal1"))
txtPOVal2 = trim(Request.Form("txtPOVal2"))
txtPOVal3 = trim(Request.Form("txtPOVal3"))
txtPOVal4 = trim(Request.Form("txtPOVal4"))
intPOval1 = parseInt(txtPOVal1)
intPOval2 = parseInt(txtPOVal2)
intPOval3 = parseInt(txtPOVal3)
intPOval4 = parseInt(txtPOVal4)

intPOTotal = intPOval1 + intPOval2 + intPOval3 + intPOval4
 
leppyk,

documentation said:
CLng Function
Returns an expression that has been converted to a Variant of subtype Long.
CLng(expression)
The expression argument is any valid expression.
Strings like "12345" etc are valid expression. If the form fields are properly validated client side, you can simply use clng(request.form("txtPOVal1")) etc as PHV suggested. If they are not validate, you have to make a provision of on error resume next to pick up error on this process of conversion clng() and redirect the page back to user for inputting correct data.

regards - tsuji
 
Thanks for your repsonse, when i use that function i get the error type mismatch.
If i use System.Int32.Parse(STRINGNAME) i get Object required: '' error.

Any ideas what is wrong?
 
Any ideas what is wrong?
What is System.Int32.Parse ?
Are you sure to use VBScript ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
it converts the string representation of a number to its 32-bit signed integer equivalent. the error i get is
Microsoft VBScript runtime error '800a01a8'

Object required: ''


When i use the CLng function i get
Microsoft VBScript runtime error '800a000d'

Type mismatch: 'CLng'
 
Info right from M$ themselves......


The Int32.Parse method
To convert the string representation of a hexadecimal integer to a decimal integer, you can use the Int32.Parse method. This method converts the string representation of any number to its 32-bit signed integer equivalent. The .NET Framework provides the following four overloaded versions of the Int32.Parse method: • Int32.Parse(String)
• Int32.Parse(String, IFormatProvider)
• Int32.Parse(String, NumberStyles)
• Int32.Parse(String, NumberStyles, IFormatProvider)
To convert the string representation of a hexadecimal integer to a decimal integer, you can use the Int32.Parse(String, NumberStyles) method. This version of the Int32.Parse method accepts a string and a number style. The string contains the string representation of any number in a style that you specify by using the number style.

Troubleshooting
If you pass a string to the Int32.Parse method, and the string uses "0x" to specify a hexadecimal format, a System.FormatException error may occur at run time.

I didn't see in the posted code where this Int32.Parse was used, but, maybe the Thread starter could post a little more of the code.

-SWarrior
 
AFter reading up on this a little bit, I can't see any reason why you would want to use this design. If your string happens to have a SPACE in it, this function will give you an OFF the WALL number, not something that you'ld really want, or at least what I think you'ld want. It will also convert letters to a number...

For example:
' 12ABCDEF ' parses to 313249263
' FFFFFF00 ' parses to -256

I'm thinking that you might want to re-do your code and use something like TSUJI said to, the CLng Function

-SWarrior
 
Thank you all so much for your help, i am doing this as a favour for a girl at work and i'm not very familiar with coding. The top of the page is has

<HTML>
<HEAD>
<META name=VI60_defaultClientScript content=VBScript>
<META NAME="GENERATOR" Content="Microsoft FrontPage 4.0">

<SCRIPT ID=clientEventHandlersJS LANGUAGE="javascript">
//This code launches when the page hits the client and causes the List of projects to be displayed
//history.go(-2)
</script>
</HEAD>
<BODY>

so i am not sure if i'm writing in VBScript of Javascript. I know this is probably a simple solution for you but i'm only a beginner.
 
Greetings leppyk!

According to your latest post, you are definately using javascript. Hence the language element in your line:
Code:
<SCRIPT ID=clientEventHandlersJS LANGUAGE="javascript">
With that bit of knowledge, you would be better off asking your question in the javascript forumn. I think all you would need to do is use a double + to add two values together like the example below, but you will get better answers elsewhere.
Code:
X = "2"
Y = "3"
z = ++X
z = ++y

Good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top