/ Forums / Advansys Formativ / Formativ Creator / Organizing Code with Classes / Reply To: Organizing Code with Classes
September 11, 2008 at 3:05 pm
#5632
As you probably know, in VBS, you can create Class to defines an object, its properties and methods to control the object’s behavior. Please see the Visual Basic Script Guide for more information. You can access the guide from the Formativ Help menu.
The example code below create a class when then Applet start. The class object is destroyed at the end so you can use it in throughout the Applet (i.e. Form events, etc).
dim gMyClass '------------------------------------------------------------------------------- ' Main line processing '------------------------------------------------------------------------------- Sub Main(Client, GWEvent) set gMyClass = new CMyClass msgbox "Inside Main sub: " & gMyClass.DateTime gMyClass.UpdateDateTime() msgbox "Inside Main sub: " & gMyClass.DateTime MyDialog.showmodal set gMyClass = nothing End Sub '================================================================================ ' Description about my class '================================================================================ class CMyClass private iDateTime ' Constructor private sub class_initialize iDateTime = now end sub ' Destructor private sub class_terminate end sub ' Update date time public sub UpdateDateTime() iDateTime = now end sub public property get DateTime() DateTime = iDateTime end property public property let DateTime(aVal) iDateTime = aVal end property end class '================================================================================ ' On button click in the form '================================================================================ Sub MyDialogButton1Click(Sender) msgbox "on button click: " & gMyClass.DateTime gMyClass.UpdateDateTime() msgbox "on button click: " & gMyClass.DateTime End Sub
Hope I haven’t misunderstood your enquiry.
Regards,
Advansys Support