VB.NET – VB Based on string variable from module reference properties

I have a public attribute module (named constant, its value), none of which is associated with any specific object. I need to call these attributes based on the value in a string variable. The variable The value of will be the name of the attribute I need to use.

I know that the best candidate for this is CallByName, but this requires an object to get the attribute, as I mentioned, in This situation does not exist.

For example, the first value that the variable should take is “Master”. When I want to be able to use the variable to call the property Master() (the string declared as a public property Array).

Thanks in advance!

To me, it sounds like you are trying to use characters in the same way as Enum values String. There are several ways to do this, but here is a simple example that can help you think about how to parse a string into a constant programming problem.

Namespace Constants

Public Enum Priorities
Unknown = 0
Low = 1
Medium = 2
High = 3
VeryHigh = 4< br />End Enum

Public Class ConverterTo
Public Function Priority(ByVal value As String) As Constants.Priorities
Select Case value.ToLower
Case "low"
Return Priorities.Low
Case "medium"
Return Priorities.Medium
Case "high"
Return Priorities.High
Case "veryhigh"
Return Priorities.VeryHigh
Case Else
Return Priorities.Unknown
End Select
End Function
End Class
End Namespace

div>

I have a public attribute module (named constant, its value), none of which is related to any specific Objects are associated. I need to call these properties based on the value in a string variable. The value of the variable will be the name of the property I need to use.

I know that the best candidate for this is CallByName, but this requires an object to get the attribute, as I mentioned, it does not exist in this case.

For example, the first value that the variable should take is “Master”. When I I hope to be able to use this variable to call the property Master() (a string array declared as a public property).

Thanks in advance!

To me, it sounds like you are trying to use strings in the same way as Enum values. There are several ways to do this, But here is a simple example that can help you think about how to parse a string into a constant programming problem.

Namespace Constants

Public Enum Priorities
Unknown = 0
Low = 1
Medium = 2
High = 3
VeryHigh = 4
End Enum

Public Class ConverterTo
Public Function Priority(ByVal value As String) As Constants.Priorities
Select Case value.ToLower
Case "low"
Return Priorities.Low
Case "medium"
Return Priorities.Medium
Case "high"
Return Priorities.High
Case "veryhigh"
Return Priorities.VeryHigh
Case Else
Return Priorities.Unknown
End Select
End Function
End Class
End Namespace

Leave a Comment

Your email address will not be published.