Visual Basic 6 Tips


Declare All Variables & Option Explicit

Declare all variables to save programming time by reducing the number of bugs caused by typos (for example, aUserNameTmp vs. sUserNameTmp vs. sUserNameTemp).

In Visual Basic 6, go to Tools > Options > Editor tab, then turn on "Require Variable Declaration." This should add "Option Explicit" to the General Declarations section of any new modules or forms you create. You can also manually type in "Option Explicit" , without the quotes, at the top of the code for each form/module that has already been created.


[ Top ] [ Home ]



Keep Your Code Portable by Using App.Path

Would you like to avoid having to modify the path in your Visual Basic program, every time you need to run it from a different subdirectory or drive?

Use these steps to make your life easier:

  1. Add the following commands to Sub Main() in the main module or to Form_Load() in the main form.

       ChDrive App.Path
       ChDir App.Path

  2. Wherever you have hard coded the full path to a file, remove the path leaving just the filename.

    For example; Change “C:\Data\VisualBasic\VideoStore.mdb” to “VideoStore.mdb”.

  3. Make sure that the file being accessed is in the same location as the project that needs to access it.


[ Top ] [ Home ]


Copyright ©1996 - 2018 Chin. All Rights reserved Instagram Twitter YouTube Reproduction without explicit permission is prohibited. See: Terms of use