VB Link to a property from a module based on a string variable

I have a module of common properties (called Constants for what it stands for), none of which are associated with any specific object. I need to call these properties based on the value in a string variable. This variable value will be the name of the property I need to use.

The best candidate I know for this type will be CallByName, but it requires an object to get a property, which, as I mentioned, does not exist in this case.

As an example, the first value a variable should take is "Master." When the time comes, I want to use this variable to call the Master () property (an array of strings declared as a public property).

Thanks in advance!

+4
source share
2 answers

It seems to me that you are trying to use strings in the same way that Enum values ​​work. There are several ways to do this, but here is a simple example that can help you think of ways to solve problems with your strings.

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
+1
source

So what I need to do is declare an instance of ConsObj (there has been a renaming since the initial publication), and this object is now passed to a function that infer values ​​from the properties.

Thanks to everyone for the suggestions, some gave me ideas on how best to do something else elsewhere in the script. Sorry, I never published the code, just a bit of a hassle, because the code is on the network without Internet access.

0
source

All Articles