Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: Soul Taker on November 24, 2004, 04:07 AM

Title: Treat a String as Code
Post by: Soul Taker on November 24, 2004, 04:07 AM
I may be overthinking this and missing an obvious way, but how do I treat a string as code to be executed?
For instance, say I have a string containing "Call SomeFunction(Param, Param2)";  how do I then actually execute the code contained in the string?
Title: Re: Treat a String as Code
Post by: MyndFyre on November 24, 2004, 04:25 AM
You would need to implement scripting.  I do not believe that this is otherwise inherently supported in Visual Basic; in JavaScript or PHP, you can use the eval() function to treat a string as code.
Title: Re: Treat a String as Code
Post by: K on November 24, 2004, 01:02 PM
not without using the microsoft script control (http://www.microsoft.com/downloads/details.aspx?FamilyId=D7E31492-2595-49E6-8C02-1426FEC693AC&displaylang=en). 
Title: Re: Treat a String as Code
Post by: UserLoser. on November 24, 2004, 01:31 PM
You might be able to use CallByName
Title: Re: Treat a String as Code
Post by: Soul Taker on November 25, 2004, 06:49 AM
 >:(
Doesn't look like CallByName would work for what I want.
Guess I'm going to have to skip this and find some complicated way to do it, thanks.
Title: Re: Treat a String as Code
Post by: dxoigmn on November 25, 2004, 08:07 AM
Quote from: Soul Taker on November 25, 2004, 06:49 AM
>:(
Doesn't look like CallByName would work for what I want.
Guess I'm going to have to skip this and find some complicated way to do it, thanks.

Well what is it you're really trying to accomplish?  Perhaps it can be done in way to use CallByName?
Title: Re: Treat a String as Code
Post by: Soul Taker on November 25, 2004, 10:21 AM
Quote from: dxoigmn on November 25, 2004, 08:07 AM
Quote from: Soul Taker on November 25, 2004, 06:49 AM
>:(
Doesn't look like CallByName would work for what I want.
Guess I'm going to have to skip this and find some complicated way to do it, thanks.

Well what is it you're really trying to accomplish?  Perhaps it can be done in way to use CallByName?
The only time I've used CallByName was to call control properties.  Unless it can be used for user-defined functions, it won't be useful to me.
I'm working on a workaround now anyway.  Sadly, it won't be as effective as just buffering a bunch of function calls into a string array and then quickly calling them like I wanted to, but it should do pretty much what I intended.