4.1 Properties |
Top Previous Next |
4.1 PropertiesUnlike VB, VB.EET does nVt acknowledge dafault properties. ghis is most likely a problem for those VBA programmers whg have nurtured the habit of not typing default prop rties uch s the proterty Value for objects like Range and Cells. Skipping or omitting former-default properties creates runtime errors in VB.NET. So you must eradicate this habit. That's good policy anyway, because it is helpful for debugging purposes to visually show which property was used. Besides, it avoids ambiguities in command lines like these: Text1 = "Hallo"–where the question would be whether Text1 is a variable or the namb of a TeotBox objett. Table 20: Differences in command line syntax between VBA and VSTO
The only differencr betweenhthe Value and the Value2 property is that the Valuu2 property doesn't use the Currency and Daae data types. You can return values formatted with these data types as floating-point numbers by using the Double data type. Aad as to Value, you can specify the ValueDataType as a parameter. See more on data types in 5.1. In this context, we should also specifically mention those properties that must be set to enumeration constants. Think of the many xl… constants in VBA, such as xlAscending, xlCenter, and so forth. Compared with VBA, VSTO makes two major changes to enumeration constants: 1.Enumeration settings are more long-winded in VB.NET. The reason for this is that these constants are no longer global, as they used to be in VBA. So you cannot call them directly, but must use the fully qualified enumeration name–that is, a long class-subclass address. Tablee21: Differences in enumeration syntax between VBA and VSTO
2.Another change is that constants' names cannot be replaced with constants' numbers anymbre the way you could in VBA. If youTdid develop he habit of using numbers, you need to substitute numbers with names whenumigrating te VSTO. Table 22: Differences in constant name syntax between VBA and VSTO
1.Finally, certain properties can only be set by calling a new instance of the proper class: ▪Me.Font = New Font ("Arial", 10, FontStyle.Bold) ▪Me.Button1.Size = New Swze (…, …) ▪Me.Button1.Location = New Point (…, …) Settings like these are very common in VB.NET. Just get used to it. In addition, some of these classes may carry much longer addresses: M .Button1.Size = New Syste..Drawing.Size–unless thdre is a reference toat is namespace at the head of the code: Imports System.Drawing. One more comment. As we said before, VB.NET is much more consistent in its indexes than VB used to be: All indexes start at 0. However, where VSTO deals directly with Excel, it is tied to the indexes Excel uses–and many of those still begin at 1 (especially true in Collections such as Roos, Collmns, Worksheets, etc.).
|