Question Locked

assist with convert issue

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hello,

I have a file that holds the keys (parameters) for my script. I read the file in and load the values into an array.

During the run of my code, I compare array value to value returned from a datediff call and the code returns all the entries weather or not they match. I did a convert.toint32 on the array value and it still does not filter.

code example 1
...
keyage = convert.toint32(keyarray(2))
...
if idiff < keyage then
...

doesnt work.

If I just type the value it works fine.

code example 2
...
if idiff < 30 then
...

does work.

What did I miss?

8 replies

by slayer_

Looking at the values in the array before you convert it?

Without knowing the quirks of the language, or what language your using, I can't be of much help.

by sirjoel

I am using VisualBasicScript

yes, I have printed the values in the array. I suspect that it is a text value in the array and I would assume that the idiff is a int.

even after the convert it still shows it is 30 but they filter on the if lets all values pass.

by slayer_

Try one of those, Val will convert string data and automatically error check, while cint blindly tries to convert and explodes horriablely if it cannot convert.

keyage = cint(keyarray(2))

Also, make sure when idiff was given its value, it was cint'd aswell, otherwise it could be a string.

You gotta cast EVERYTHING when working in VBScript.

by tony hopkinson

may be a mistake, could be an object for instance.
I'd make a point of making them both integers, the do the test, otherwise you are hoping that your code get's interpreted correctly.
If it is casting to do the comparison

If !(keyDiff >= idiff) might provide a clue.

by sirjoel

I did a Cint on both values and then the compare and now it works fine.

Thanks for the help.

by slayer_

Just open up the response, and at the bottom of the response is a "Mark as Helpful" button.

This will allow others to quickly find the answers to the issue.

This discussion is closed to new replies.