variant type used improperly?
Hello everybody. I often come across pieces of code wherein the variant type is used seemingly without reason. I'll show you one example from Microsoft (so it's not supposed to be trash code):http://support.microsoft.com/kb/137038/en-us
You'll find that the Ret variable (which is declared as variant) is used to store the return value from the GetPrivateProfileString API call. However, that call no question will return a long. So why did they use the variant type? And this is just one example. Like I said, there's plenty of cases where variants are gonna receive well-defined values. Anybody knows why this happens? :confused::confused::confused:
Thank you.
Re: variant type used improperly?
Re: variant type used improperly?
It is just a code snippet to explain things to you. In your real code you would declare your variables according to your needs and judgements. It is very much possible that the snippet they have put there was a part of a larger program and they have just copied the relevent parts as it is without any changes.
Re: variant type used improperly?
it would appear that microsoft themselves tend to support the use of variant variables, prior to .net, that is why many of there scripting and VBA functions return variants, or variant arrays