Classic Visual Basic (VB 6 and earlier) FAQs
The following is a list of frequently asked questions for VB6 and VB5, etc.
If you click on one of the questions below, you will be taken to a page that contains at least one possible solution to the problem, and an explanation that you can hopefully understand. If you think something within the FAQ section needs a better explanation, please let me or the thread poster know via our PM (private messaging) system.
Please note: "Classic VB" is the name commonly used for Visual Basic 6/Visual Basic 5/etc, which is what these FAQs are designed for. If you are looking for help with the 2002 or later (including "Express") versions of VB, please see the relevant forum here.
Coding standards/Good Practice
Data types/Variables (including working with Strings, Dates, and Arrays)
Closing your forms/program
Dealing with Errors
Working with Other Programs (includes DOS commands)
Optimising (making your program faster/more efficient)
API (=Application Programming Interface, basically functions built in to Windows)
Other FAQ pages that include Classic VB:Database Development FAQ
Office Development FAQ (Excel/Word/Outlook/...)
Games and Graphics FAQ
Networking FAQ (Winsock etc)
Application Deployment FAQ (installation packages, etc)
- Dec 2015 : [Forms] How can I deal with DPI issues? (eg: Windows 10 automatically resizing forms)
- Oct 2010 : [General] Squeezing the most out of Randomize and Rnd
- Apr 2010 : [General] Where can I get VB6? Is starting to learn VB6 a good idea?
- Where can I get VB6? Is starting to learn VB6 a good idea?
- Where can I find the help files (aka MSDN library) for VB 6?
- How can I use Random numbers? [Tutorial]
- for ways to get a bigger range for Randomize, and an alternative to Rnd, see: Squeezing the most out of Randomize and Rnd
- What are Events and how do I use them?
- How can I tell why my code isn't doing what I expected?
This is done by a process known as Debugging. See Using VB6 debug [Tutorial] for details and explanations.
- How can I allow only one instance of my application to run at a time?
- How do I Pause my program?
- How can I tell which folder my program is running from?
- How can I use the mouse-wheel in VB?
(to scroll the code window, or to make use of the mouse-wheel in your programs)
- Why doesn't my program work on another computer?
- What do I need to do to make sure my program works in Windows Vista?
- How can I change the screen resolution (so my form looks good)?
See "How can I make my form look the same at different sizes?" below (in the Forms section).
- How can I use command line parameters in my program?
- How can I get the source code of a compiled VB file (.exe/.dll/..)?
- Can I use VB6 to make a program for mobile phones/PDA's?
Coding standards/Good Practice
- What is indenting, and why should I do it?
- Why should I comment my code? How to make my code readable?
- What is Option Explicit, and why should I use it?
- Why shouldn't I use "Dim .. As New .."?
- Also see the article Why is using the 'End' statement (or VB's "stop" button) a bad idea? (from the Closing your forms/program section).
- Also see the article Where should I store the files that my program uses/creates? (from the Files section).
- Also see the Dealing with Errors section, particularly "My program works, so does Error Handling really matter?" and "What is wrong with using "On Error Resume Next"?"
- How do I put the " character into a string?
- What do #, $, !, &, @, % mean after a variable name (or number)?
- What is a String? (includes explanations of useful string functions, such as Split and Join)
- What's wrong with Dim x, y, z As Long ?
- What is the difference between Dim/Private/Public/Global/Static/Const?
(or "where can I use a variable I declared?")
- Why are my dates not working properly? (or 'How should I work with dates?')
- What is datatype coercion?
- Why are my dates/numbers giving me the wrong values?
See "How do I handle different locales?" below (in the Miscellaneous section).
- What is an Enum, and how can I use it?
(or: "How can I create a variable/parameter which has a list of possible values that I specify?")
- What are arrays and how do I use them?
- How do I check if array has been initialized?
- What methods are there to sort an Array? (CodeBank thread)
- How do I use multiple colours/fonts in a single textbox? (or "How do I use a RichTextBox?")
- How can I change the Color of a command button, or show a picture on it?
- How can I have a Timer interval of more than a minute?
- How can I make new controls at run-time? [Tutorial] (3 methods, including control arrays)
- How do I detect if an index exists in a control array?
- How can I use a progress bar?
- How can I pass a control (textbox/listbox/..) to a sub or function?
- What controls can I use to input a date/time?
- How can I make my controls show in Windows XP styles?
See "How can I make my form use Windows XP Styles?" in the Forms section
- How can I move/resize my controls to suit the current size of the form?
See "How can I make my form look the same at different sizes?" in the Forms section
- Other articles on Controls (such as adding a horizontal ScrollBar to a ListBox) can be found in the API section and the Forms section
- How can I make my form look the same at different sizes? (see also the DPI article below)
- How can I deal with DPI issues? (such as Windows 10 automatically resizing forms)
See Tutorial: Being DPI Aware from our Tutorials forum
- How do i keep a form on top of others?
- How can I Hide/Unhide the form's "X" button
- How can I make my form use Windows XP Styles? (using a Manifest file)
- Other articles on Forms can be found in the Closing your forms/program and API sections