Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
XML RSS Feed
Tips & Tricks
These are brief tips and tricks that can make Visual Basic programming easier.
New Control Usage Numerical Stuff
Starting & Stopping I/O Bug Alerts
Software Engineering Printing System Issues
Graphics Coding Techniques Other Programs
Databases Misc Forms
Web

Bug Alerts

Printing Bugs
These links give information on some printer bugs. Thanks to Chris Wagg for starting the list.

Q153125 BUG: Printer Object Font Information is Lost After Printing
Q131455 BUG: Image Does Not Print Correctly on Postscript Printer
Q183163 BUG: Setting Orientation Changes Background Mix Mode for Printer
Q176634 BUG: Line and Circle Methods Do Not Print as Transparent on Win95/98
Q190216 BUG: Printer.DrawWidth Appears To Be Ignored with Windows 95/98
Q145726 BUG: Setting FontTransparent Has No Effect on Windows 95/98
Q274523 BUG: Print to File Fails to Request Output File Name


"Open In New Window" Does Not Work in Internet Explorer
There are a couple ways this might happen. I think it happened to me because I used a program that was linked to a previous version of Internet Explorer. Click here to see Microsoft's explanation and instructions for fixing it.


Controls Inside Controls
Kelina Kwan was modifying the example Create an ActiveX control with a borderless menu bar. It places a form inside an ActiveX control so the control can display the form's menu bar.

She found that the program generated an invalid page fault if the ActiveX control contains another ActiveX control defined in the same project.

The solution appears to be to create the second control in its own project. If you compile it into an OCX, you can include it in the other control with no problems.


No Such Interface Supported
By Robert

If you try to open the Component menu using the Project menu's Components command or by pressing ^T, you may get a message similar to this one:

    System Error &H80004002 (-2147467262)
    No Such Interface Supported
This can happen if the file comcat.dll gets trashed. For information on how to replace this file, see Knowledge Base articles Q183370.


Cannot Find Provider
Derrick Kearney has this tale of woe:

I went through the torture of "Cannot Find Provider" Error last week. When I installed Visual Studio sp4, all of my ActiveX data objects where changed to version 2.5. ActiveX 2.5 objects will not work with Microsoft.Jet.OLEDB.3.51, the provider must be changed to Microsoft.Jet.OLEDB.4.0. I was fortunate enough to have a helpful member of the Experts-Exchange help me. I searched for about 3 days on the internet, I have to say knowing the error with no solution was probable the most aggravating part of the whole experience.

[Often you can find invaluable information on errors from Microsoft's Web site. Go here and search for the error. In many cases the error has been found by others and a workaround is available. I did not find one for this error, though. -- Rod]


Jet VBA File VBAJet32.dll Failed to Initialize
If you see this error:
The Jet VBA file (VBAJet.dll for 16-bit versions, or VBAJet32.dll for 32-bit versions) failed to initialize when called. Try reinstalling the applications that returned the error.
Then click here to see a Knowledge Base article describing the problem and its solution.
Add-Ins Only Visible to the User Who Installs VB
Someone wrote me saying he demonstrated the Data Form Wizard to his class, but the students couldn't get it to work.

I believe this problem is discussed in the Knowledge Base article BUG: Add-Ins Only Visible to the User Who Installs VB.


Licensing Error Bugs
Visual Basic 5 can erroneously give these errors:
  • License Information For This Component Not Found. You Do Not Have An Appropriate License To Use This Functionality In The Design Environment.
  • Compile Error : Permission Denied
  • Runtime Error '429' : ActiveX Component Can't Create Object
  • License information for this component not found. You do not have an appropriate license to use this functionality in the design environment.
For more information and solutions to these problems, follow these Microsoft links.

PRB: "License Information for This Component Not Found" Error

Vbc.exe Fixes VB 5.0 Control Installation Problem


More Licensing Error Bugs
Reinald Nijboer came up with more information on control licensing bugs. If you want to use OCX/DLL's in your own written code (for example COMDLG32.OCX), you may get this message:
"License Information For This Component Not Found. You Do Not Have An Appropriate License To Use This Functionality In The Design Environment."
Click here for Microsoft's documentation and programs that fix this for VB5 or VB6.


Download Visual Basic 6, Service Pack 3

Immediate Window Tricks
(By Thomas Remkus)
I recently sent out an email to my team informing them of some things that they can do in the immediate window that they did not know of.
You are in the design mode and you need to get the string for one of those crazy control resource numbers on a form.
Load the form so you can look at the numbers. In the Immediate window, type "? LoadResString(x)" <return> where 'x' is replace the number and you should get the value.
You have loaded the project and you have the form that you want to work on right in front of you. You need the name.
Pause the project and type: "? Screen.ActiveForm.Name" <return> in the Immediate window.
You need to get a list of the active forms that are loaded.
Pause the project and type this all on one line in the Immediate window: "for x = 0 to forms.count - 1: ? x, forms(x).name: next x" <return> [Note: You need to have a variable x defined in the project. To make this sort of thing easier, you may want to define x in a global bas module. If you do this, do not use any other variables named x or you may get confused -- Rod]
You need to get a list of the resources on your form.
Pause the project and type this all on one line in the Immediate window: "for x = 4650 to 4655: ? x, LoadResString(x): next x" <return>
You need a list of anything or need to set values and would like to use the Immediate window but it seems to take a long time.
Type this on one line: "for x = Y1 to Y2: : : next x" where 'Y1' and 'Y2' just put the values to loop.
You have written a project and you want to see what the form would look like without loading the project in runtime.
Type: "set x = new frmX: x.show vbmodal"
You would like to add new functions so that you can use more utilities in the immediate window without having to go to runtime.
Create a COM component with classes that are globally creatable and expose public methods. Reference the COMponent and you can use them directly.
You want to place some text in the clipboard rather than sending through Debug.Print and then copy it.
Type: "Clipboard.SetText X" or "Clipboard.SetData X" (check help for more info).
You are on a control and you need to change what happens at a particular event. What you need is the name and index of the current control and you can not get out of the runtime because you don't want to stop the project.
Set your focus to the control. Then pause the project. Type: "? Screen.ActiveControl.Name" then "? Screen.ActiveControl.Index"
You have a function and you are going to expect a parameter that is a VB enumerated value like vbOKOnly.
Instead of declaring the parameter as long state that it's of that enumerated type. So instead of " ... As String, alStyle As Long, ..." you can put " ... As String, alStyle As VbMsgBoxStyle, ... " and this will give other developers the intelli-sense for your values.
You have created a function and you need to use constants for some of the values. You know that creating a set of constants is great but remembering what they are is just a load of work.
Create a private enumeration in the top of your component (form, class, etc.) and state that your parameter's are of that type instead of a long. This will give you the intelli-sense that is so easy to work with.

Dead OCXs
By Barry Traver

Recently in the Usenet newsgroup comp.lang.basic.visual.misc, more than one Visual Basic 5 user has reported the same problem: Suddenly, for no apparent reason Visual Basic 5 refuses to load in COMDLG32.OCX, COMCTL32.OCX, or COMCT232.OCX. Instead the error message "'' could not be loaded" is given (even though such files are present in C:\WINDOWS\SYSTEM and VB 5 does know the correct names of the files!).

I myself experienced that problem, which meant that I was not able to use for several weeks in VB 5 the common dialog control (that's six controls right there!), toolbar, status bar, image list, progress bar, tree view, list view, slider, etc. . I'm writing this so that other VB 5 programmers will know what to do if they encounter the problem.

Here's an important paragraph from Microsoft Knowledge Base article Q217017, which can be found at http://support.microsoft.com/support/kb/articles/q217/0/17.asp, concerning the "'' could not be loaded" message:

This error message occurs when you install a newer version of an ActiveX control, uninstall it, and then install an older version of the same ActiveX control. The registry key for the newer version of the ActiveX control remains in the registry and Visual Basic 5.0 is now trying to use that registry key.

This could easily happen, for example, if you install (as I did) a recent shareware program and later uninstall it. The key point is that although the earlier version of the OCX is restored, the Windows registry still points to the later version of the OCX (and since it is no longer there, VB 5 is unable to load it).

To fix the problem, the Knowledge Base advises using RegClean, making the important point, "RegClean will only be effective if Comctl32.ocx is deleted from the system before running RegClean." (Although not mentioned by the article, it appears that comdlg32.ocx and comct232.ocx should also be temporarily deleted before running RegClean.)

For details on using RegClean, see Knowledge Base article Q147769, "RegClean 4.1a Description and General Issues," which can be found at http://support.microsoft.com/support/kb/articles/Q147/7/69.asp. The RegClean utility itself can be downloaded from the Microsoft site at http://support.microsoft.com/download/support/mslfiles/RegClean.exe.

Here are the specific steps I took to solve the problem:

  1. I downloaded RegClean from the Microsoft site.
  2. I sent the three com*32.ocx files to the Recycle bin.
  3. I unzipped and ran RegClean to repair the registry.
  4. I restored the three com*32.ocx files from the Recycle bin.
  5. I used Regsvr32.exe to register the three com*32.ocx files.
  6. I tested out VB to confirm that things were indeed working again.
  7. I reinstalled the Visual Basic 5 service pack 3 (a good idea after you use RegClean).
IMPORTANT LESSON TO BE LEARNED: If you install, say, a shareware program and then uninstall the program, it may mess up the registry for VB 5! That's because when you install the program, it may replace an older OCX with a newer version, and when you uninstall it, it will indeed replace the newer OCX with the older version, BUT IT DOESN'T FIX THE REGISTRY .


Ted Fattaleh had the same problem and has some more details:

I myself experienced that problem, which meant that I was not able to use for several weeks in VB 5

As a programmer you should know how to clean the registry manually.

The error is most common when you install VB5 the programming software in a computer that has a VB5 program with OCXs already installed.

Search the registry for Comdlg32 or Richtx32, etc. without the extension and delete the whole key that it is in it, keep searching until you couldn't find it no more. That is it, you could use the API to register it, works much better than Regsvr32, if you do use regsvr32.exe then use it from MS-DOS prompt rather than from the Start\Run.

With Comctl32.ocx is a bit different, you need to restart computer after deleting all traces of it in the registry.

[Note: Regclean is supposed to handle things like this. I'm not sure I trust it completely, however. A previous version did a little damage to my registry once. Hopefully the latest version is safer, but you should probably back up your registry before you begin in any case. -- Rod]


Puzzling Parentheses
Visual Basic evaluates expressions in parentheses and then works with the result. This is obvious in the following code. The program evaluates X + 3, multiplies by 2, and assigns the result to Y.
    Y = (X + 3) * 2
This fact is less obvious when you call a procedure or function with extra parentheses around the parameters. In the following code, the program evaluates X and pass the result to the MySub subroutine.
    MySub (X)
It is very important that the program does not pass X itself to MySub, it passes the result of evaluating the expression X. This is stored internally in a temporary variable and is never seen by the main program. In particular, if MySub changes the value of its parameter, the changes does not return to the calling routine.

For an example, run the following code.

    Private Sub Command1_Click()
    Dim X As Integer

        X = 10
        MsgBox X
        ChangeValue (X)    ' Note the parentheses!
        MsgBox X           ' X is still 10.
        ChangeValue X
        MsgBox X           ' X is now 20.
    End Sub

    ' Double the value of the parameter.
    Private Sub ChangeValue(i As Integer)
        i = i * 2
    End Sub
Jack describes this as the system converting the routine ChangeValue to taking its parameter ByVal, even if it is declared ByRef or, as in this example, it defaults to ByRef.
Beware of C/C++ Syntax
Beware of statements like "A = B = C." In C/C++ this is a valid statement that assigns both A and B to the value C. Visual Basic treats "B = C" as a Boolean expression and makes A true if B equals C and false otherwise.
Understand XOR Mode Drawing
When you draw in XOR mode, the system does not XOR the color values. Instead XORs the bits representing the index of the colors in the system color palette.

The color palatte is a table listing the (probably 256) colors displayed on your system. The background color is stored in some "random" position, say 69 = &H45. The foreground color is in some other table entry, say 42 = &H2A. You XOR these and get &H42 XOR &H2A = &H68 = 104 (if I didn't mess up the math). That means you get whatever color happens to be in table position 104. Today it could be dark red. Tomorrow it could be something else.

The easiest thing to do about all this is nothing. Use vbInvert instead of XOR and don't worry about the colors you get.

The system palette includes 20 static colors that have fixed values. They live in the first 10 and last 10 palette entries. They are arranged so the inverse of one gives another that contrasts well. That means if you use those colors and you draw using vbInvert, the result usually contrasts well so you can see it.

If you really want to get exactly the color you want, you are probably better saving a copy of the image so you can erase by restoring it. Then draw copy pen mode using red or whatever. Annoying, I know.


Understanding Line Drawing
When Visual Basic draws, it seems to convert its coordinates into pixels and then place the results in short integers. If the coordinate positions in pixels are greater than 32767, the program crashes. That means you can use very large values if you work with twips but smaller values when working with pixels.
Understanding Forms
When you define a form named MyForm, Visual Basic creates one instance of the form with the name "MyForm." Many people confuse this special instance with other instances created using Dim. For example, the Caption statement in the following code sets the caption on the automatically created instance. The caption on frm is not set.
    Dim frm As New MyForm

        MyForm.Caption = "This is the single instance"
        frm.Show
Even more confusing problems can arise if you use MyForm within the MyForm code module. In that case an instance like frm might accidentally set properties on the automatically created form not on itself. For this reason, never use MyForm within the MyForm code module.
Debug Object Creation and Destruction
It is often hard to figure out when objects are created and destroyed. When in doubt, stick Debug.Print statements in the object's Initialize and Terminate event handlers to try to see what's happening.
Send your Tips and Tricks to feedback@vb-helper.com.

 
Subscribe to the VB Helper newsletter
Copyright © 1997-2001 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
www.vb-helper.com/tips5.htm Updated