Solved

Asp "typecast" or convert string to int

Posted on 2004-04-07
11
1,180 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
Comment Utility
try

dim myIntegerValue as INTEGER
MyIntegerValue = CInt(TheStringVariable)




-Brian
0
 

Author Comment

by:Engwi
Comment Utility
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
Comment Utility
try

if isnumeric(CInt(TheString)) = true then
 'its okay as an integer
end if
0
 
LVL 5

Expert Comment

by:KarcOrigin
Comment Utility
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
Comment Utility
They should be variant if you dont define them.

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



-Brian
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:Engwi
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
document.write IsNumeric(CInt(MyString))



try that, it should print either 1 or True.


-Brian
0
 
LVL 19

Expert Comment

by:BrianGEFF719
Comment Utility
sorry it should be

response.write


-Brian
0
 

Author Comment

by:Engwi
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now