I'm trying to cut down on processing time by creating a method that uses string to create object calls. For example:
I have an XML file with several fields. I am trying to populate a ListView using the data from the XML file. Normally, I would call the characterData object that contains the XML data. My code would look like:
Code:
Dim characterData As New CharacterData
Dim listItem As New ListViewItem
Dim skill(3) As String
skill(0) = "Appraise"
skill(1) = objRPG.SetTotal(txtInt1.Text, characterData.AppraiseMisc, characterData.AppraiseRanks).ToString
If characterData.AppraiseCheck = True Then
skill(2) = "Yes"
Else
skill(2) = "No"
End If
listItem = New ListViewItem(skill)
lstSkills.Items.Add(listItem)
skill(0) = "Astrogate"
skill(1) = objRPG.SetTotal(txtInt1.Text, characterData.AstrogateMisc, characterData.AstrogateRanks).ToString
If characterData.AstrogateCheck = True Then
skill(2) = "Yes"
Else
skill(2) = "No"
End If
listItem = New ListViewItem(skill)
lstSkills.Items.Add(listItem)
This works. The Ranks and Misc portions are simple number strings. The Check is either True or False.
I'm trying to create a method that will allow me to enter certain names and get the correct portions of the CharacterData object called.
For example:
Code:
AddItem("Appraise", "Int")
Private Sub AddItem(ByVal skillName As String, ByVal attributeName As String)
Dim ranks As Object = "characterData." & skillName & "Ranks"
Dim misc As Object = "characterData." & skillName & "Misc"
Dim attribute As String = "txt" & attributeName & "1.Text"
Dim check As Object = "characterData." & skillName & "Check"
Dim listItem As New ListViewItem
Dim skill(3) As String
skill(0) = skillName
skill(1) = objRPG.SetTotal(attribute, misc, ranks).ToString
If check = True Then
skill(2) = "Yes"
Else
skill(2) = "No"
End If
listItem = New ListViewItem(skill)
lstSkills.Items.Add(listItem)
End Sub
Here, I get a return that characterData.AppraiseCheck is a string and can't be converted to a Boolean. How can I pass a string paramter and have it added to an object call? Hopefully I've explained myself clearly enough.
Thanks in advance.