Move Areas of Common Functionality Within Programs to Visual Basic 5

An ActiveX EXE server can be called from any Visual Basic program. ActiveX DLL servers can be used in process by 32-bit Visual Basic 4 and Visual Basic 5 programs. Areas of common functionality can be identified and placed in separate component programs. These can be compiled as either DLLs or EXEs, according to the client application. If you use EXEs, these programs can be run from any program. There is a small problem with running these servers out of Visual Basic 3 clients. While Visual Basic 3 is waiting for a return from a synchronous call in the ActiveX server, it doesn’t receive any Windows messages. The practical consequence of this is that if the server displays a dialog box, the Visual Basic 3 application will not repaint itself until the call has returned, as shown in Figure 6-6.

There are a number of workarounds to this problem: You can either make the dialog box nonmovable by removing the move item from the system menu, or you can make the server an asynchronous server and poll a programmer-defined property until it completes its processing. Another workaround is to port your Visual Basic 3 code to the 16-bit version of Visual Basic 4, which processes Windows messages when waiting for a server to return control.

As an example of this, the form FRMADDRE.FRM remains unchanged and is added to a Visual Basic 5 ActiveX.EXE program and the following code is added to the class:

Public Sub Show
    Dim frmNew As New frmAddress
    Load frmNew
    frmNew.txtAddress.Text = sAddress
    frmNew.txtPostalCode.Text = sPostalCode
    frmNew.Show Visual Basic Modal
    sAddress = frmNew.txtAddress.Text
    sPostalCode = frmNew.txtPostalCode.Text
    Unload frmNew
    Set frmNew = Nothing
End Sub

Set the class instancing to 5 - Multiuse, and compile the project.

Figure 6-6 An illustration of the refresh problem in Visual Basic 3

In the original Visual Basic 3 program, you replace the code behind the cmdAddress button with the following code:

Sub cmdPopUpAddressForm_Click ()

    Dim objAddress As Object
    Set objAddress = CreateObject("AddressServer.CAddress")

    objAddress.strAddress = spuAddress
    objAddress.strPostalCode = spuPostalCode

    objAddress.Show 

    spuAddress = objAddress.strAddress
    spuPostalCode = objAddress.strPostalCode

    Set objAddress = Nothing
End Sub