Microsoft Knowledge Base

How To Use OLE Control Procedures to Test a VB 4.0 Application

Last reviewed: January 10, 1997
Article ID: Q156764
The information in this article applies to:
  • Microsoft Visual Test for Windows 4.0, 4.0a, 32-bit only
  • Microsoft Visual Basic 4.0, 32-bit

SUMMARY

An OLE control is a Windows custom control that conforms to an OLE specification. You can test 32-bit OLE Controls by setting and getting the data stored in these controls using the OLE Control commands (OLECTL...) in a Visual Test Script. This article demonstrates how to use the OLE Control commands to interact with OLE Controls in a 32-bit Visual Basic 4.0 Application.

NOTE: Visual Test only works with 32-bit OLE Controls used in 32-bit applications.

MORE INFORMATION

The steps below demonstrate the use of the OLE Control commands to interact with a 32-bit Visual Basic 4.0 Application.

This article uses the Visual Basic sample program Loan that ships with the 32-bit version of Visual Basic 4.0 (\samples\grid\loan.vbp).

The sample script below uses the OLE Control commands to set the values for the TextBox Controls such as PurchaseAmount and PercentDown, and the Combobox Controls such as InterestRates.

The sample script below clicks on Show Payment Button to populate the Grid Control's cells and then retrieves and prints the populated cell values in the Developer Studio Viewport.

Load and Modify the Visual Basic Sample

  1. Start Visual Basic 4.0 (32-bit version) and load the Loan project (samples\grid\loan.vbp). Add the Visual Test OCX (MSTEST.OCX) to the Visual Basic Toolbox by doing the following:

    - Select the Tools - Custom Controls menu (CTRL+T) in Visual Basic.

    - Click the Visual Test OLE Custom Control Module check box located

         in the Available Controls list. Click OK.
    

    - Place the MSTEST.OCX control (now located in the Visual Basic Toolbox)

         on the Form named Loansheet.
    

  2. Run the modified Visual Basic sample application by pressing the F5 key.

Load Visual Test and Create the Sample Script

NOTE: Do not minimize Visual Basic during the following steps.

  1. Start Visual Test.

  2. Type the following code into a new script file:

    dim GrdName$ , PurchAmt$ , PercntDwn$ , YrsMax$ , YrsMin$

                dim   IntMax$ ,IntMin$ ,CalcBtn$
                dim property$
    
       timeout = 10
    
       'Find the Form that has the OLE Controls and set focus to it
    
             CurrentWindow = WFndWndC("LoanSheet", "ThunderForm", _
                                       FW_FOCUS, Timeout)
             WSetWndPosSiz(CurrentWindow, 36, 96, 473, 427)
                 Viewport Clear
    
       'Variables are initialized with the names of the controls using the
       'Name property of the control.
    
          PurchAmt$  = "#txtpurchTotl"
          PercntDwn$ = "#txtDwnPay"
          YrsMax$    = "#txtlenMax"
          YrsMin$   = "#txtlenMin"
    
          IntMax$   = "#ComIntrMax"
          IntMin$    = "#ComIntrMin"
    
          CalcBtn$   = "#CmdcalcPmts"
          GridName$  = "#grdPayments"
    
       'Fill in some sample values for a calculation
    
       OlectlSetproperty(PurchAmt$,"Text" ,"200000" ,timeout)
       OlectlSetproperty(PercntDwn$,"Text","5" ,timeout)
       OlectlSetproperty(YrsMax$ ,"Text","30",timeout)
       OlectlSetproperty(YrsMin$,"Text","15",timeout)
       OlectlSetproperty(IntMax$,"Text","9.5",timeout)
       OlectlSetproperty(IntMin$,"Text","7.5",timeout)
    
          'Click on the Button 'Show Payments'
             OleCtlClick(CalcBtn$)
    
       'Find the Grid control on the Visual Basic Form
    
       Dim   Lpdisp as long
       Lpdisp = OlectlFind(GridName$ ,10)
    
       'Select a range of cells to get the values from.
    
       OlectlSetproperty(_ctl(Lpdisp),"SelstartCol" ,1 ,10)
       OlectlSetproperty(_ctl(Lpdisp),"SelstartRow" ,1 ,10)
       OlectlSetproperty(_ctl(Lpdisp),"SelendCol" ,3 ,10)
       OlectlSetproperty(_ctl(Lpdisp),"Selendrow" ,3 ,10)
    
       'Get the values in those cells
       Dim Cellvalue as variant
       Cellvalue = OleCtlGetProperty ( _ctl(Lpdisp) , "Clip" ,10 )
    
       'Print the cell values to the Viewport
    
       Print "Values returned from the Grid control"
       Print "====================================="
       print Cellvalue
       Print "====================================="
    
       'Get a list of all the properties of that Grid control
    
       Dim propertyList(40) as  OLECTL_PROPERTY
       Dim TotProperty as long
    
       Totproperty = OleCtlPropertyList(_ctl(Lpdisp),propertyList ,10)
    
             'Print all the properties Name and their values of the Grid
             'control to the ViewPort
    
       Dim i%
       Print  "Property Name: ";" --- "; "Value: "
            Print
    
             for i% = 0 to Totproperty-1
                     print  propertyList(i).propname ; ":   " ; _
          propertyList(i).propvalue
             next i
    
             End
    
    

Run the Sample Script

  1. Run the script you created in step 5 by pressing the F5 key.

  2. Note that the Loan Application's Grid Control has been populated with some values and also that Visual Test's Viewport contains information about the Visual Basic Controls.

REFERENCES

For more information on testing OLE Controls, please refer to the Visual Test Online Help under:

   Visual Test 4.0 Books Online
      \ Programmer's Guide
            \ Simulating and Verifying User Actions
                  \ Working with OLE Controls

For information on Clip , SelstartCol, SelstartRow, SelendCol, and SelendRow, please refer to the Visual Basic Online Help.


KBCategory: kbusage kbole kbhowto
KBSubcategory: kbnocat
Additional reference words: 4.00 vtest4 OLE controls OCX VB kbdss



THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 10, 1997
©1997 Microsoft Corporation. All rights reserved. Legal Notices.