From the course: Visual Basic Essential Training

Unlock this course with a free trial

Join today to access over 24,500 courses taught by industry experts.

Create custom constants

Create custom constants

- [Instructor] Declaring a constant is straightforward. You use the constant keyword, C-O-N-S-T, instead of the dim keyword. Now, typically constants are declared either at the class level or more likely they're declared in a module. Modules are shared across multiple files, so if you put your constants in a module, then you can use it throughout your project. So here's an example of how I would do that. I'm declaring a public constant in my class that is called DocFileExtension. It's a string, and here's the value that's assigned to that constant. Remember that once the value is assigned, you can't change the value. Here's an example where I'm doing a local constant. That's very rare, you don't typically see that, but I did it for the demonstration. Want to talk about names here. This is Microsoft's suggested naming convention, which is Pascal casing, where every letter in the word is capitalized. But you'll see this line of code, line nine, you'll see this a lot in classic visual…

Contents