Trying to compare temp_i and i. They are both 1. The compare says they are different. Why? I suspect this has
something to do with variants. Thank you.
Please Login or Register to view this content.
Trying to compare temp_i and i. They are both 1. The compare says they are different. Why? I suspect this has
something to do with variants. Thank you.
Please Login or Register to view this content.
I am not sure what you are attempting with your code, but after you load minus one into the temp_v variable, you overwrite with CInt(i) and since i equals one, CInt(i) also equals one and, hence, you remove the minus one you placed in temp_v and replace it with (plus) one. That is why later on i and temp_v both equal one.
Last edited by Rick Rothstein; 12-05-2019 at 06:48 PM.
They should both be one, but I always get this message. It says they are not both 1. (or rather the don't equal each other)
Please Login or Register to view this content.
Here's my experimental code as is. This should run as a function. I must be doing something
bad in here. Thanks for helping.
Please Login or Register to view this content.
I still do not see what problem you are trying to convey. In your code, this line...
temp-v = -1
is doing nothing since the next line of code overwrites it with, basically, the value of i (CInt does nothing when the value passed into it is already an interger)... so i and temp_v will always display the same value in that last message box.
It's experimental. My question concerns only the result of the <> test which says the two variants are not equal.
The -1 is an artifact. It used to be "dog". I was reading about the variant data type and they mentioned initial variant
assignments usually set the type.
Is there some reason my <> fails?
Sorry if this was not clear. My bad. Thanks for helping.
Good. It should work but doesn't here. It always says they are unequal. There must be something going here I don't see. Thanks for your help.
First print says values are equal. Even so, "why am I here" says they are not.
Please Login or Register to view this content.
How are you calling the function?
Aren't you testing the string value like
?Please Login or Register to view this content.
otherwise, no idea.
I changed
dim temp_v as variant
to
dim temp_v as integer
and everything is now ok. Why the comparison fails is beyond me. Thanks for all help. It's still a mystery but the code now works.
How are you calling the function? If you pass "1" rather than 1, you would get the behaviour you are describing.
Rory
That must be it. I went back and changed temp_v to a variant and "cast" temp_v this way
temp_v = CInt(i)
if i <> CInt(temp_v) then ....
The above appears to "make" the if compare integers. Thanks all. This thread is closed. Thanks to all.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks