dim txtbillto as textbox
dim txtshipto as textbox
txtshipto =txtbillto
the line of code txtshipto =txtbillto sets the text property of txtshipto to the
value in the text property of txtbillto . but what if that isn’t what you wanted?
what if, instead, you wanted to create an object reference in txtshipto that referred
to the object txtbillto ? you’d have to use this code:
set txtshipto =txtbillto
as you can see, default properties require you to use the set keyword to set refer-ences
from one object variable to another.
vb.net gets around this problem by getting rid of default properties. therefore, to
copy the text property from txtbillto into the text property of txtshipto ,you’d
have to use this code:
txtshipto.text =txtbillto.text
setting the two variables equal to each other sets a reference from one to the other. in
other words, you can set an object reference without the set keyword:
txtshipto =txtbillto ‘ object reference in vb..net
to be more precise, default properties without parameters are no longer supported.
default properties that require parameters are still valid. default properties with para-meters
are most common with collection classes, such as in ado. in an ado exam-ple,
if you assume that rs is an ado recordset, check out the following code:
rs.fields.item(x).value ‘ ok,,fully qualified
rs.fields(x).value ‘ ok,,because item is parameterized
rs.fields(x)‘ error,,because value is not parameterized
the easy solution is to fully qualify everything. this avoids any confusion about
which properties are parameterized and which are not. however, as you know from
your vb days, the number of dots you have should be minimized. the reason is that
each dot requires an ole lookup that slows you down. therefore, you should code
carefully when dealing with parameters.
subs and functions require parentheses
as you saw in the last chapter when you used the msgbox function, you must now
always use parentheses with functions, even if you are ignoring the return value. in
addition, you must use parentheses when calling subs, which you did not do in vb6.
for example, assume that you have this sub in both vb6 and vb.net:
sub foo(byval greeting as string)
‘ implementation code here
end sub
注册会员,创建你的web开发资料库,