My program runs off a XML configuration file. This part of code comes from a DLL that will initialize, read, and write to the XML configuration file. I have found that my configuration values may change (add or remove values). As such I have tried to make a more flexible solution than statically reading and writing the values. The values are held in memory in nested user defined structures (I hope you can make that out).
CODE
Structure configValues
Public cfgUser As configGroup
Public cfgStartup As configGroup
Public cfgUpdate As configGroup
Public cfgMainForm As configGroup
End Structure
Public cfgUser As configGroup
Public cfgStartup As configGroup
Public cfgUpdate As configGroup
Public cfgMainForm As configGroup
End Structure
CODE
Structure configUser
Public cvProfileName As configValue
Public cvGGDN As configValue
Public cvBotsListSelect As configValue
Public cvBotsList As configValue
End Structure
Public cvProfileName As configValue
Public cvGGDN As configValue
Public cvBotsListSelect As configValue
Public cvBotsList As configValue
End Structure
CODE
Structure configGroup
Public iCount As Integer
Public aKeys() As configValue
Sub addKey(ByVal key As configValue)
ReDim Preserve Me.aKeys(iCount)
Me.aKeys(iCount) = key
Me.iCount += 1
End Sub
Sub addkey(ByVal strName As String, ByVal objValue As Object, ByVal tType As Object, ByVal objDefault As Object)
Dim key As New configValue
key.strName = strName
key.objValue = objValue
key.tType = tType
key.objDefault = objDefault
Me.addKey(key)
End Sub
End Structure
Public iCount As Integer
Public aKeys() As configValue
Sub addKey(ByVal key As configValue)
ReDim Preserve Me.aKeys(iCount)
Me.aKeys(iCount) = key
Me.iCount += 1
End Sub
Sub addkey(ByVal strName As String, ByVal objValue As Object, ByVal tType As Object, ByVal objDefault As Object)
Dim key As New configValue
key.strName = strName
key.objValue = objValue
key.tType = tType
key.objDefault = objDefault
Me.addKey(key)
End Sub
End Structure
A simple sample of the XML File.
CODE
<Config>
<User>
<Name>JoeBob</ Name >
< Exists>True</ Exists >
</User>
</Config>
<User>
<Name>JoeBob</ Name >
< Exists>True</ Exists >
</User>
</Config>
A function similar to what I will be using to read the XML.
CODE
strName = CType(configXMLDocument.GetElementsByTagName("Exists",Boolean)
Enough with the background, here is my problem. When reading the file I need to know what the type of objValue is, or in this case that Exists is a Boolean. This way I can put everything into a loop and just step through all the values without having to specify the type for each one. I guess I am wondering if there is a way to use a variable in the place of the type object (Boolean). Below is what I think should work but of course the complier completely blows up. If you need more details or a better explainiation let me know.
CODE
Dim t As System.Type = configValues.cfgUser.aKeys(1).objValue.GetType()
Dim b As Boolean = CType(configValues.cfgUser.aKeys(1).objValue, t)
Dim b As Boolean = CType(configValues.cfgUser.aKeys(1).objValue, t)


