Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to create custom method / property in VB?
Message
 
To
05/09/2000 21:29:21
Marlou Gargantos
Independent Consultant
Manila, Philippines
General information
Forum:
Visual Basic
Category:
Other
Miscellaneous
Thread ID:
00412732
Message ID:
00412765
Views:
22
>Reuse is the issue here. In VFP, it's easy to create custom property and custom method. This feature is very useful because it gives us convenient way of doing things. I want to have a custom method which will contain a routine that will enable/disable particular controls or objects within a form. In VFP, I can easily create a custom method say ObjectEnable. It will contain the below method:
>
>LParameters lEnable
>With Thisform
>   .txtBox1.Enabled = lEnable
>   .txtBox2.Enabled = lEnable
>   .txtBox3.Enabled = !lEnable
>   .cmdDelete.Enabled = lEnable
>Endwith
>
>I can call the method anywhere in the form say in the click event of a particular button:
>
>Thisform.ObjectEnable(.T.) - To enable the controls
>
>or
>
>Thisform.ObjectEnable(.F.) - To disable the controls
>
>I don't how to do it in VB?

The VB code to do this is the same, except that you must write your method in code. Open the code window of your form and insert this code:
Private Sub ObjectEnable(lEnable As Boolean)
    txtAddress1.Enabled = lEnable
    txtAddress2.Enabled = Not lEnable
End Sub
Note you do not use thisform. Use nothing or "Me."
Here is a trick you can use to hit all your TextBox controls:
    Dim loCtrl As TextBox
    For Each loCtrl In Me.Controls
        If TypeOf loCtrl Is TextBox Then
            loCtrl.Enabled = lEnable
        End If
    Next
George
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform