VBNotebook Home | Articles | Q&A Session: You Can't Get There From Here
These questions, or variants thereof, are often asked in VB newsgroups. The problem is that there isn't an easy, in-the-box, solution for these situations. In some cases, there isn't a workable solution at this time and, in others, the solution may be an ugly and hard to maintain hack or require third party products to implement. If you know of a way to implement solutions to these problems that aren't mentioned here, let me know and I'll mention them here and give you credit.
__________________________________________________________________________________________
Q1: I want to setup a global error trap. How can I do this?
A1: As of VB6, there is not a way to do this. Third party products are available that help automate the process of adding error handling to the routines in your program, although I think it's better to implement error handling yourself rather than retro-fitting it in with an automated tool.
__________________________________________________________________________________________
Q2: I want to create a DLL in VB that exposes its functions and subs in the same way a standard C/C++ DLL does, not a OLE/ActiveX style DLL. How can I do this?
A2: You can't. You can only create ActiveX DLLs (aka in-process automation servers) with VB.
First off, make sure that this is what you really need to do. If the program you want to use your routines from is capable of working with ActiveX DLLs, by all means use them. Some people don't realize that you can simply create a functions class that has the routines you want to expose. In most cases, all you'll need to do is move your routines from a standard module to a class module.
However, if you really need a standard DLL, there are 3rd party alternatives you might want to investigate. Desaware's SpyWorks Professional allows you to export functions from a VB created DLL. It is useful if you have an existing VB DLL that you want to use with something that doesn't support ActiveX. PowerBasic offers a product which allows you to create DLLs using BASIC syntax. It is useful when you're creating a new program that needs this capability.
__________________________________________________________________________________________
Q3: How can you assign multiple columns from a database table to a combo box?
A3: This really isn't possible with the standard combo box. There are some ugly hacks you can do (such as using a fixed width font), but they really aren't adequate. The best solution for most developers is to purchase a 3rd party combo box that provides this functionality. Another alternative would be to write your own control that did this, but it is not an easy undertaking to do so (which is why most people will opt for a 3rd party solution). I've heard of a few freeware alternatives that work around this problem as well but I haven't tried any of them.
__________________________________________________________________________________________
Q4: How can I get an Implemented class to raise events? I've tried a number of different ideas, but nothing seems to work.
A4: You can't do this in VB 6. The following Knowledge Base article describes this problem.
PRB: Error 459 Trying to Use Alternate Object Interface
Article ID: Q172329
http://support.microsoft.com/support/kb/articles/q172/3/29.asp
__________________________________________________________________________________________
Q5: Is it possible to create MDI child forms in a DLL so that they can be loaded into and viewed in the main application's MDI parent window as real MDI Child forms?
A5: In general, there isn't a clear cut, easy way, to do this. Most solutions are, for the most part, slimy hacks that make something that should be simple difficult, unstable, or confusing, for both you and your users. These solutions are generally based around using the SetParent API call.
There have been several threads posted in newsgroups over the past few years that outline possible solutions to this situation. You should be able to locate these threads on this topic by doing a search of Visual Basic related newsgroups at Google Groups. Search terms like "MDI Child Forms in ActiveX DLL" or "MDI Form in DLL" should turn up a number of hits. Perhaps one of these proposals will work for you.
One of the most practical ideas is to create large user controls that get loaded dynamically onto a MDI child form. This works better than most other solutions, but it has its quirks as well.
Some third party products may be available to help facilitate this, but I'm a bit skeptical of their overall usefulness and stability in this context.
I've found that dynamic form building is a much better solution for many applications rather than building a lot of static forms and storing them in main executables or in DLLs.
__________________________________________________________________________________________
Q6: I've recently taken over an old VB3 project that needs to be converted to VB6. The files were stored in the binary format. How can I convert them to ASCII text so that I can read them into VB6? I don't have a copy of VB3 readily available.
A6: Sorry, but there's no way to do it without using VB3. Perhaps you can locate a copy of VB3 to read in and convert the files to ASCII format (various Internet auction sites and computer seconds stores are a good place to look). Also, VB2 can be used to convert most projects since it uses the same base file format as VB3 (only certain VBX properties may not convert fully). Note that you'll need to have all of the VBX controls the VB3 project uses installed in order for the conversion to work correctly.
__________________________________________________________________________________________
Q7: I need to distribute my VB program on a single floppy disk but this doesn't seem to be possible. What can I do?
A7: Sorry, but it's really not possible to do this unless you are certain the VB runtime and any other support files you need are installed on the target systems. There are some third party products that can put everything into a single install executable and some that promise to compact everything into one file that expands out when it's run. You might want to investigate these options to see if they're practical in your case. Fortunately, systems without a CD drive are becoming less and less common so this issue is fading away.
__________________________________________________________________________________________
Copyright 2000-2005, J. Frank Carr