Eliminating Magic Numbers in VBA with George Hepworth
Please join us for our Monthly Chapter Presentation , at 6:30PM Pacific (UTC -8)
Moved to accommodate Geoffrey L Griffith’s follow up presentation on Com Add-ins in January.
Eliminating “Magic Numbers”
If you’ve ever taken over an existing Access Relational Database Application, you might have encountered this problem. You find code with numbers like this:
lngPublisherID = Nz(.cboPublisher, 60)
What does 60 mean? Where did 60 come from? Why isn’t it 0? What did the original developer mean?
Compare that to this version:
lngPublisherID = Nz(.cboPublisher, enuDefaults.defPublisher)
And the light comes on. 60 is the Primary Key of the default Publisher assigned when the actual Publisher is unknown.
Replacing “Magic Numbers” is a self-documenting way to make your code more accessible to the next developer who looks at your code.
I’ll provide examples of places where I’ve found it relatively quick and easy to improve code with self-documenting alternatives to Magic Numbers.
In addition to Enums, I’ll introduce an class-based approach. Yes, after all these years, I’m finally getting my feet wet with Classes in VBA.
Bring to the meeting your own examples and ideas about making code more readable and understandable.
Access Pacific holds FREE Q&A webinars the First Thursday of every month, from 6:30 pm to 7:30 pm Pacific.
AUG Access Pacific Calendar .ics file
==============================================================================
Please prepare ahead of time by downloading Zoom, if you don’t already have it.
Get Zoom
To join our meetings, please use the following link and phone number or use your computer’s speakers with audio:
When it’s time, join the meeting from here:
Join Zoom Meeting
If you are asked:
Meeting ID: 852 1966 9601
Passcode: 123456
Dial by your location
+1 253 215 8782 US (Tacoma)
+1 346 248 7799 US (Houston)
+1 669 900 9128 US (San Jose)
+1 301 715 8592 US (Washington DC)
+1 312 626 6799 US (Chicago)
+1 646 558 8656 US (New York)
Meeting ID: 852 1966 9601
Passcode: 123456
Find your local number