Tuesday, September 22, 2015

Dot notation

I don't know how to explain the Dot notation completely. So I will explain it with examples. For example, we consider of a cellphone. We can notate it like this.

phone

This is the object. From the cellphone, you can gain a lot of information. Now we try to gain the information of some phone number.

phone.phonenumber

We've added the property of phone number to the phone object.

Now we suppose that we want to use the property "phone number" as "2120000000" because this is your girlfriend's number which we want to manipulate here.

phone.phonenumber = "2120000000"

Now we have an object "phone" and the property "phonenumber", and the value "2120000000" for the property.

If we wanted to call someone with the cellphone, now we must use the phone. It is called doing a method.

phone.call

Method can come with parameters. With parameters, we can set the detail of the method. Maybe a parameter of the call method would be WhoToCall.

phone.call WhoToCall:=MOM

Note that there is a space between the method (call) and the parameter (WhoToCall), while there is no space between the equal sign and the value (MOM).

We might need more parameters for the call method. For example, we might have a VideoCall parameter and a IsSkypeCall parameter.

phone.call WhoToCall:=MOM VideoCall:=No IsSkypeCall:=No

To separate these parameters, we put a space between the 3 parameters.

Back to the Excel VBA. In the VBA programming we mainly use these "object," "method" and "parameter." For example, there is an object called ActiveCell which is cell where your cursor is currently is. We can use the ActiveCell object in the same way.

ActiveCell.Font

This shows the property "Font" of ActiveCell. Fonts have a name property all of their own. To reach to the information of the name property, place a dot after Font property, then type the Name property.

ActiveCell.Font.Name

A property needs a value, so now we set "Times New Roman" for the value of the property.

ActiveCell.Font.Name = "Times New Roman"

Now the font of the cell where your cursor is currently is is set to "Times New Roman." That is to say, this sets "Times New Roman" to be the font of the ActiveCell.

We can also set a bold value for the Font:

ActiveCell.Font.Bold = True


REFERENCES

HomeLearn "Dot notation" accessed on 22nd September 2015.