Visual Basic Q&A

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries Tagged ‘Windows’

BUG: Error When Data Control Is Set to a Wrong Text Database

Symptoms
A 16-bit Visual Basic for Windows version 4.0 program containing a Datacontrol with a Connect property set to Text and the DatabaseName propertyset to a non-text database generates an application error when run. Theapplication error displays the message – VB caused a General ProtectionFault in module VB.EXE at 003F:2106. Choose close. VB will close.
A 32-bit Visual Basic for Windows version 4.0 program with the same controlset to the same property displays the error message – Couldn’t find object.
Resolution
Microsoft has confirmed this to be an issue in the Microsoft productslisted at the beginning of this article. Microsoft is researching thisissue and will post new information here in the Microsoft Knowledge Baseas it becomes available.

BUG: Design Option in Pop-up Menu Data View Window Not Available

Symptoms
If you use a Windows NT 4.0 computer and are not a member of the administrators group, you will not get the Design option in the pop-up menu for a table when you right-click on on the table in the Data View Window of Microsoft Visual Basic 6.0.
NOTE: This bug does not occur on Windows 2000 machines.
Resolution
The Visual Basic IDE is incorrectly determining that the Design option should not be shown unless you belong to the administrators group.

BUG: All check boxes are cleared in a data-bound CheckedListBox control when rows are added to the DataTable control

Symptoms
You have a data-bound CheckedListBox control on your Windows Form. When you click to select some items in the CheckedListBox control at runtime and then you add a new row to the DataTable control that is bound to the CheckedListBox control, all the check boxes on the control are cleared.
Note Check boxes are not cleared when the CheckedListBox control is not data-bound.
Resolution
This problem occurs because the CheckedListBox control is not designed for data binding.

PRB: GetChunk Corrupts Binary Data on Win98/NT4 SP4

Symptoms
When using the Data Access Objects (DAO), Remote Data Objects (RDO) or the ADO GetChunk method, on a long binary field of a Microsoft Access database, binary data may appear corrupt if the binary information previously stored was read from disk using a String (BSTR) variable instead of a Byte array. The problem occurs under one of the following conditions:
You recently upgraded your computer to Windows 98 or Windows NT version 4.0 SP4. Previously stored data now appears corrupt.
-or-You are using a shared database. The corruption occurs when the binary data was stored by clients running on Windows 95 or Windows NT 4.0 SP3, and then extracted by clients running Windows 98 or Windows NT 4.0 SP4 or vice versa.
Resolution
The problem is that the information stored to the database is mistakenly being converted to Unicode before being stored. The “corruption” occurs when reading the information from disk using the Visual Basic or Visual Basic for Applications Get statement.
By design, the Get statement relies on the data type of the variable to determine how the information should be read into Visual Basic. If you pass a String (BSTR) variable to the function, Visual Basic identifies the information as being a text string, and converts it to Unicode. However, since the data is binary and not text, this conversion corrupts the data before it is ever stored to the database.
Although binary data stored in Unicode format can be “decoded” in some cases, it requires that the Unicode symbol table used to map 1-byte ANSI characters to 2-byte Unicode characters be the same for both the conversion to and the conversion from Unicode. Due to the recent addition of the European Currency symbol, the symbol table for Windows 98 and Windows NT 4.0 SP4 is different from those used previously. These changes will have no effect on text strings, but can effect binary data mistakenly converted to Unicode.

INFO: VB 6.0 Readme Part 1: Important Issues – Read First!

Symptoms
The information below includes the documentation and workarounds for VisualBasic 6.0. This information can also be found in the README.htm file thatships with Visual Basic 6.0 on the Visual Basic 6.0 CD-ROM. Please see theREFERENCES section of this article for a list of the Microsoft KnowledgeBase articles relating to the Visual Basic 6.0 readme.
Following is a list of all parts of the readme file:
Part 1.Important Issues – Please Read First!
Part 2.Data Access Issues and DataBinding Tips
Part 3.Control Issues
Part 4.Language Issues
Part 5.Samples Issues
Part 6.Wizard Issues
Part 7.Error Message Issues
Part 8.WebClass Designer Issues
Part 9.DHTML Page Designer Issues
Part 10. Extensibility issues
Part 11. Miscellaneous Issues
Part 12. Microsoft Transaction Server (MTS) Issues
Part 13. Dictionary Object
Part 14. Visual Component Manager
Part 15. Application Performance Manager
Resolution
Passing User-Defined Types to ProceduresWith Visual Basic 6.0 it is possible to pass a user defined type (UDT) asan argument to a procedure or function. However, there is a restriction.Passing a UDT to a procedure in an out-of-process component or acrossthreads in a multi-threaded component requires an updated version of DCOMfor Windows 95 and Windows 98, or Service Pack 4 for Windows NT 4.0. Thisupdate is required on your development computer as well as on any computerthat will run your application. A run-time error will occur if the requiredfiles are not installed.
The above does not apply to passing UDTs within a single-threadedapplication; this will work without updating. The Package and DeploymentWizard will not determine the dependencies for the necessary components -it is up to you to make sure that the files are on the end user’s computer.You can test for the existence of the components by trapping for run-timeerror 458 – “Variable uses an Automation type not supported in VisualBasic”. If this error occurs, the DCOM or Service Pack components must beupdated; the update procedure differs depending on the operating system:
Windows 95 or Windows 98
DCOM98.EXE is a self-extracting executable that installs the updatedDCOM components for Windows 95 or Windows 98. It can be found in theDCOM98 directory of the Visual Basic 6.0 CD. This file may be freelydistributed with your Visual Basic application.Windows NT 4.0
The updated DCOM components are automatically installed with ServicePack 4 (SP4). When it is released, you can download the Service Packfrom the Microsoft Web site.
Searching Online by Topic TitleTo search for a topic when you have the title:
In the navigation pane of the MSDN window, click the Search tab and thentype or paste the title of the topic you want to find. Enclose thesearch string in quotation marks.Click Search Titles Only.Click List Topics. (If your search returns more than one hit, you cansort the topic list by clicking the Title or Location column heading.)Select the title of the topic you want and then click Display.
To find where a topic is located in the table of contents, click theLocate button on the toolbar. The table of contents will synchronizewith the topic you are viewing.
NOTE: The Locate button is unavailable for the topics in the Referencenode of the Visual Basic documentation.Cross References to Internet Client SDK
Refer to the Internet/Intranet/Extranet SDKIn the Building Internet Applications book within the Component ToolsGuide, multiple cross references are made to a part of MSDN referred to asthe “Internet Client SDK.” The correct name for this SDK is the”Internet/Intranet/Extranet SDK.” When searching for an Internet Client SDKreference in MSDN, please look in this section.
Context-Sensitive HelpTo use Help buttons and the F1 key to access Help without having the MSDNCD in your CD drive, you must choose the Custom install option during setupof the MSDN Library. Check the boxes labeled “VB Documentation,” “VBProduct Samples,” and “VS Shared Documentation.” You may also want to check”VSS Documentation” if you are using Visual SourceSafe.
Sample Code Sometimes Does Not Cut and Paste ProperlyLine breaks and formatting information may not copy correctly when you copyand paste sample code from the MSDN Library Visual Studio documentation toyour code editor. To work around this issue, do one of the following:
Manually edit the line breaks after you copy the code.View the sample code source, copy the entire code sample, including the<pre> and </pre> tags, paste it to your code editor, and then delete theunwanted sections from the pasted version.
Locate Button Disabled for Reference TopicsWhen you find a language reference topic in MSDN through the Search tab,you cannot use the Locate button to find where the topic is located in theMSDN Table of Contents tree.

INFO: Troubleshooting Error 429 When Automating Office Applications

Symptoms
When you use the New operator or CreateObject function in Microsoft Visual Basic to create an instance of a Microsoft Office application, you may get the following error message:

Run-time error ‘429′: ActiveX component can’t create objectThis error occurs when the requested Automation object could not be created by COM, and is therefore unavailable to Visual Basic. The error is typically seen on certain computers but not others.
This article provides some troubleshooting tips to help you diagnose and resolve common problems that are known to cause this error.
Resolution
Unlike some errors in Visual Basic, there is no one cause to an error 429. The problem happens because of an error in the application or system configuration, or a missing or damaged component. Finding the exact cause is a matter of eliminating possibilities. If you encounter this error on a client computer, there are a number of things you will need to check to isolate and resolve the error.
The items later give you some practical suggestions for troubleshooting this error when you work with Office Applications. Some of this information may also apply to non-Office COM servers as well, but this article assumes you are trying to automate Microsoft Office.
Checking the CodeThe first place to begin looking for the problem is in the code. Before you can troubleshoot the error, you need to know where the error occurs. Try to narrow it down to a single line of code.
When you find the code that is failing, try to do the following:
Make sure the code uses explicit object creation. Any problem is easier to spot and identify if the problem is narrowed to a single action. For example, do not do the following:

Application.Documents.Add ‘DON’T USE THIS!!
or:

Dim oWordApp As New Word.Application ‘DON’T USE THIS!!’… some other codeoWordApp.Documents.Add Both of these methods use implicit object creation. Microsoft Word is not started until the variable is called at least once. Since the variable could be called in different parts of the program, this could make the problem hard to localize. Also, it is not clear whether the problem is with creating the Application object or the Document object.
Instead, make explicit calls to create each object separately:

Dim oWordApp As Word.ApplicationDim oDoc As Word.DocumentSet oWordApp = CreateObject(“Word.Application”)’… some other codeSet oDoc = oWordApp.Documents.Add This makes the problem easier to isolate and makes the code more readable.When creating an instance of an Microsoft Office application, use CreateObject instead of New. CreateObject more closely maps to the creation process used by most Visual C++ clients, and allows for possible changes in the server’s CLSID between versions. CreateObject can be used with both early-bound and late-bound objects.Verify that the ProgID string passed to CreateObject is correct and that it is version independent (that is, use “Excel.Application” rather than “Excel.Application.8″). It could be that the system that is failing has an older or newer version of Microsoft Office than the version you specified in the ProgID.To aid in debugging applications that cannot be run in the IDE, use the Erl command to report the line number of the line that fails. For example, the following code will tell you which Automation object cannot be created (Word or Excel):

Dim oWord As Word.ApplicationDim oExcel As Excel.ApplicationOn Error Goto err_handler1: Set oWord = CreateObject(“Word.Application”)2: Set oExcel = CreateObject(“Excel.Application”)’ … some other codeerr_handler:MsgBox “The code failed at line ” & Erl, vbCritical Use a combination of message boxes and line numbers to track down the error.Try using late binding (that is, Dim oWordApp As Object). Early bound objects require their custom interfaces to be marshaled across process boundaries. If there is a problem marshaling a custom interface during CreateObject or New, you will get an error 429. A late bound object uses a system-defined interface (IDispatch) that does not require a custom proxy in order to be marshaled. Try using a late bound object to see if this makes a difference.
If the problem occurs only when the object is early-bound, the problem is with the server application, and can typically be corrected by reinstalling the application (see later).If you are automating from ASP or an MTS component, use CreateObject instead of Server.CreateObject(). Using Server.CreateObject will instantiate the Office application under the identity of an MTS package which is known to cause problems with Microsoft Office.
Checking the Automation ServerThe most common reasons for an error with CreateObject or New are problems with the server application itself. Typically, these problems are with the configuration or setup of the application. Here are some items to check:
Verify the Microsoft Office application you want to Automate is installed on the local computer, and make sure that you can start the application from the Start and then Run dialog box. If the program cannot be started manually, it will not work through automation.Re-register the application by typing the path to the server in the Start and then Run dialog box, and then append /RegServer to the end of the line. Press OK. This should silently run the application and re-register it as a COM server. If the problem is with a missing registry key, this will typically correct it.Check the LocalServer32 key under the CLSID for the application you want to Automate. Make sure it points to the correct location for the application, and make sure the path name is in a short path (DOS 8.3) format. While it is not a requirement that a server be registered using a short path name, long path names that include embedded spaces have been known to cause problems on some systems (see later).
To check the path key stored for the server, start the Windows Registry Editor by typing regedit in the Start and then Run dialog box. Navigate to the HKEY_CLASSES_ROOT\Clsid key. Under this key you will find the CLSIDs for the registered automation servers on the system. Using the values later, find the key that represents the Office application you want to Automate and check its LocalServer32 key for the path.

+========================+=========================================+| Office Server| CLSID Key|+========================+=========================================+| Access.Application| {73A4C9C1-D68D-11D0-98BF-00A0C90DC8D9}|+————————+—————————————–+| Excel.Application| {00024500-0000-0000-C000-000000000046}|+————————+—————————————–+| FrontPage.Application| {04DF1015-7007-11D1-83BC-006097ABE675}|+————————+—————————————–+| Outlook.Application| {0006F03A-0000-0000-C000-000000000046}|+————————+—————————————–+| PowerPoint.Application | {91493441-5A91-11CF-8700-00AA0060263B}|+————————+—————————————–+| Word.Application| {000209FF-0000-0000-C000-000000000046}|+————————+—————————————–+ Does the path match the actual location of the file? Be aware that short path names can give you the impression that a path is correct when it may not be. For example, both Microsoft Office and Microsoft Internet Explorer (if installed in their default locations) will have a short path similar to “C:\PROGRA~1\MICROS~X\” where X is some number. It is not immediately obvious that you are looking at from a short path name.
You can test that the path is indeed correct by copying the value from the registry and pasting it into the Start and then Run dialog box (remove the /Automation switch before running the application). Does the application start when you select OK? If yes, then the server is registered correctly. If not, you should replace the value of the LocalServer32 key with the correct path (use a short path name if possible).Problems have been known to occur when automating Word or Excel if either the Normal.dot template (Word) or the Excel.xlb resource file (Excel) has become corrupt. To test if a corruption has occurred, search the local hard drives to find all instances of Normal.dot or *.xlb. (Please note that if you are running Windows 2000, Windows NT, or Windows 95/98 with profiles enabled, you may find multiple copies of these files, one for each user profile on the system.) Temporarily rename the Normal.dot file(s) or the *.xlb file(s), and re-run your Automation test (Word and Excel will create these files if they cannot find them). Does the code now work? If yes, then the files you renamed should be deleted since they are corrupt. If not, you should rename them back to their original names so any custom settings saved in these files won’t be lost.If you are on a Windows NT, Windows 2000, Windows XP, or Windows Server 2003 system, run the application under the Administrator account. Office servers require read/write access to the registry and disk drive, and may not properly load if your current security settings deny this privilege.
Checking the SystemSystem configuration can also cause problems with the creation of out-of-process COM servers. The following are some things to check on systems where the error occurs: Does the problem happen with any out-of-process server? If you have an application that just uses a particular COM server (for example, Word), you’ll want to test a different out-of-process server to make sure the problem is not with COM layer itself. If no out-of-process COM server can be created on that system, then a reinstallation of the OLE system files (see below) or a reinstallation of the operating system will be required to resolve the issue.Check the version numbers for the OLE system files that manage Automation. These files are typically installed as a set, and should match build numbers. An improperly configured setup utility can mistakenly install the files separately, causing them to become mismatched. To avoid problems with Automation, you should check the files to make sure the files match builds.
You will find the Automation files in the Windows\System or Winnt\System32 directory. The following is the list of files to check:

+—————+————-+—————-+| File Name|Version| Date Modified|+—————+————-+—————-+| Asycfilt.dll|2.40.4275| March 08, 1999 || Oleaut32.dll|2.40.4275| March 08, 1999 || Olepro32.dll|5.0.4275| March 08, 1999 || Stdole2.tlb|2.40.4275| March 08, 1999 |+—————+————-+—————-+ Check the file version by right-clicking on the file in Explorer and selecting Properties from the popup menu. The values most important are the last four digits of the file version (the build number) and the date last modified. You want to make sure these values are the same for all the Automation files.
Please note that the version numbers and dates given above are for example purposes only. Your values may differ. The important thing is that these values match each other, rather than this table.
If the files don’t match build numbers or modified dates, you can download a self-extracting utility that will update your Automation files. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
290887?(http://support.microsoft.com/kb/290887/) VBRun60sp6.exe installs Visual Basic 6.0 SP6 run-time filesWindows NT 4.0 has a known problem with starting Automation servers that live in a folder that contains an embedded space in the name, and/or resembles another folder whose first 8 characters are identical. For example, a server living in C:\Program Files\SomeFolder may fail to start during a call to CreateObject if there is another folder on the system called C:\Program Stuff\SomeFolder. For more information, see the following Knowledge Base article:For additional information about this problem and steps to workaround it, click the article number below to view the article in the Microsoft Knowledge Base:
185126?(http://support.microsoft.com/kb/185126/EN-US/) BUG: COM/OLE Server Fails to Start on Windows NT 4.0
Reinstalling Microsoft OfficeIf none of the preceding steps helps to resolve the problem, consider uninstalling and reinstalling Microsoft Office. Microsoft recommends that you uninstall the existing version first, and then reinstall from the original installation disks.
For a complete list of the items to be removed, please see the following Knowledge Base articles:
219423?(http://support.microsoft.com/kb/219423/EN-US/) OFF2000: How to Completely Remove Microsoft Office 2000
158658?(http://support.microsoft.com/kb/158658/EN-US/) OFF97: How to Completely Remove Microsoft Office 97