Solved

Asp "typecast" or convert string to int

Posted on 2004-04-07
11
1,183 Views
Last Modified: 2007-12-19
Greetings

I seem to have a really weird issue with converting string to int in ASP.

I know that basically it should work like this :  

TheInteger = Cint(TheString)

Now, what hapens in my code , is that I declare a variable and do some string type manipulation on it, after I have my result , I attempt to convert it to Int.

Now, what happens is that the moment that convertion takes place ,
the DLLHost process on my machine goes to 99% CPU usage and stays there for a while; it eventually goes down to normal ??

So , phseudo for this is as follows :

Dim TheStringVariable
  <Do some stuff with that variable > 
  <like using the Left() and Right() functions>
  <to extract values>

Now, Declare Variable number two :

Dim MyIntegerValue

MyIntegerValue = CInt(TheStringVariable) <--- This gives me headaches ?

Any help / pointers will be greatly appreciated !

Regards
 Engwi
0
Comment
Question by:Engwi
  • 6
  • 4
11 Comments
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10772436
try

dim myIntegerValue as INTEGER
MyIntegerValue = CInt(TheStringVariable)




-Brian
0
 

Author Comment

by:Engwi
ID: 10772486
BrainGEFF719

Thanks for the comment , will try that ..

Something else I did not mention is the fact that , if I replace the Variable , TheStringVariable with something like  : "1234" then
all is fine.

Taking this in consideration, I thought that the data in "TheStringVariable" was causing the issue ... maybe something or some char that cant be converted to Int ??

I did a Responce.Write(TheStringVariable) but the content is fine ??

Any other thoughts ?

Regards
 Engwi
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10772502
try

if isnumeric(CInt(TheString)) = true then
 'its okay as an integer
end if
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 5

Expert Comment

by:KarcOrigin
ID: 10772509
Hi,

In ASP all the variables are considered as a variant so you can do any sort of String manipulations without converting the variable to the Int or String

Sorry I am not 100% sure about it but just give a try

Thx
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10772528
They should be variant if you dont define them.

Dim X                      <-- Variant
Dim X As Integer      <-- Integer
Dim X As String        <-- String



-Brian
0
 

Author Comment

by:Engwi
ID: 10772565
Brain

Dead right , but some other weird thing is that I couldn't get the conditions in one of my loops to realize that I am working with integers.

I had to do a quick numerical calulation on those so that the ASP knew I was talking about ints.

It did not automatically asume that the variant will be used as an Int in the expression... Or am I doing something wrong ??

Regards
 Engwi
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10772575
dim Number AS STRING
number = "12345"
number = left(number,2) 'number = 12
number = cint(number)
number = number +1 'number = 13
number = cstr(number)
number = number & " months is too many!"

response.write number



try that code and tell me how it goes :)
-Brian
0
 

Author Comment

by:Engwi
ID: 10772790
Brain

Ok , next thing is that if isNumeric(Cint(MyString)) = True
gives me a type mismatch error ??

How can that be , I just manipulated this Varaible by working with string functions ??

Regards
 Engwi
0
 
LVL 19

Accepted Solution

by:
BrianGEFF719 earned 20 total points
ID: 10772806
document.write IsNumeric(CInt(MyString))



try that, it should print either 1 or True.


-Brian
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10772813
sorry it should be

response.write


-Brian
0
 

Author Comment

by:Engwi
ID: 10773131
BrainGEFF719

It might help If I stop expecting the ASP to cast a BLANK STIRNG to an Integer !! :-)

Problem solved , your last comment led me to discover my problem.

Thanx again !

Regards
 Engwi
 
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question