Solved

Executing a string

Posted on 1998-07-27
14
355 Views
Last Modified: 2011-09-20
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.
0
Comment
Question by:fred12
  • 5
  • 5
  • 2
  • +2
14 Comments
 
LVL 2

Expert Comment

by:percosolator
ID: 1466827
No.

What do you wish to accomplish?  

There's almost always another way to do something.

Tell me what you wish to do.


0
 

Author Comment

by:fred12
ID: 1466828
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
 
LVL 2

Expert Comment

by:percosolator
ID: 1466829
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
 

Author Comment

by:fred12
ID: 1466830
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
 
LVL 2

Expert Comment

by:percosolator
ID: 1466831
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
 

Author Comment

by:fred12
ID: 1466832
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
 
LVL 2

Expert Comment

by:percosolator
ID: 1466833
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Expert Comment

by:frankhommers
ID: 1466834
Try the microsoft scripting control. It'll allow you to execute VBScript or JScript code to an certain extend. (See the microsoft site).
0
 
LVL 39

Expert Comment

by:abel
ID: 1466835
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
 

Author Comment

by:fred12
ID: 1466836
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
 
LVL 2

Expert Comment

by:polygon
ID: 1466837
you may never get what you with VB. just forget about your it or make your own compiler?!?
0
 
LVL 2

Accepted Solution

by:
percosolator earned 50 total points
ID: 1466838
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
 
LVL 39

Expert Comment

by:abel
ID: 1466839
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
 

Author Comment

by:fred12
ID: 1466840
Thanks to all for your time and coments

No case statement I'm taking up "perl"
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now