How to Return Property Value in VB6 Programming?

Saturday, September 5, 2009 ·

It is often needed to return property value of an object to perform a calculation or some other task in your Visual Basic Application. And in the most previous sample program I've written use this way to perform some calculations, and also some other tasks. For example in the sample program of How to Convert Degree from Celcius to Another in VB 6 Programming? also returning property value to be calculated, and then the result of calculation to set the property value of other object.

To return the value of an object property, you can use below syntax:
Variable = Object.Property
Object2.Property = Object1.Property

You can use the first syntax if you want to return the value of an object property into a variable, so the value will be kept in the variable.

You should use the second syntax if you want to return the value to set another object property value.

In the most sample program I've written in the previous postings use the second syntax to return value of an object property and perform the calculation, then the result kept as value of another object property.

Notice below sample code:
Text2.Text = Val(Text1.Text) * 1.8 + 32

The value of Text1.Text is returned and used as an operand in the calcuation phrase and the result of calculation then used as value of Text2.Text. In this example you don't need a variable to keep the calculation result.

Another example code:
strName = txtName.Text
lblName.Caption = txtName.Text

Any comment? Please leave it in the below comment box.


Post a Comment