Executing a string

Is there a way to execute a string. (In clipper "&" before a variable executed the string as if were a line of code.) Is there a simple way without building an interpreter.
fred12Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

percosolatorCommented:
No.

What do you wish to accomplish?  

There's almost always another way to do something.

Tell me what you wish to do.


0
fred12Author Commented:
I want to use a database(or list box) to pass data to a variable and have that variable executed like it was a line of code. Ive done this in clipper, foxpro, dbase.
 I know I can parse the string and kinda make my own compiler but it would be limited to the commands I program.
 Is there another way.  
0
percosolatorCommented:
could you give me a little more to go on?  VB does not support anything like that.  

I have seen foxpro do it, so I'm with you in that respect.

Could you give a little background, and a simple example?
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

fred12Author Commented:
example:
variable="form1.enabled = true"
&variable        

this is the same as:
form1.enabled =true

 Of course this &variable does not work in vb. In clipper this was useful because you could use a huge database of commands, it was also very useful for writing/testing code while the exe was executing. Im trying to do the same in vb5. It was a great way to write code, and had lots of other uses.

0
percosolatorCommented:
Thought so.

Wanted to do something similar.  Wanted to soft-code an if-then statement, wound-up figuring out how to use SQL Server to evaluate the if-then statement.

You can't do it.  How I would proceed with this is to setup a case statement.

Select Case Comand ' (Deliberate miss-spelling there)

       Case 1:

           Form1.Enabled = True

End Select

or

Select Case Comand

       Case "Enable Form1"

           Form1.Enabled = True

End Select

Or such.

--

           
0
fred12Author Commented:
Thanks
Are you 100% sure. If not I will open question, if no solution is posted in few days re-answer. Unless of course your 100%
possitive.    

0
percosolatorCommented:
Yeah.  If it's possible, I'll will be so surprised that I'll drop dead from shock.

I asked two other programmers here. One's used FoxPro, and said, "Yeah, you can do it in FoxPro.  Not VB".  The other doesn't know if you can or not (new guy).

Not sure why you can't.  I've not used FoxPro in a long, long time. (learned on 2.5) It could be that VB's not an interpereter, but a compiler.

But by all means, leave the question open.  Maybe we can get somebody else's input.

I'm 99 & 44/100 % sure. <g>


(old soap ad, or somesuch)

Doug
0
frankhommersCommented:
Try the microsoft scripting control. It'll allow you to execute VBScript or JScript code to an certain extend. (See the microsoft site).
0
abelCommented:
This is something for AI!
Usually a compiled program cannot be modified at runtime. One of the main problems is that when you run your program as an exe, you cannot modify it, because it's locked by the system.
You will have to do your debugging in debugging mode and if you definitely want something like "Execute("Me.Show")" I suggest another solution:

Use C/C++. Make a smart program that looks up all available library-calls to all available libraries. Make it as smart as you want and make additional libraries for statements like "i=i+1". Let the user choose a libraty, a function and the variables. Use the API LoadLibrary and GetProcAddress and call the function.

This is a lot of work, but it can be done. From VB? Forget it, or make your own parser (with a select case statement).

When you succeed, upload it to the Web. There are probably a lot of people waiting for such a tool (maybe I go on making one by myself...). It would be a great testing tool for API's, but it'll be very difficult to simulate VB-statements with it.

One other way: look up the MSVBVM50.DLL and look at the export table. It'll be a lot of work as well, but using these functions you'll be able to emulate a lot of calls. Again, you have to make your parser in C.

I wish you good luck when you go for something like this! You'll need it. If I ever manage to make such a program, I'll try to find you and send it to you. Promised, word of honour!

Regards, Abel

IMPORTANT NOTE:
Try your hands on Perl (www.perl.com it's free and widely documented). You can program anything with it, it runs on compile time (you write a textfile, perl parses it and compiles it and then runs it) and you can modify code on the fly. You can even execute perl-statements with another perl-statement! Might be the programming language you need for this, but unfortunately it's mainly made for writing to stdout (meaning that it's a very useful program for use with Web-page creation). Luckily there are lots of additionals out there with which you can write full functional GUI code. Almost all of them are free to get as well.
0
fred12Author Commented:
Well percosolator, Im glad your not going to drop dead. Answer question in few days if no new comments appear, thanks again.

 Thanks for the comment frankhommers, its half of what I need.

 abel. Im afraid this is too much of tackle for me, However Im going to try pearl. If ever you do this in C I would appreciate  a copy My email is hbdevice@netcom.ca  
 Your comment were insightfull thanks alot.

0
polygonCommented:
you may never get what you with VB. just forget about your it or make your own compiler?!?
0
percosolatorCommented:
Well, fred12.  I would have really like to have been shown that it can be done; every now and then it would be useful.

You implementing the case statement approach?

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
abelCommented:
I will keep your email and let you know whenever I decide to make such a program and when it's finished.

Regards, Abel

PS1: The Perl function I was talking about is "eval".
PS2: It really is Perl, not Pearl.
0
fred12Author Commented:
Thanks to all for your time and coments

No case statement I'm taking up "perl"
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.