Subrigital function and parameters of VB COM programming base

xiaoxiao2021-03-06  86

I have already contacted the variables, attributes, and enumerations of the class, but how can we use them better?

Obviously, the child process is one of the way, and it has almost all Visual Basic programs, so here is to illustrate.

Add the following code to the CDOG class:

Public sub bark () msgbox "woo! Woo!" End Sub

The child here is most common, we can simply use myDog.bark to call it.

Let's try it out:

Change the code of form FORM1 Command button:

Dim mydog as cdog set mydog = new cdog mydog.name = "billy" mydog.bark set mydog = Nothing

It should be noted that in type "MyDog." Will pop up the corresponding list, each of the other colors have different types of small icons. For example, the Bark sub-process item is yellow-green, attribute is gray and blue, so that we can help us identify Bark is a method of MyDog objects.

Press F5 to run and test it.

In fact, in addition to the child, we can also add a function in your code. Here we don't exist, you can try it yourself. Because the function and the general sub-process are in addition to being in a class, its work is also the same. But don't forget that all sub-processes and functions have their own parameters.

Now let us imagine that there is a SLEEP method in the class. When we want to sleep or do DOG snoring, you have to call this method.

But how do we know when these small things wake up? This is a very interesting question that the answer is to use events.

When we type characters in the text editing box, you will generate a CHANGE event, and when we click the Command button, a Click event will be generated. Similarly, if you want to know when these small things wake up, you need to use the AWake event you're on the next section.

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

New Post(0)