Say I want to make a bike designer program in Excel VBA. I have a class object ( cBike
) that has some default settings. Now I want to make a form (for example, the one in the picture) that can be used to change these parameters before storing the bike in the database. The (sub) storage method is in cBike
.
I could save the object as a public variable in the form code, for example:
Public objBike As cBike Public Sub StoreBikeToDatabase() 'database storing code goes here End Sub
While this works, I have seen many people argue against using public (global) variables. I'm not quite sure why, except for the fact that if you have too many global variables, your code will be messy.
Alternatively, I could forget the object and use the values ββfrom different form controls, rather than the properties of the module of the cBike
class. However, this seems like a slightly awkward solution.
My question is: which of the above solutions is the best, if any? And if none of them, then what should I do instead?
Update: I would strongly recommend that you read both the accepted answer and the one next. Both answers have some great ideas, and over them are added additional code examples that can be used for others with questions similar to mine.
source share