troubleshooting Question

avoiding global variables

Avatar of anshuma
anshumaFlag for United States of America asked on
Visual Basic Classic
6 Comments2 Solutions356 ViewsLast Modified:


On one of the forms I have a button cmdMainMenu. On its click either of the two things should happen which are shown below. But I use a global variable  isForm1Hidden . Now this is the problem I can imagine that I will have to hide form1 at so many places in future and then I will have to set  "isForm1Hidden" at those places. Similarly when I will bring up the form again I will have to set it again.

This is a major problem , if I forget this somewher I will run into some other problems. How can I avoid this ?  
I am working on an old code with a very poor design and it has so many global variables for cases like this. I will appreciate if someone can help me with this

Private Sub cmdMainMenu_Click()
    Unload Form5
    If isForm1Hidden Then
     strBuildSQL = SelectQueryBuilder("Build_Number", "LU_Build")
     Set oBuildRS = ExecuteQuery(strBuildSQL)
     Call GeneralCodes.PopulateComboBox(Form1.cboBuild, oBuildRS, "Build_Number")
     isForm1Hidden = False
     errorinForm1 = False
    End If
End Sub
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros