Solved

Asp "typecast" or convert string to int

Posted on 2004-04-07
11
1,187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

734 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