Question

Locked

assist with convert issue

By sirjoel ·
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?

This conversation is currently closed to new comments.

7 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

have you tried....

by Slayer_ In reply to assist with convert issue

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.

Collapse -

more info

by sirjoel In reply to have you tried....

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.

Collapse -

What about the Val or cInt commands

by Slayer_ In reply to more info

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.

Collapse -

Val - no, Cint - Yes

by sirjoel In reply to What about the Val or cIn ...

thanks for the help.

Collapse -

Assuming that idiff is an integer

by Tony Hopkinson In reply to more info

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.

Collapse -

Thanks

by sirjoel In reply to assist with convert issue

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

Thanks for the help.

Collapse -

no problem, be sure to mark helpful responses as helpful

by Slayer_ In reply to Thanks

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.

Back to Software Forum
7 total posts (Page 1 of 1)  

Related Discussions

Related Forums