According to the doc, the Variant.TypeLong
constant tells you that a Variant is of type Uint64 or Int64. But how can we know if we need to use the Variant.UInt64Value
property or the Variant.Int64Value
?
You can’t programmatically. You as the developer need to know, how to interpret the value and act accordingly.
Well, that pretty much defeats the purpose of the Variant type, isn’t it?
That’s all the beauty of implicit type. How could the variant know it must use Int64 if you give it a positive value ? The only way it will know it is an Int64 is if you pass it a negative value. Same thing between decimals and not.
Was it not Norman who said Variants bite like misbehaved dogs ?
The[quote=145547:@Michel Bujardet]That’s all the beauty of implicit type. How could the variant know it must use Int64 if you give it a positive value ? The only way it will know it is an Int64 is if you pass it a negative value. Same thing between decimals and not.[/quote]
Then, how does the Variant.Type know that a Variant is holding an Integer or a Double?
I’m well aware of the pros and cons of the Variant type. I’m aware that it can harm in many ways. I’ve already been bitten and learn from that. Back then,we were in another century…
Back to the OT.
Xojo is a strongly typed language. So I thought that the Variant type would get a hold of its data’s native type when i’m doing something like this:
Dim foo As UInt64
Dim bar As Variant = foo
The internal storage structure of UInt64 and Int64 should be same in the computer memory. For Int64, the most significant bit having value 1 would indicate negative values according to 2s complement. While for UInt64, any value would be a positive value, same as the binary magnitude, irrespective of the value of most significant bit.
I rest my case.
The quote you’re refering to is out of context.
Int64 vs Uint64 is a matter of interpretation
IF your code expects an unsigned value then use Uint64
If you code expects a signed value then use Int64
For instance is &h8000000000000000 = 9223372036854775808 (uint64) or -9223372036854775808 (int64)
Its the exact same bits just one interpreted as signed & one as unsigned
you can always write a
#if RBVersion >=2015 then
Check if VarType got upgraded
#endif
there in the code, so compiler sees it.
Its undocumented & unsupported
Please don’t use this mechanism and please don’t recommend people use undocumented & unsupported mechanisms
[quote=145562:@Michel Bujardet]
@Eric de La Rochette Xojo is a strongly typed language.
I rest my case.[/quote]
Using variants expecting an automatic type to do your job is not the right way to use a strongly typed language. YOU should know which type to use, define your variable as such, instead of complaining that the washing machine ruined your laundry.
But hey, it is your code. You can mess with it as you see fit …
Wow… That’s an agressive answer. I didn’t meant to hurt you. I wasn’t complaining, I was noticing and asking for advice.
After reading your post, I found your answer ironic because all I wanted to do was to keep the track of the type of a variable in order to use the right method to get the right type and value out of a Variant that is provided by a third party piece of code. Just to get my own code back on the track of the strong typed language that Xojo is.
That’s all I wanted. I surely wasn’t looking for a lecture about my coding skills…
[quote=145658:@Eric de La Rochette]Wow… That’s an agressive answer. I didn’t meant to hurt you. I wasn’t complaining, I was noticing and asking for advice.
After reading your post, I found your answer ironic because all I wanted to do was to keep the track of the type of a variable in order to use the right method to get the right type and value out of a Variant that is provided by a third party piece of code. Just to get my own code back on the track of the strong typed language that Xojo is.
That’s all I wanted. I surely wasn’t looking for a lecture about my coding skills… :)[/quote]
Sorry for the lecture. I have used PHP long enough to never use variants anymore if I can avoid it. PHP has no type at all, by the way, and it is a PITA.