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.
formSave = Screen.ActiveForm.Caption
AppActivate DOSAppName$ ' Transfers control to the DOS application
PushKeys DOS_ScreenCapture$ ' Send keys to the active (DOS) application
' The following 4 lines of code are not needed in VB 3.0,
' These are needed so that the clipboard will be available
For i = 1 To 10 ' I tried various values - 1, 10, 1000 -
' 1 failed, 10 works sometimes, 1000 hung
DoEvents ' Without this - Error - Can't Open Clipboard
Next i
AppActivate formSave ' Without this, DoEvents hangs the application
' The following code never fails in VB 3.0, is intermittent in VB 6.0
tt$ = Clipboard.GetText()
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.
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.
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.
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
-
The PictureBox control is the primary
control to contain other controls. It can be Sunken 3D or Flat only. The Frame can also contain buttons, but is Flat or
Chiseled only.
-
There is no way to align any control to
the client except to write code.
-
The tutorials are hard to find. (Search
help for 'tutorial')
-
There are many missing controls - Status
bar, Progress Indicator
-
Buttons are operated with the space bar,
not the Enter key.
-
The user interface menus scroll vertically
- uck!
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.
-
You must manually add ComDlg32.OCX ActiveX
control to each application. In VB 3.0, CommDlg.dll was accessed via cmdialog.vbx Because the VB 6.0 help says to use CommDlg.dll,
the detailed instructions do not work.
-
The constants changed. Setting
CMDialog.Flags = OFN_FILEMUSTEXIST
+ OFN_HIDEREADONLY
no longer hides the readonly checkbox.
You must use cdlOFNFileMustExist and cdlOFNHideReadOnly instead.
-
Basically, all constants must be replaced
with their new values.
-
-
Things wrong with the FileOpen... dialog
box.
-
You can't resize the box to make it readable
-
You can't force it to open in details
mode
-
It can't show the directory tree in a
separate panel
-
It can't show the complete path
-
You can't change the column order
-
No search direction / search column indicators
-
Can't add additional columns (attributes,
date created, extension)
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.
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.
|