Visual Basic 6.0 Notes


PushKeys

The PushKeys command is available for VB 5.0 and above only. This is the only reason I moved from VB 3.0 to VB 6.0. PushKeys works more than 100 times faster than the VB SendKeys commnad. However, the keystrokes appear to be queued until a DoEvents command is executed. Normally, this would not be a problem except that DoEvents stops the execution of the VB 6.0 application.

According to Microsoft, DoEvents returns control to the Visual Basic program after the operating system has finished processing the events in its queue and all keys in the SendKeys queue have been sent. The Sleep 32-bit API function is a subset of the DoEvents function.


I tried to develop a template in one directory and do a save as in another directory. I ended up modifying the wrong data and lost the template. There is no way to modify the directory where project members are saved except to delete and reload them. I have not yet figured out how to determine where exe's are created.


File Commands

There is no documented way to test for the existance of a file. Use Name "filename1" as "filename2" to rename a file.

Use the dir command.


Project Definition

How is a project defined? The top level file appears to be an ASCII *.vbg (Visual Basic Group Project) file which points to an ASCII *.vbp (Visual Basic Project) file. A project can contain several frm (form) and bas (Basic module) files. The filenames and paths are stored in the vbp file. This is the only place that these can be seen or edited.

Line Continuation

In order to continue a command on the next line, terminate the line with a space, underscore, enter.

Both of these should give the same result

   Dim Msg   ' Declare variable
   Msg = "1st part of string "
   Msg = Msg & "Next part of string "
   Msg = Msg & "Last part of string"

   Msg = "1st part of string " _
         & "Next part of string " _
         & "Last part of string"
Available starting with VB 4.0
Use the Object Browser to determine the methods and properties of objects.

VB has 34 base classes. Of these, 20 are UI controls, 7 are defined in Global (App, Clipboard, Forms, Licenses, Printer, Printers, Screen). The others are Form, MDIForm, Menu, PropertyPage, UserControl, UserDocument, VBControlExtender.


Setting Variables on a Form

Property functions let you create custom properties for forms and class modules. Properties are accessed using the PropertySet, PropertyGet, and PropertLet statements. First, declare the property as a form-level variable

   Private TempStr as String
Then add the following procedures to the form
   Public Property Let FormVariable(str as string)
       TempStr = str
   End Property
   Public Property Get FormVariable()
       FormVariable = TempStr
   End Property
The property is now set using
   Form1.FormVariable = "test"

Event Calling Sequence

For a Form
  Initialize --> Load --> Form_Activate 

Screen.ActiveControl is not valid during either Initialize or Load, but is valid during Form_Activate

Form_GotFocus appears to never get called.

Clicking a control generates 3 events in a control specific order.

Control Event Order
ListBox
CommandButton
MouseDown --> Click --> MouseUp
FileListBox
Label
PictureBox
MouseDown --> MouseUp --> Click
Form
TextBox
Unknown

Missing Features

These are some of the more common features missing from Visual Basic 6.0

Debug

You place break point by clicking in the Left-hand gray border. If a red dot appears, the program will pause and be displayed in the debug window when that line of code is executed.

In debug mode, double click a variable to see its value. Sometimes, simply pointing to a variable will display its value, but double clicking works on more variables.

In order to single step the program, you must first display the Debug Toolbar. This is hidden in View / Toolbars / Debug which is not visible on a 640x480 display unless you scroll the View menu to display the Toolbars selection. (In my opinion, this rates significantly below poor design. Scrolling a menu is never acceptable!)


File Types

*.frm Form Description
*.frx Form Extension file
Various strings, default data, etc.
Not text files
*.bas Library files
*.cls Code to create new objects
ActiveX Documents (pro)
ActiveX Designers (pro)
User Controls (pro)
*.vbw Windows Locations
*.vbg VB Group - Identifies the startup project
*.vbp Project files - Lists the included files, the name and path for the exe, who the software is licensed to

xx

When converting from VB 3.0 to VB 6.0, the common dialog controls changed. Things wrong with the FileOpen... dialog box. Humm, it seems that it is better to write your own and to blow off the weak standard dialog box. However, the properties and methods should still be as similar as possible. Perhaps both sets of constants (3.0 and 6.0) should be supported in order to simplify code migration.

xx

Visual Basic is dangerous. Several times now, I have generated small projects to test something, then copied the code to another directory to include it in a larger project. Suprise ... all the changes were made to the original code which I was trying to preserve ... not the copy.

The problem appears to be that the *.vbp (VB project) files contain hard coded paths, such as

Module=GlobalConstants; ..\..\..\Program Files\Microsoft Visual Studio\VB98\GlobalConstants.bas
Module=Module2; ..\TestDosApp\globcons.bas
must inspect this file yourself before doing any work.

It is a real pain that the project name can't be the same as the form name even though they have different extensions. Real languages provide more freedom.


Referencing a Form

The main help for the following is under Data Types. Object variables, such as CallingForm below, are allocated 4 bytes for a 32-bit address which points to the actual object. Variables are associated with objects by using the set command. The help suggests using specific classes rather than a generic parent (e.g. Form instead of Control) so that the compiler can perform error checking.

Fonts

When working with Courier New and a Picture Box, the fonts are irrational. If you set the fontSize = 8 it is actually set to 8.25!

xx


References


xx

I am trying to generate generic code which implements cut, copy, paste, and delete on text objects.
   Screen.ActiveControl.SelText 
can access the selected text, but how do I know if the ActiveControl is a text box and not a button? Well Screen.ActiveControl returns a control. However, there is no built-in help for control - no members, no properties, no parent, nothing. Neither the help file nor the fabulous Object Browser provides any information.

The help for ActiveControl contains a partial answer: TypeOf returns the object's type. However, the help for the TypeOf keyword points to If..Then..Else and provides no additional help at all. (The help for VB 3.0 and VB 6.0 are equally bad.) Searching the Object Browser for TypeOf returns No items found.

   ActiveForm.ActiveControl
does not work, it has no value even though it is the example used for the ActiveForm help example. Therefore, the rule is Don't trust the help files!

Additional TypeOf help is provided under Clipboard / checking data formats .

****************

It would make a lot more sense if the UI Controls had built-in overloaded virtual functions which handled these basic commands.

The whole point of object oriented programming is that you can treat an unknown object as a base object in the class hierarchy and execute overloaded methods without knowing, or caring, what the specific type of the object is.

VB 6.0 fails totally as an object oriented language.


Converting 3.0 to 6.0

Converting VB 3.0 to 6.0 is a real pain. For more info see VB_3_0_To_6_0.htm
Author: Robert Clemenzi - clemenzi@cpcug.org
URL: http:// cpcug.org / user / clemenzi / technical / Languages / VisualBasic/Notes.htm