Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1192
  • Last Modified:

Asp "typecast" or convert string to int

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
Engwi
Asked:
Engwi
  • 6
  • 4
1 Solution
 
BrianGEFF719Commented:
try

dim myIntegerValue as INTEGER
MyIntegerValue = CInt(TheStringVariable)




-Brian
0
 
EngwiAuthor Commented:
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
 
BrianGEFF719Commented:
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!

 
KarcOriginCommented:
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
 
BrianGEFF719Commented:
They should be variant if you dont define them.

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



-Brian
0
 
EngwiAuthor Commented:
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
 
BrianGEFF719Commented:
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
 
EngwiAuthor Commented:
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
 
BrianGEFF719Commented:
document.write IsNumeric(CInt(MyString))



try that, it should print either 1 or True.


-Brian
0
 
BrianGEFF719Commented:
sorry it should be

response.write


-Brian
0
 
EngwiAuthor Commented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now