    188	  Actr 

     8.      ActiveX 
    ve| 

    Visual Basic  5.0     ActiveX 
(   OLE ).   ActiveX  
-cejDBep,   ,   
      . 
            ActiveX  
,      Visual Basic. 

    8.1.   ActiveX 

     ActiveX      (,  
., -.dll  .);    ActiveX   
      . 
     Visual Basic      ActiveX:  
 ActiveX,  ActiveX    ActiveX. 

    8.1.1.   ActiveX 

      ActiveX (     OLE) 
      
,        . 
          ActiveX .   9 
"   ActiveX". 

    8.1.2.  ActiveX 

     ActiveX (   -)   
ActiveX,         
-   ActiveX    
 OLE.      
  ,  -,   
Internet Explorer,     
        ActiveX .   10 
"    ActiveX". 

    8.1.3.   ActiveX 

        . - 
  ,    ,  
. .1-  ,   ,  . 
     ,    ,  
 "  ActiveX,   Visual Basic.  
Visual Basic, Microsoft Excel. Microsoft Access, Microsoft Project, Microsoft 
Visual FoxPro, Microsoft Visual C++   . 
    Visual Basic        
   ActiveX, ,     
   . 


     8.    ActiveX	189 


    8.1.4.    ActiveX 

        ActiveX : 
        .  ,  
   ActiveX,    ,   
.   -   ,   
   , j/  
        
-  Help, -   
.        
,  Object Browser    ; 
        ,   .   
ActiveX  ,       
.     ,   
       .   
  ActiveX,   - (  
  ,   ).  - 
,     ,    
,     -"~~ 

    8.2.    Visual Basic 

        ActiveX    
 ,    ,  . 
    ,    
      .    
         
.   ,    ,    
,    . 
            Visual 
Basic.         ActiveX. 

    8.2.1.   

        ActiveX     
    Visual Basic.     
  " * 

       

            ,  
Visual Basic.   '   .  
,       .    
    .      
   . 
             
ActiveX.      . , 
   ,    ,  
.  .,   ,  .. 
         
   . 

         

              Project  
 Add Class Module. ,        
  


    190	   Visual Basic 

      Class Builder  Visual Basic.  Class Builder 
    . 
        Class Builder Visual 
Basic CMJ ,   " Class Builder". 

    8.2.2.    

           : 
             ,    ; 
            . 
     ,   ,     
 Dim  Set,     : 

    Dim  objObjectl   As   Classl Dim  objObject2   As   Classl 
    Set   objObjectl   =  New  Classl Set   obObject2   =  New  Classl 

    :     .    .  
  , objObjectl  objObject2    Classl.  
  ,-   Dim objObjectl As New Classl, 
,   ,    ,  
  Set. 
        Set .   " 
:  "  7 "    ActiveX". 

    8.2.3.    

         : Initialize  Terminate. 
           ,  ^ 
       Class    Object. 

     Initialize 

     Initialize     ,   
   .  Initialize   
   ,     : 

    Private   Sub  Class_Initialize() 
    '       
    i   =   5 End  Sub 

     Initialize      , 
 . 

     Terminate 

     Terminate ,      
     Nothing.    
   ,     
,       . 
    Private   Sub  Class_Terminate() 
    '        . End   Sub 


     8.    ActiveX 191 

    8.2.4.   

              
 Public Sub  Function.      
 Public Sub  Function      . 
         ,     . 
      : 

    Public   Sub   ShowDateO 
    MsgBox   ":    "   &  Now () End  Sub 

             ShowDate()   
 : 

    Private   Sub   Form_Load() Dim  objObjectl   As  New  Classl 
objGbjectl.ShowDate End   Sub 

            . 

    ^65. 
    [(General) 
    J   JshowDate 
    d 
    Public Sub ShowDateO 
    MsgBox ": End 
     Project! - Forml (Code) 
    & Nou( 
     
    Uiapt] 
    Form 
    d 
    Load 
    ZJ 
    Priuate  Sub  Form_Load() Din objObjectl  fis New Class' 
objObjectl.ShowDate End  Sub| 
    Project! 
    : 06.10.9716:12:08 
    OK 

    . 8.1.    . 

        ,      
 : 

    Public Function SquareNum(Num As Integer) _ 
    As Integer 
    SquareNum = Num * Num End Function 

             ShowDate  SquareNum: 

    Dim Demol As Classl 
    Set Demol = New Classl 
    Demol.ShowDate 
    i = Demol.SquareNum(Num:=5) 


    192        Visual Basic 


            Class Builder. 
  % ,        
 Add Procedure       Add Procedure,  
     .     
      ^ 

    Add Procedure 

    Name; j NewProcl -.-	.-.---
    ' <*** Sub	(" Property ' (* lynctton!        (~ Event. 
    ,scope - ( Public	'"*" Private 
    J~" All Local variables as Statics 
    OK 
    Cancel 
    I 
     Projectl - Class 1 (Code) 
    (General) 
    jJ JNewProd 
    ZJ 
    Public Function NewProcl() ~j] End Function 
    IMJj 
    j 
     I 
    >^ 

    . 8.2.   Add Procedure     . 

      Object Browser     ,  
   

    _ Object Browser	 |i i   1 
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
    Jprojectl	d      I ^U;*l fl 
    1    ...........	diiliJ 
     Classes		Members of 'ClassV 
     <globals>		^ NevuProc! 
    	1	A* ShovuDate 
     Forml	,	s SquareNum 
    : Private Class Class 1 I    Member of 'joivji.si                          
                                                      '   : 

    . 8..      Object Browser. 


    8.2.5.   

          : 
      public  
        public  Property. 


     8.    ActiveX	193 


     Public    .  
Property    ,    
  . 
         Public 
           User 
( public    General Declarations  ): 

    Public   User  As   String 

         Classl    
 User: 

    Dim Demol As Classl Set Demol = New Classl Demol.User = "" 


       

             
   . ,  Text  Visual Basic  
     TextBox.    : 

    Textl.Text   =   "Visual   Basic" 
     
    Text   =   "Visual   Basic" 

       : 
    1.   ,  . 
    2.   Tools  Procedure Attributes. 
    3.    Procedure Attributes   Advanced. 
    4.    Name  ,   
  . 
    5.    Procedure ID  (Default) (. 8.4). 

    8.2.6.   Property    

     Property ,       
     .    
Property    : 
    	       ; 
    	     ; 
    	     . 
     Property    . ,   
 Set  Let,     ,  
 Get,    .     
 ,     . 

      

          Property Let  Property 
Get,         User 
(    ): 

    7  .   I36 


    194    Visual Basic 


    . 8.4.   Procedure Attributes. 


    Private gsUser As String Public Property Let User (s As String) 
    gsUser = Ucase(s) End Property 
    Public Property Get User () As String 
    User = gsUser End Property 

         

         Classl    
  User: 

    Dim Demol As Classl 
    Set Demol = New Classl 
    Demol.User = "" '   Let 
    Print Demol.User '   Get 

      ,     , 
  Property Get  Property Let.     
 Object    Property Get  Property Set. 
         Property Get.   
   Property Let. 
     Property Let       , 
    .      
   . 


     8.    ActiveX 195 


             
Property Get    Property Let  Property Set. 

    8.2.7.  Class Builder 

     Visual Basic   Class Builder,   
  .   Class Builder   
    . 
    ^ 

    . 8.5.   Class Builder. 

    I !    Class Builder: 
    1.   Add-lns  Add-In Manager. 
    2.   Available Add-lns  Visual Basic Class Builder Utility  
 . 
    3.   Add-lns  Class Builder Utility. 
    4.           , 
  .         
File | New     , , , 
   (. 8.6). 

    8.3.     ActiveX 

       ,      
-, ,  ActiveX EXE  ActiveX DLL.   
    -,    
  ActiveX. 

    8.3.1.     

     Visual Basic    ,   
  in-process (ActiveX DLL)  out-of-process (ActiveX EXE). 

     in-process  out-of-process 

     in-process        
,   out-of-process.   ,   
in-process     -  
          
.  out-of-process -v-   , 
  . , ,    ,    
    . 


    196     ActiveX 


    . 8.6.    Method Builder    . 

          
in-process  out-of-process .   "  
 "  7 "    ActiveX". 

       

        Visual Basic     
 .         
New Project   ActiveX EXE  ActiveX DLL (. 8.7).   
       , 
    . 

    :     ,   . 

    8.3.2.    

        ActiveX DLL  ActiveX EXE   
  ,      . 
-   I       Project Properties ( 
 Project | Project   | Properties) (. 8.8).     
   General. 

    Project Type 

     Project Type   : Standard EXE, ActiveX EXE, 
ActiveX DLL  ActiveX Control.     ActiveX DLL  
ActiveX EXE Visual Basic   Project Type . 


     8.    ActiveX     197 


    . 8.7.   Visual Basic. 
    . 8.8.  General   Project Properties. 


    198	    ActiveX 

            
. ,     Standard EXE,    
Component . 

    Startup Object 

       ActiveX EXE  ActiveX DLL   Startup 
Object  (None).  ,     
 ,      ,   Startup 
Object   Sub Main.       
       -;  Sub   Main. 

    Project Name 

     Project Name  ,  -  
    . 
           -,   
 j   clsPassWord    Server2:	I 

    ' -    Dim x As 
Server2.clsPassWord Set x = New Server2.clsPassWord 
    ' -     
    Dim x As Object 
    Set x = CreateObject ( "Server2.clsPassWord") 
    Project Description 

     Project Description      
 ActiveX  ,   .    
    References   ,   
  Available References.        
  Object Browser (. . 1.7). 

    Unattended Execution 

     Unattended Execution ,     
    .    
  .     , 
  ,      ,  
     . 

    8.3.3.     

           ActiveX  
       ,   
  . 

     Name 

     Name  -    
 ,    Class'1     Projectl, 
      -    
 : 

    Dim  x  As   Projectl.Classl Set   x  =  New   Projectl.Classl 


     Instancing 

     Instancing ,   ,    
     ,   ,    
   


     8.    ActiveX 199 


    :  Instancing  Visual Basic 5.0   
   Public  Visual Basic 4.0. 

      ActiveX EXE  ActiveX DLL    
Instancing ,     : 

    ActiveX DLL 

    . 8.9.   Instancing   ActiveX EXE  ActiveX DLL. 

         Instancing .   
"  "  7. 

    8.3.4.   

        ActiveX   
.     .  .dll,   
     Project Properties. 

       

       ActiveX EXE  ActiveX DLL Visual Basic  
     ,    
    . 
      Project Compatibility   Component   
Project Properties   .    
Visual Basic         
   . 
      ,      
,    Project Compatibility (,  
 ), Visual Basic       
   . 
       ,   Visual Basic, . 
  " ". 

    ActiveX EXE 

    200	   ActiveX 


    8.3.5.   

        ActiveX   ,  
   . 
       ActiveX      
 .    : 
    	 ; 
    	    Setup; 
    	       /Regserver. 
    Visual Basic   ActiveX DLL   .  
  DLL     Regsvr32.exe,  
    

    Regsvr32.exe   dlll.dll 

         DLL  -   
 |  References. 

           ActiveX EXE, 
        /UnRegserver; 

    Serverl.Exe   /UnRegserver 

          ActiveX DLL   
Regsvr32.e   /    DLL,     : 

    Regsvr32.exe   /u  dlll.dll 

    8.4.    ActiveX 

    Microsoft Visual Basic        
    in-process      
out-of-process.        
  Visual Basic.      
   . 
       ,    ActiveX DLL  ActiveX 
EXE,        .   
    -    
   

    8.4.1.    

          ActiveX   
 ,      . 

     ActiveX DLL 

       ActiveX DLL,     
 ActiveX DLL  Standard EXE    in-process 
   Visual Basic.    
        
 in-process. 

     ActiveX EXE 

       ActiveX EXE    
   Visual Basic,      
  Visual Basic.       
    ,      
    Visual Basic. 


     8.    ActiveX	201 


    8.4.2.      

            
  Visual Basic    . 
        Object Browser   
  .      
,       References. 
          
             
   : 
        .        
   .    Visual 
Basic      ,   
   ,     . (  
      ,     
 (, ),   .  
        
  ).    , 
   ,       
   vtable; 
        .      
 ; 
        Help.         
 ,    . 
           
vtable .   "  "  7 "    ActiveX". 

    8.4.3.   

             
  ,     Visual Basic.    
  -     
  :   ,   
 ,      . 

       

              
: "Connection to type library or object library for remote process has 
been lost. Press OK for dialog to remove reference" (    
     _   .  
      ). 
      ,     (GUID) 
          
 . 
       ,      .  
  References      MISSING.  
       . 
            . 
 " "   7 "    ActiveX". 
      ,     GUID, . 
 "   "   7. 


    202	   ActiveX 


    8.4.4.    

            . 
 ,       ,  
    . 
     -   ,  
,         
 : 
        ,    -.  
         : 
         ,  -  
  . 

      

       ,  -,  
 Raise  Err,     -. 
      . 
     -     
 ,   On Error Resume Next   
    On Error Goto. 

       

       ,  -, 
  .    ,  
,      ,  . 
        ,  - 
    .    
      . 

    8.4.5.    

             
   Raise  Err. 
     ,  ,     
(),         . 

        

       ActiveX      
 -.        
 Raise      . 
     Raise   : 

    /n.Raise , , , 1_, 1_ 

       Raise: 


     8.    ActiveX 203 

            : 
      : 

    Dim Salaryl As Single 
    Public Property Let Salary(ByVal newSalary As Single) If newSalary < 0 Then 
    Err.Raise 12345 + vbObjectError, , "   " Else 
    Salaryl = newSalary End If End Property 
    Public Property Get Salary () As Single 
    Salary = Salaryl End Property 

      -: 

    Private Sub Commandl__Click () Dim x As Company.Employee 

         

    On Error GoTo HandleError Set x = New Company.Employee 

                                  . 

      Err.                    
    .   Long, 
     .  Visual Basic 
(  )     0  65535. 
       Number      
,                        vbObjectError. 
,     999,     
Number  Err  vbObjectError + 999.   
  -.  ,    
      Visual Basic.            
    .  ,     , 
  .    ,  
    Visual Basic.              
    .  ,   .    
,   .        
 Visual Basic,     Visual Basic.  
   ,   "Application-defined or 
object-defined error" (,     ). 
1_           
    .    ,    
 .   , Visual Basic      
 Visual Basic. help_KOHmeKcm 1 .   
    1   . 


    204   


    .Salary = -50 '    
    MsgBox x.Salary 
    Exit Sub HandleError: If Err.Number = 12345 + vbObjectError Then 
    MsgBox "   " End If End Sub 

       

      Visual Basic      
      Error Trapping   
General   Options.     ,    
     ,      
  . 
            : 

    	 

    Break on All Errors	         
  
    Break in Class Module	      
  ,        
.     ActiveX    
- ActiveX         
  ActiveX,         
,      . 
    Break on Unhandled Errors	    ,  
    .     
  ,       . 
          
    . 

    8.5.   

            
   .    ,  
  , ,    
,   . 
    ,      ,  
       .  
   . 

    8.5.1.    

            
 : 
    1.  . 
    2.  . 

     8.    ActiveX	205 
      
        Declarations     
  Event.      ,  
 : 
    Public Event Status(ByVal StatusText As String) 
      
         -,  
 RaiseEvent          
.       Status: 
    '   ,        Public   Sub  SubmitOrder() 
    RaiseEvent  Status ("    ...") 
    '   ,       
    EndTime   =  Timer   +   2 
    Do  While   Timer  <   EndTime 
    DoEvents Loop 
    RaiseEvent   Status ("   ...") 
    '      
    EndTime   =   Timer  +   2 
    Do  While   Timer   <   EndTime 
    DoEvents Loop End  Sub 
             
-    . 
    8.5.2.    - 
      ,     
ActiveX,    : 
    1.   WithEvents. 
    2.    . 
    3.   ,    WithEvents. 
      WithEvents 
     WithEvents      ,  
    .     
 Dim    WithEvents,    : 
    Dim WithEvents Order As Projectl.Classl 
       WithEvents      
  ,     (. 8.10). 
        
     ,    WithEvents,   
,     : 


    206   


    . 8.10.    With Events     
   . 

    Private   Sub  Order_Status(ByVal   StatusText  As   String) 
    Debug.Print   StatusText   '	         Immediate End  Sub 

       

       ,   ,   
    ,     
WithEvents,    ,    
    .     
   Order;   SubmitOrder,  
   (. 8.11): 

    Private   Sub Commandl_Click() Set Order = New Projectl.C Order.SubmitOrder 
    End  Sub 
    :iassl 

           . 
  "    "  7 "   
 ActiveX" 

    8.5.3.       

          , 
      . 
    ,      ,    
 ,      .  
  ,    ,    
      . 
       : 
    1.    ,     . 
         -,   
     . 


     8.    ActiveX 207 


    . 8.11.    . 

    2.   Timer    ,   
,  . 
    3.     ,    
,   ,    . 
    4.         . 
    -   ,    
.         
 . 

    :   ,   
 ,    .     
        
  Timer    Windows API SetTimer  KHITimer. 

       

         ,  
         . 
           , 
     ,    Cancel. 
, , 


    208	  

           Cancel  True, 
   . ,   
-    :	' 

    Dim WithEvents   x  As   Objectl Sub.... 
    x.DoAsynchronousTask 
    CancelDialog.Show   '               _ "" 
    End  Sub 
    Sub x_InProgress(PercentDone, bCancel) 
    '       
    bCancel = CancelDialog.bCancel 
    End Sub 

            : 

    Dim bCancel   as   Boolean Event   InProgress(ByVal  pd  as   Long, ByRef  
 cancel   as   Boolean) 
    Private   Sub   ...(...) 
    bCancel = False 
    RaiseEvent InProgress(percent, bCancel) If bCancel Then '   End If 
    End Sub 

     ,  , ,    
-   ,   "".   
   Boolean bCancel    , 
 ,     "".     
   "",  bCancel   Sub 
  True    If    InProgress 
  . 

    :   InProgress    ByVal  
  ,   ,    
,    .    ByRef, 
, ,      . 

    8.6.   

       ,   ,   
    .   
      ( ), 
 .    ,  
 . 
          : 1. 
  . 


     8.    ActiveX	209 

    2.  ,    . 
    3.  -,   . 
       ,        
     ,  
      . 

    8.6.1.   

         ,    
     ,    
   . 

       

           ,  
    .      
        . 
          Implements   
    Declarations   .  
      . 
        : 
            ; 
              
   ( ); 
              
 ,      
   . 

         

            
,     .     
,  -,    
,   ,      . 
       ,   ,  
    -,  
 .      ,  
 ,         . 
    ,    , .   " ". 
        .   " 
"  7 "  ActiveX". 

       

            Visual Basic: 1. 
  . 
    )     ActiveX EXE  ActiveX DLL. 
    )         . 
    )     . 
    )     File   Make <  >,   
  . 


    210	  

         .  DLL   
} ,   Implements   ,  
 . 
              
- : 
    '                  
    IPayroll 
    Public Sub Calculate() 
    '       End Sub 
    Public Sub Deposit() 
    '  -     
    End Sub 
    2.      . 
    )          . 
    )   Implements,  ,   
 ,   . 
    )          
  : . 
    )    . 
            ,  
   ,    : 

    '               ,       
    '    
    '        IPayroll 
    Implements   IPayroll 
    Private   Sub   IPayroll_Calculate() 
    '            
    End   Sub 
    Private   Sub   IPayroll_Deposit() 
    '      -         
    '             End  Sub	, 

     ,    ,    
 '     ,   
  . 

    3.  -,    . 

    )   -    . 
    )  -    ,   
 . 
    )  . 
    )     Setup,   ,   
 ,      out-of-process. 


     8.    ActiveX	211 


    8.7.     

             
   . 

    8.7.1.    

         ,   
         
  . 
    ,     ,    
Yes  No,       vbYesNo 
  .      
  . 

       

           
,  . 
        ,      
    : 

    '            Public   Enum  Temp	' 
    Cold  =   -5 
    Warm  =18 
    Hot   =30 End  Enum 
    Public   Sub  ReportTemp (x  As   Temp) If  x   <   Cold  Then MsgBox   
"   " 
    End   If End   Sub 

          ,  
   Public       public,  
 . 
        ,   ,  
      . 

    :        
 . 

    :      ,    
       ,  
   ,   . , 
  VbDayof-Week  Visual Basic   
       vbMonday, vbTuesday  . . 

    8.7.2.     Help 

             
         
- . 
    : -      ,  
  . 


    212	    


            
   Procedure Attributes  Project Properties (. . 8.4). 
           - 
   Object Browser       
-,     . 
    :      Public,   
  ,      ,   
 Property. 
           : 
    1.      ActiveX. 
    2.       . 
    3.   Tools  Procedure Attributes. 
    4.   Description  Help Context ID   . 

    8.7.3.   

      Visual Basic ,   Public   
,         . 
            
-,    ,      
   DLL,       Instancing . 

      ActiveX 

        ActiveX     
Instancing   MultiUse     
 . 
            .  
          
    .       
     . 
        ActiveX    Instancing  
  SingleUse,      
       .  
          . 

    ActiveX DLL 

      ActiveX DLL,   Instancing   
 MultiUse ( PublicNotCreatable). -    
  ,   -. 
      -    DLL,  
       . ,   
-    ,   
   DLL      . 

    8.7.4.   Friend 

     ,      
  ,        
-,     Friend,   
  ,         
  . 


     8.    ActiveX 213 


     Public      ,    
  .  Private     
,         . 
    ,     Friend (""),   
  ,    ,    Friend  
        public . 

    :    Friend     
Property.  Property,   ,    
 . 

        VB  Class'1     Class2: 

    '       Classl 
    '              , 
    '            
    Friend  Sub  VB () 
    MsgBox "Visual Basic" End Sub 
    '   Class2 Public Sub HiVB() 
    Dim x As New Classl 
    x.VB End Sub 
    '     ( , '   ) 
Private Sub Form_Load() 
    Dim xl As New Class2 
    xl .HiVB End Sub 

    . 8.12.   Friend. 


    214	    


    8.7.5.    

            
      .    
     . ,  Microsoft 
Excel  Button ()      .   
   Worksheet ( ).    Button  
-     CreateObject   
Set  = New .   Button   Add,  
  Worksheet. 
     Visual Basic     ActiveX,  
   .    , 
   ,    ,  . 
         ActiveX   : 
    1.    ,    Instancing  
 SingleUse  MultiUse. 
    2.   ,   Instancing   PublicNotCreatable. 
          ,    
       . 

    8.7.6.     

           .  
Visuai Basic  Collection   .     
  ,    : 

    Dim Employees  As  New  Collection 

      Collection    Add  Remove (  
)   Count (   ).   
     Employee,    
 Employees: 

    Public Sub AddEmp (s As String, i As Integer) 
    Dim Emp As New Employee '      
    Emp.FName = s 
    Emp.ID = i 
    Employees.Add Item:=Emp, Key:=Emp.ID '     :: 
End Sub 

             
     . ,     
,  Employees       
   : 

    Private   Sub   cmdPrintEmployees_Click() 
    For  Each  x   In  Employees Print  x.FName,   x.ID 
    Next   x End  Sub 


    8.7.7.   

    Visual Basic   ,   
 ,    , 
     .   
 ,  Project Properties   Project    
 Component   Project Properties. 


     8.    ActiveX 215 


    Project2 - Project Properties 

    . 8.13.  Component   Project Properties. 

      Version Compatibility      , 
   : 

             | __ ___________	___  ______ 

    No	        
Compatibility j  ,     
.       . 
,      ,   
  .       
      -|     
   . 

    Project Compatibility 

            
,      ,  
       .  
       . 
    Binary	   Visual Basic    
Compatibility |   ,    ,  
        
. ,     ,  
.     ,   
,        , 
     . Visual Basic  
,        
      . 


    216 :    

        .   
"   "  7 "    ActiveX". 

    8.7.8.    

        -   
 "Component Busy", ,   . ,  
,     ,    
   . 
         ,   
  (, OLEServerBusyRaiseError, OLEServerBusyTimeout  OLEServerBusyMsgText) 
        ,    
   .       
 Component Busy. 

    Public  Const  App_Title  =   "     " 
    App.OLEServerBusyMsgTitle  =  App_Title 
    .OLEServerBusyMsgText   =   "        _     

     .   __              
,     _               " 

    8.8. :    

         ,    
  CreditCard       
     . 
         : 

    		 

    CardNumber	 	 
    ExpireDate	  	 
    PurchaseAmount	 	 
    Approve	 	 

    8.8.1.    

    1.    ActiveX DLL.    ActiveX DLL 
      . 
    2.   ,     : 

    	 

    Project Name	CC 
    Project Description	 " " 
    Unattended Execution	  
    3.    Name    CreditCard. 
    4.     Cc.cls    Cc.vbp. 


     8.    ActiveX	217 


    8.8.2.     

    1.   ,   Public,     
   : 

    | 	  
    CardNumber	Integer 
    ExpireDate	Date 

          .   " ". 
    2.   Property,     PurchaseAmount: 
    )   private   ,    
  . 
    )   Property Get    . 
    )   Property Let ,    
   .    ,   
 .    ,    . 
         .   
"  Property   ". 
    3.   Public,   Approve,   
  Boolean. 
         ,     
 True;        False. 
           :  
...  ... 
    PurchaseAmount   <   1000  And  ExpireDate   >  Now()      Approve  =  
True PurchaseAmount   >=   1000  And  ExpireDate   <=  Now()      Approve  =   False 
    4.  CardNumber     CreditCard ( 
 Procedure Attributes). 
         CreditCard    
 : 

    Option Explicit 
    Public CardNumber As Integer 
    Public ExpireDate As Date	..t1 
    Private msngAmount As Single 
    Public Property Get PurchaseAmount() As Single 
    PurchaseAmount = msngAmount End Property 
    Public Property Let PurchaseAmount(ByVal sngAmount As Single) If sngAmount 
> 0 Then 
    msngAmount = sngAmount '   private   Else ' 

    ;    

    msngAmount =  End If End Property 
    Public Function Approve() As Boolean 


    218	:     


    '        If msngAmount < 1000 
And ExpireDate > Now() Then 
    Approve = True Else 
    MsgBox "   - " 
    Approve = False End If End Function 

    5.  . 
    6.    Cc.dll. 

      .dll    Project Compatibility   
 Project Properties.  ,      
 , GU;C       -   . 

    8.8.3.  - 

    1.       CreditCard,  Add Project  
 File. 
    2.     ,  Standard EXE    
Open.      ,   . 
    3.    References     . 
    4.       1  .CreditCard. 
    5.     "" (  
CommandButton ,1   " " (TextBox). 
    6.     Click    
CommandButton -   : 

    Set   ccl   =  New  .CreditCard   '         CreditCard     ;.^ 
    Cc.dll	..      . 
    ccl.ExpireDate  =   "1/1/99" 
    ccl.PurchaseAmount   =  Textl.Text 
    ccl.CardNumber  =   1234 
    MsgBox  ccl.Approve 

    7.   Project Group (Project Explorer)     
Projectl    Set as Start Up    (. 8.14). 
       Forml     . 
    8.  ,     " "   
 "-".    F8,   
-   "L   " (Step Into)    
  . 
        PurchaseAmount    Approve 
     CreditCard. 
    9.    PurchaseAmount  2000.  Approve 
  False (.8.15). 

    8.9. :     

           - 
     Approve. 


     8.    ActiveX 219 


    . 8.14.      . 

    . 8.15.    . 

    8.9.1.     Status 

    1.    CreditCard    Approve  
  : 

    Public Event Status(ByVal StatusText As String) '   _ Declaration 
    Dim sngEndTime As Single 
    RaiseEvent Status ("  ...") 
    '       
    sngEndTime = Timer + 2 


    220 :     


    Do While Timer < sngEndTime 
    DoEvents '     Loop 
    RaiseEvent Status("  ...") '  
    sngEndTime = Timer + 2 Do While Timer < sngEndTime 
    DoEvents '     Loop 

          ,  , 
         . 
    ,  - 
   . 
    2.    CreditCard   Status    . 
    3.    Cc.dll. 
    4.  -  ,     
  (. . 8.16) 
    5.  -    1   
 With Events: 

    Dim WithEvents  ccl As  CC.CreditCard  '      Declaration  .:1:. 

      Visual Basic          
  ,  Status (. . 8.16). 
    6.   Status         
 (   Label2): 

    Private   Sub  ccl_Status(ByVal   StatusText  As   String) 
    Label2.Caption   =   StatusText End  Sub 

    7.      . 
                . 

    . 8.16.     . 

