VB.Net - Casting variables to different Types

CType

1
2
dim x as system.decimal
x = CType(txtAssetID.Text, System.Decimal)

Occasionally I’ll place controls into arrays, pulling them out are quite difficult - because the array will be declared as an object, it will come as an object and none of the properties associated with that object are available.

In one case I placed a control of type UC_INPUT into panel object - If I want to place something into the VALUE property I could use a command similar to the following.

1
CType(pnlUps.Controls(x), uc_Input).Value = aRow(x).ToString

In another case, I placed multiple controls into that same panel object. If I wanted to initialize the VALUE propery of each I could do something like the following:

1
2
3
4
5
6
7
8
9
For Each aControl As Control In pnlUps.Controls
Select Case True
Case TypeOf (aControl) Is uc_Input
CType(aControl, uc_Input).Value = aRow(CType(aControl, uc_Input).ColumnName).ToString
Case TypeOf (aControl) Is uc_Input_checkbox
CType(aControl, uc_Input_checkbox).Value = aRow(CType(aControl, uc_Input_checkbox).ColumnName).ToString
Case Else
End Select
Next