PDA

Click to See Complete Forum and Search --> : Index to FAQ's: Classic VB (VB6 and earlier)


si_the_geek
Jul 5th, 2005, 06:33 PM
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 (http://www.vbforums.com/forumdisplay.php?f=25).


Sections in this Page
General
Coding standards/Good Practice
Language syntax
Data types/Variables (including working with Strings, Dates, and Arrays)
Controls (TextBoxes/ListBoxes/etc)
Forms
Closing your forms/program
Dealing with Errors
Files
Registry
Printing
Multimedia (music/pictures/etc)
Working with Other Programs (includes DOS commands)
Optimising (making your program faster/more efficient)
API (=Application Programming Interface, basically functions built in to Windows)
Miscellaneous

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)


____________________________________________________________
Recent Additions

Oct 28 2010 : [General] Squeezing the most out of Randomize and Rnd
Apr 15 2010 : [General] Where can I get VB6? Is starting to learn VB6 a good idea?
Mar 22 2010 : [Coding standards/Good Practice] What is indenting, and why should I do it?
Mar 3 2010 : [Controls] How can I have a Timer interval of more than a minute?
____________________________________________________________

General
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?
up to Section list

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"?"
up to Section list

Language Syntax

How do I put the " character into a string?


What do #, $, !, &, @, % mean after a variable name (or number)?
up to Section list

Data types/Variables
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)
up to Section list

Controls

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 sectionup to Section list

Forms

How can I make my form look the same at different sizes?


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
up to Section list

si_the_geek
Sep 19th, 2007, 06:38 PM
Closing your forms/program

How should I close my form/program/class?


Why is using the 'End' statement (or VB's "stop" button) a bad idea?


How can I show a confirmation message when my form is closing?


How can I tell why my form is closing?


Also see the article "How can I detect/fix memory leaks? in the Miscellaneous section
up to Section list

Dealing with Errors
What does this error mean, and how do I fix it?


My program works, so does Error Handling really matter?


Why do errors crash my program, and how can I stop that from happening? (making an Error Handler)


What is wrong with using "On Error Resume Next"?


Why does my program give me errors running as an Exe but not in the IDE?
up to Section list

Files

How can I check if a file exists?


How can I read/write a text file?
How to do basic manipulation of text files [Tutorial]


How can I edit a text file without opening it?


How can I show an "Open" or "Save" dialog?
See this tutorial (which focuses on the dialog), or this tutorial (which also opens/saves files using code similar to the articles above).


How can I read/write an .Ini file?


Where should I store the files that my program uses/creates?


How can I delete a file?


Other articles on files (such as opening a file in its default application) can be found in the <a href="#otherprograms">Working with Other Programs</a> sectionup to Section list

Registry
How can I work with the Registry?
See Working with Windows Registry using Visual Basic 6 from our Tutorials forum
up to Section list

Printing
How can I Print from my program?
See this tutorial (http://www.freevbcode.com/ShowCode.Asp?ID=3646) (ignore/remove any ÿ characters from the code examples!)


How can I print less than a whole page?
See this article (http://support.microsoft.com/kb/175083) from MSDN
up to Section list

Multimedia
How can I play MP3/WAV songs?


For other work with audio, see the Sound and DirectXSound Tutorial
(note that it is not finished, but contains lots of info!).


What picture types does VB support? (or: why wont VB load this picture/icon?)


How can I create/find icons to use in my program?


For other graphics based issues, see the Games & Graphics FAQ
up to Section list

Working with Other Programs
How do I open a file/web-page in its default application?


How do I run DOS commands from VB?
(note that most DOS commands have VB equivalents, eg: in DOS you have Copy and in VB you have FileCopy)


How do I shell a command line program and capture the output?


How can I use Excel from VB? [Tutorial]
(see the Office Development FAQ for other topics relating to MS Office)
up to Section list

Optimising

How do I optimize my code?


How do I use one dimensional arrays instead of multidimensional?


I want to use IIf but it is slow!
up to Section list

API
How do I get the current Windows user name?


What is a window handle (hWnd) and what is it used for?


How can I find a window (hWnd) outside of my program?


How can I retrieve a list of running processes?


Examples of more API functions can be found on a separate FAQ page (Warning: this page takes a while to load!)
The following links open just the relevant post from that thread:


How to get a windows hWnd from caption/class name (http://www.vbforums.com/showpost.php?p=1263162&postcount=1)

Forms/Windows:
Set Window Parent (http://www.vbforums.com/showpost.php?p=1263162&postcount=1) (put one form inside another)

Creating odd shaped forms/controls (http://www.vbforums.com/showpost.php?p=1263227&postcount=5)

How to limit a form's size (min and max) (http://www.vbforums.com/showpost.php?p=1263307&postcount=7)

Transparent Form (http://www.vbforums.com/showpost.php?p=1750978&postcount=35)

Move Form With No Border (http://www.vbforums.com/showpost.php?p=1750978&postcount=35)

System Tray and Title Bar Button (http://www.vbforums.com/showpost.php?p=1263274&postcount=6)


Controls:
A few simple TextBox functions - Line count etc (http://www.vbforums.com/showpost.php?p=1263481&postcount=17)

Find an list item in a ListBox by its string value without looping (http://www.vbforums.com/showpost.php?p=1263466&postcount=14)
(ComboBox version) (http://www.vbforums.com/showpost.php?p=1263469&postcount=15)

Add Horizontal Scroll bar to Listboxes (http://www.vbforums.com/showpost.php?p=1750978&postcount=35)

How to Select/Deselect All the items in a FileListBox/ListBox/ComboBox. (http://www.vbforums.com/showpost.php?p=2613172&postcount=39)

How to Limit the Character Length of a Combo box. (http://www.vbforums.com/showpost.php?p=2613172&postcount=39)

mouseover effect on command buttons (http://www.vbforums.com/showpost.php?p=1753635&postcount=37)

Simulate MouseEnter and MouseLeave events (http://www.vbforums.com/showpost.php?p=1263423&postcount=9)


Information:
Get Windows version (http://www.vbforums.com/showpost.php?p=1263414&postcount=8)

Get computer name (http://www.vbforums.com/showpost.php?p=1263429&postcount=10)

Get the Windows, System, and Temp directories (http://www.vbforums.com/showpost.php?p=1263439&postcount=11)

Detect whether a program/ActiveX control/ActiveX DLL is running in the VB6 IDE (http://www.vbforums.com/showpost.php?p=1263450&postcount=12)



Other:
Extracting a file's icon (http://www.vbforums.com/showpost.php?p=1263184&postcount=2)

GDI (graphics) functions (http://www.vbforums.com/showpost.php?p=1263188&postcount=3) (the declarations) (http://www.vbforums.com/showpost.php?p=1263190&postcount=4)

Arrange Desktop Icons (http://www.vbforums.com/showpost.php?p=2022148&postcount=38)

Determine if a COM Port is Available (http://www.vbforums.com/showpost.php?p=2022148&postcount=38)


up to Section list

Miscellaneous

Does Visual Basic 6 support Unicode?


How can I use Unicode with forms and standard controls?


How can I detect/fix memory leaks?


How do I handle different locales?


How do I use Resource Files? [Tutorial]


How can I set my exe icon using a resource file?


How do I make properties? (for a Class / Form / UserControl)


How can I show the 'link select' (hyperlink) mouse cursor?


Why is TRUE equal to -1 and not 1?


How do the ReadProperties and WriteProperties work? (PropertyBags)


Why can't I use WithEvents on arrays of objects?
up to Section list


If you can think of a "frequent" question (and preferably an answer to it as well) that you think should be added to the FAQs, please see this thread.