I have a number of CheckBoxes in a window (CBoxA, CBoxbB, etc…). And a number of corresponding properties (PrefCBoxA, PrefCBoxbB, etc…) where I store the value of those checkboxes.
Now I can make an array of those checkboxes by:
Var AllCheckBoxes() as DesktopControl
AllCheckBoxes.Add(CBoxA) etc...
with every entry is a reference to the checkbox object.
How can I make an arrays of properties (NOT of their values).
My goal is then to loop trough the arrays, and do:
PrefCBoxA= CBoxA.value
For example, this snippet locates the property named “Value” of the checkbox named “CheckBox1”, and sets it to True.
Dim props() As Introspection.PropertyInfo = Introspection.GetType(CheckBox1).GetProperties()
For Each prop As Introspection.PropertyInfo In props
If prop.Name = "Value" Then
prop.Value(CheckBox1) = True
End If
Next
Thanks Andrew. This help but does not solve the problem I am facing.
To clarify what I am trying to achieve is maybe better exemplified by that this code:
Var theArrayOfControls() as DesktopControl
theArrayOfControls.Add(CheckBoxAESounds)
which perfectly provide an array containing reference to instance of DesktopControls.
While this:
Var theArrayOfProperties() as Variant
theArrayOfProperties.Add(TestProperty) // defined as: Public Property TestProperty As string = "Luciano"
provides an array of the values of the corresponding properties, and not a reference to their instances.
It might be that Introspection is the way to achieve this, but I didn’t manage to do it.
The issue is that not all data types are objects that can be just references. The base types (Booleans, Integers, Strings, etc) are just data.
You could remedy this by creating a class which contains a property of the type you want and two operator_convert methods to get the value in and out.
Class BooleanType
Private Property mValue as Boolean
Sub operator_convert(value as Boolean)
mValue = value
End Sub
Function Operator_Convert as Boolean
Return mValue
End Function
End Class
Then instead of using Boolean, you use BooleanType in your code.