About Visual Basic 6.0 development (below)

zhaozj2021-02-08  266

About Visual Basic 6.0 development (below)

2001-02-03 · New Day · Yesky

In the technical and application of Visual Basic 6.0 (on) (hereinafter referred to as above), we discussed the programming practice of classes, categories and classes of classes, in fact, the reason why class can be widely used in software engineering Application, the most important point is that it can be very convenient to encapsulate many of the programmed properties, which not only overcomes the complexity of the control (OCX) and link library (DLL) design and debugging, but also improves The simplicity and efficiency of the program code - this article will discuss the full class programming, including methods, attributes, and basic events. (1) Features and definitions of the attributes of the class; similar to the properties of the standard control, the attributes of the class allow the user to assign values ​​within the specified data range, which is shared by each code section within the class. The acquisition and delivery of the property needs to be programmed through the Property Let and the Property Get statement. Of course, we first need to define the corresponding variable definition of global or module-level in the class. (2) The attributes and basic definitions of the event; similar to the form of the form, the class also has two basic events, class_initialize (triggering time triggered) and class_terminate (triggered when unloading), these two events are private. In fact, we can ignore these two events - as long as you remember to improve the methods and properties of the class. The class can also define your own events. It is similar to the program's programming format, but only the WitHevents keyword is required to perform parameter declaration, and the event cannot have any named parameters or optional parameters, which has no return value. In fact, the structure and attributes of the structure can be fully replaced with complex classes of the structure. (3) Programming examples of classes, events, and attributes; the design purpose of this program is to transform all uppercase, lowercase and reverse sorting of the content of the text box in the class control form. In order to facilitate the writing and call of the code, I reference the enumeration programming method in the class.

The following code is in the class class1: Option Explicit Private WitHevents MyTXT AS TEXTBOX 'method's parameter interface public enum style Lcaseit' lowercase property LPIGIT 'uppercase properties NLOGOIT' reverse sorting property end enum 'custom enumeration, used to implement an automatic assignment of the property Private MVARBIAOZHI AS STYLE 'Implementing the Upset Done () AS String' 'DONE method for the specified enumeration done (), the' form text box is used to perform the corresponding character conversion operation 'and return a transformed string If mvarBiaozhi = Nlogoit Then dONE = StrReverse (myTXT) 'reverse order ElseIf mvarBiaozhi = Lcaseit Then dONE = LCase (myTXT)' forced lowercase conversion Else dONE = UCase (myTXT) 'mandatory capitalization conversion end If end Function' dONE method ends Public Property let Biaozhi (ByVal vData As sTYLE) 'obtained attribute is assigned a value mvarBiaozhi = vData End property Public property get Biaozhi () As sTYLE' passed attribute value to the class Set Biaozhi = mvarBiaozhi End property Public Sub Attach (itTEXT As TextBox) 'Connecting the method set mytxt = ittext end sub private sub class_initialize ()' This event activates the msgbox when the class load is loaded "Hello! This program shows you the skills, properties, events programming using the class!" End Sub private sub class_terminate () 'This event activates msgbox when the class is unloaded "Hello! Remember to fill in the code after the object to revoke the object!" End Sub' class is completed (4) Reference programming of form code; add text control Text1, drop-down list control combo1, command button Command1 (CAPTION = "start transformation", adjusting the three controls to the appropriate position in the form FORM1.

转载请注明原文地址:https://www.9cbs.com/read-3468.html

New Post(0)