Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enumerations can use Reserve Words!

Status
Not open for further replies.

LlomaxX

Programmer
Nov 7, 2002
64
US
Here's a little news that suprised the heck out of me. Did you know you can create Enumerations using reserved words in VB6? Neither did I. Imagine my suprise when all of a sudden my tested code stopped working, and I tracked it down to my Date function, which is supposed to return the date portion of the system time. Instead, Date would return 1. If I assigned Date to a date variable, I got a date of 12/31/1899! We tracked the problem to this:

Enum MPSTextBoxPasteType
AlphaNumeric
Date
Numeric
End Enum

The Date function had been replaced by the Date enum value of 1. Sure, I could have avoided the problem by qualifying the Date function with VBA.Date, but who does that?

If you want to have some fun with your fellow coders, place the following in a public module somewhere in your program:

Enum Gotcha
IsNumeric
IsEmpty
IsNull
Date
Time
Now
.
.
.
End Enum

...you get the idea. Anything that you would pass a value to, such as IsNumeric, all of a sudden won't compile, and things that don't require an argument, such as Now, return strange results.

I'm sure Microsoft will tell you it's a feature. I guess that's why everything is an object in .Net...so that you have to qualify everything and this won't happen. It just really suprised me that VB6 would allow you to use reserved words such as these as Enum values.

Just FYI.
 

Therefore, it's a good idea to use the full identifier:

VBA.IsNumeric()
Gotcha.IsNumeric






[/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
I've heard (never tried it, though) that you can do the same dirty tricks with plain modules. You can define a module called "Err", for instance. If you give it the same properties and methods as the Err object, Every call to the Err object executes the routines in your module instead.

Best regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top