Most FAQs (including this one) are available at the anonymous ftp archive
site rtfm.mit.edu. All four parts of the VB FAQ may be found in the
directory /pub/usenet-by-group/comp.lang.basic.visual.misc/.
As the FAQ maintainer, I don't have time to explore all of the aspects of
Visual Basic. I rely on your submissions to improve the quality and
inclusiveness of this document. If you have found a VB hint, tip, trick,
work-around, etc., please write it up and send it to me!
Peter Millard millard@buffnet.net - VBDOS FAQ maintainer
How do I use (create) global variables in VBDOS?
-
VBDOS provides the user with two types of global variables.
These are both used in declarations of variables.
To share variables between all subs and functions in a specific
module, use the SHARED keyword. This makes that specific
variable global _in that module_. For example:
DIM SHARED CancelFlag AS INTEGER
would make the variable CancelFlag a global variable in that
module.
To share global variables between separate modules, use the
COMMON keyword. For example:
COMMON SHARED CancelFlag AS INTEGER
would make the variable global between all modules that this
common statement appears in, and since we are using the
SHARED keyword also, this will also be shared in all the subs
and functions in the modules which this declare statement
appears. All COMMON statements must be matched between
modules which the variables should be global in. For example,
if you have one set of 10 COMMON statements in one module,
and a different set of 10 COMMON statements in another
module in the same project, you will get a 'Type Mismatch
Error'. Make all COMMON blocks identical in all the modules
in a specific project. (See Misc. Programming Tips Below).
[Top of Page][Table of Contents]
Does VBDOS make standalone .exe files?
- VBDOS can compile programs in two different ways (user
option). It can compile programs to use a RUNTIME file (like
a DLL) or can be compiled as a standalone .exe file.
[Top of Page][Table of Contents]
What is the current version of the VBDOS compiler?
- VBDOS is currently at version 1.0
[Top of Page][Table of Contents]
How do I not make a text box beep when I hit the enter key?
- Put "something else" in your _KeyPress event, depending on
what you really want. This code example makes *nothing*
happen, for an extended period of time:
Sub Text1_KeyPress (KeyAscii As Integer)
If KeyAscii = 13 Then '13 is Key_Return
KeyAscii = 0 '0 (zero) is nothing
End If
End Sub
This might not be a very nice thing to do, since your users
usually have some intention when they press Enter. Usually
they will want to jump to the next control, like the Tab key
does. You will then change the line KeyAscii=0 to KeyAscii=9
(Key_Tab) in the example above.
BTW, you'll also find this in the Microsoft VB
KnowledgeBase. They add that you should set the MultiLine
property to False. Of course.
Click here to get a copy from Microsoft (1563 KB).
Click here to get a copy of the FULL TEXT Searchable version (4205 KB)
[Top of Page][Table of Contents]
How does Visual Basic handle shelled tasks? How do I find out when they are finished.
- In VBDOS, all shelled tasks are completed before control
returns to the program. No tasks are done while the DOS
command is being executed.
[Top of Page][Table of Contents]
How do I break lines of long text into multiple lines of text in the msgbox?
- Use the append a chr$(13) to the end of the string to break
lines into multiple lines. EG:
msg$ = "This is line 1" + chr$(13)
msg$ = msg$ + "This is line 2"
MSGBOX msg$
[Top of Page][Table of Contents]
What's the difference between MODAL and MODELESS forms?
- Modal forms are forms which require user input before any
other actions can be taken place. In other words, a modal form
has exclusive focus until it is dismissed. When showing a
modal form, the program pauses at the SHOW command until
the modal form is either hidden or unloaded. The internal
MSGBOX and INPUTBOX$ forms are examples of modal
forms. To show a form modally, use the syntax:
MyForm.SHOW 1
Modeless forms are those which are shown but do not require
immediate user input. Most child forms (in a MDI application)
are typically modeless. To show a form modeless, use the
syntax: MyForm.SHOW
[Top of Page][Table of Contents]
When/Why should I use Option Explicit?
- Opinions vary greatly on this subject. The main reason to use
the OPTION EXPLICIT statement at the top of all modules is
to minimize the amount of bugs introduced into your code by
misspelling a variable name. Most variants of BASIC
(including VB) have the capability to create variables 'on the
fly' (without any declarations). This capability can be a double
edged sword.
At the minimum, it is suggested to use the DEFINT A-Z
statement in leu of OPTION EXPLICIT. This statement will
cause any variables which are created on the fly to be created
as integers as opposed to single precisions. (Integers take up
less memory).
The OPTION EXPLICIT statement causes VB to 'disable' it's
ability to create variables on the fly. Thus, all variables must be
declared using a DIM or REDIM statement. All variables not
declared will cause an error when the OPTION EXPLICIT
statement is used. This will eliminate any bugs when a variable
is misspelled.
[Top of Page][Table of Contents]
Why doesn't PRINT or CLS from a frm module work?
- To print information to the screen bypassing the desktop, the
commands must be issued from a .BAS module. All
PRINT/CLS output from a form module is directed to the nul:
device.
[Top of Page][Table of Contents]
How do I invoke FKey traps which won't be triggered by other keys which share the same KeyCode?
- To trap the only FKeys in events you need to use a
combination of the KeyDown, KeyPress, and KeyUp
events.
The basic concept for this is that _all_ keys trap the UP &
DOWN events, while only 'printable' characters trigger the
KeyPress event. Thus, when a character key is pressed, it will
trigger the KeyDown, the KeyPress, then the KeyUp events (in
that order). While a FKey (or arrow, or tab, etc...) will trigger
the KeyDown, then the KeyUp events (in that order).
The following code uses a textbox tag property to decide
whether a printable character is pressed or not.
SUB Text1_KeyDown()
Text1.tag = "key"
END SUB
SUB Text1_KeyPress()
Text1.tag = ""
END SUB
SUB Text1_KeyUp()
IF Text1.tag = "key" then
'--PUT F-KEY HANDLER HERE----
ELSE
'--PUT OTHER KEY HANDLERS HERE----
END IF
END SUB
[Top of Page][Table of Contents]
How do I boost memory available to VBDOS.EXE (the IDE)?
-
- Try to have as much EMM available as possible. VBDOS.EXE allocates subroutines & functions which are < 16K into EMM.
- To make more conventional mem availble, use the /S:n
switch. This will make VBDOS.EXE use a specific
amount of conventional memory. A good compromise
between speed & memory is /S:340. The lower the n
value, the slower the environment runs.
- Running out of DGROUP usually causes most 'out of memory' errors. Possible causes are:
- Too many subs & functions exist. Each one takes up 46 bytes of DGROUP.
- Large static arrays. All static arrays are stored in
DGROUP. If a DIM statement is for a COMMON
SHARED statement, the array becomes static. Make
the COMMON SHARED statement appear before
the DIM statement to make the array Dynamic &
therefore will not be stored in DGROUP.
- Variable Overhead. Each var has a 4 byte overhead
for _each_ module. For multiple modules projects
which use lots of Global (COMMON) statements,
this overhead is repeated for _each_ module.
- Possible causes for running out conventional memory:
- Not enough EMM.
- Subs or functions which exceed 16K.
- Large arrays. Non-variable length string arrays can
be stored in EMM using the /ea switch.
[Top of Page][Table of Contents]
My program runs in the IDE, but won't run when compiled??
-
- Arrays are dynamic by default in the IDE, but when they
are compiled, they are static by default. Therefore, they
are stored in DGROUP instead of the far heap. Use
'$DYNAMIC to make all arrays dynamic or use REDIM
instead of DIM.
- Program generates a "program memory overflow" during
compile. You need to break a single module into multiple
ones.
[Top of Page][Table of Contents]
MISC. Programming TIPS:
-
- When useing the form designed, to continuously draw
controls of a specific type, hold down the control key
when clicking on the appropriate control from the tool-
box.
- Use the INCLUDE statement to manage large numbers of
COMMON SHARED statements, user defined data types,
or external function DECLARES. To use an include file,
simply put all the VBDOS statements that will be shared
into a single file. Save the file as something appropriate.
(Typical naming convention is to use an extension of .BI
for basic include files). Then simply insert the line:
'INCLUDE: 'foobar.bi'
into either your .BAS module, or the module level code
in a form.