Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 30th, 2007, 11:33 AM
Registered User
 
Join Date: May 2005
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
Default Using Strings to Call objects

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.

 
Old June 1st, 2007, 10:48 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I don't think you'll be able to do this. The object needs to be able to be resolved before running the statement that instantiates it (as I understand it), and that isn't possible in your case.

You can call routines by name, but to do so you need to use a built-in function which is made just for that purpose. There is no equivalent function for object resolution by name.

I presume that the presence in code of the function to call procedures by name cause the compiler to store within the app the actual names of every possible candidate for such a call so as to be able to accomodate the call.
The Following User Says Thank You to BrianWren For This Useful Post:
rpjamess1 (December 21st, 2008)
 
Old June 1st, 2007, 11:43 AM
Registered User
 
Join Date: May 2005
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
Default

I found a work around that requires only 1 extra line of code per method call. It doesn't call the objects within the method, but still passes parameters to streamline what I'm trying to do. Thanks for your reply.






Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT php:function: call objects non static method polarbear Pro PHP 1 June 6th, 2008 05:39 PM
strings RoniR VB.NET 2002/2003 Basics 1 May 4th, 2007 02:55 PM
strings bschleusner C# 2005 3 February 27th, 2007 11:46 PM
How can I call COM+ objects on another computer jdmc C# 2 May 30th, 2006 05:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.