Solved

Asp "typecast" or convert string to int

Posted on 2004-04-07
11
1,188 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
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!

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

624 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