CPS613 |
VB .NET Techniques and References | |
Miscellaneous Information |
Dim radios(4) As RadioButtonInitinalizing arrays of Objects is more cumbersome that arrays of literals (as shown in the documentation): The array needs to be populated element by element. For example,
radios(0) = RadioButton1 radios(1) = RadioButton2 radios(2) = RadioButton3 radios(3) = RadioButton4However, once this is done, one can iterate simply through the elements of an array using a for statement.
Both links in this section include good examples.
This functionality is well supported in Visual Studio but because it is unusual to design built-in controls that must work as a group, this requires some additional (minimal) work:
When you share a single handler between multiple controls, the parameter called sender is the control that invoked the event, i.e. the one that the user selected. As you will notice, sender is of type System.Object, so if you would like to acccess properties or methods for this control, you will first need to cast sender to the correct control type. In VB, there is no direct casting like in C or Java. Instead you can copy the variable of a generic type into another of a more specific type. So for example, if you are certain that sender is a RadioButton and you would like to access a RadioButton property or method, you can simply do the following:
Dim button As RadioButton = senderthen use button instead of sender.
Information that is specific to the clicked radio button can be found primarily in the Text property of that button since this is where the choice made by the user is described. VB has a few useful conversion functions to convert strings to other types of variables, in particular Cint can convert text to an integer. However, if it is not convenient to work with strings, the Tag property can be used to store (at design or code time) other more useful information like a key or index.