Running code from text file.
I know there is a way to get a code for a certein object from a text file, I just forgot where I saw that infomation. How can this be done?
Also: Is there a way to run 1 line of code from a textbox?
Ex:
VB Code:
'Textbox text: Msgbox "Sup", vbOkonly
Private Sub Command1_Click()
'runcode from textbox"
End Sub
Re: Running code from text file.
Quote:
Originally Posted by OuTLawZ-GoSu
Also: Is there a way to run 1 line of code from a textbox?
What do you intend to do with the code you want to run? As in what do you mean by run - what would be in the textbox?
Cheers,
RyanJ
Re: Running code from text file.
I do this with saved queries, and it is pretty simple. Something like
VB Code:
Private Sub Command1_Click()
Dim sSQL As String
Open "c:\DeleteQuery.txt" For Input As #1
Line Input #1, sSQL
Close #1
adoRs.Execute sSQL
End Sub
Re: Running code from text file.
I need the code in the textbox to do anything. In the textbox, I would put, " Msgbox "Look", vbOkOnly ", then click the button that would get the code from the text box and activate. So when I press the button, a message box will show up saying "Look".
BTW: I heard that VBScripts can do this. Is that true?
@Hack: What should be in the text file?
Re: Running code from text file.
Quote:
Originally Posted by OuTLawZ-GoSu
I need the code in the textbox to do anything. In the textbox, I would put, " Msgbox "Look", vbOkOnly ", then click the button that would get the code from the text box and activate. So when I press the button, a message box will show up saying "Look".
BTW: I heard that VBScripts can do this. Is that true?
@Hack: What should be in the text file?
Do you mean
VB Code:
Private Sub Command1_Click()
Msgbox Text1.Text
End Sub
Quote:
Originally Posted by OuTLawZ-GoSu
@Hack: What should be in the text file?
Anything you want. You can put a query, or you can put straight text. I just put "Hi OuTLawZ-GoSu" in a text file and saved it, then feed it to a message box like
VB Code:
Private Sub Command2_Click()
Dim strTextFromFile As String
Open "c:\test10.txt" For Input As #1
Line Input #1, strTextFromFile
Close #1
MsgBox strTextFromFile
End Sub
And the message box popped up what was in the text file.
Re: Running code from text file.
Let me get this staright, you want to compile code from the text file and run it through your program?
if so i dont think its possible or not easily anyhows.
Re: Running code from text file.
I have not done this before, but I recall reading that it is possible to execute VBScript commands dynamically by including a reference to the Windows Scripting Host. I would start there ...
Re: Running code from text file.
@Huck:
Na thats not what I meant.
I want to put any vbcode into a text file, then execute it by a button click.
Say I got this in a text file,
Private sub CmdCaption()
form1.Command1.Caption = "Caption 1"
End Sub
I want to load that code from the text file and apply it to the form.
Ex:
Code:
Private Sub Command1_Click()
LoadCode <text file address here>
End Sub
'The "loadcode" I made up for the exmple or what I'm looking for.
When I click Command1, the code from the text file executes. Changing Command's caption to "Caption 1".
And the textbox thing, I was thinkin that I could use the same meathod(the meathod that executes code from the text file) to execute code directly from a textbox.
Like,
If I got this code in a textbox, " Msgbox "Look", vbOKOnly " , and I press a button, the button will use the code thats in the textbox.
So it would look something like this:
VB Code:
Private Sub Command1_Click()
GetCode textbox.text
End Sub
The "loadcode" I made up for the exmple or what I'm looking for.
@BruiceG:
Do you know a link where I can find that info?
Re: Running code from text file.
Requires more research. I was trying to get something going by including a reference to the Windows Scripting Host, but could not get it to work. Sorry.
Re: Running code from text file.
yup
Bruce G
i did in same way by referencing Windows Script host..
and i m reacalling it was some sort of
Vbscript command
Eval ..
Re: Running code from text file.
I found this on one of the other forums, thx anyway though.
Quote:
You need to use Microsoft Script Control 1.0 go to project-->Refrances and add it. You can search goole and or this forum that should give you plent of info on how to use it. but here is the gist
VB Code:
Dim MyScript As New MSScriptControl.ScriptControl
MyScript.Language = "VBscript"
MyScript.AllowUI = True 'Not quite shue what this line does I have hardly used script contorl but that is what the tutorial i saw on it said to do.
MyScript.AddCode <your VBAcode As a string"
MyScript.Run <your Sub In the code To run>
Just so you know this does not run VB code as you are used to but VBA (or is it VBS if forgot) similart but more limuted verson of VB
Re: Running code from text file.
some thoughts
em... i guess what u need might be some sort of VB code interpreter. that could run the VB code on fly :)
but if that happened, that mean, people don't have to buy VB to code a VB application.
em, IMHO, you could try to code a simple interpreter for testing, which based on the HTML.
eg.
#LOOPS,5
<b>watsover</b>
#LOOPE
which would loop 5 times and u get the result
<b>watsover</b>
<b>watsover</b>
<b>watsover</b>
<b>watsover</b>
<b>watsover</b>
and we parse the enchanced HTML file line by line.
then you could go on IF THEN ELSE statement and so on ....
well, build your own language which probably have a snytax like VB?
Re: Running code from text file.
i asked exactly the same question, i wanted to do exactly the same thing.
-First go to Project -> References and go down the list to Microsoft Script Control 1.0
-After selecting and adding that, go to Project -> Components and go down the list to Microsoft Script Control 1.0
-Select and Apply that
-The icon will be on the left hand toolbox
-Put that on your form
-The simplest code for it is:
ScriptControl.ExecuteStatement text1.text
'ScriptControl' can be replaced by your name of it, as can 'text1'
There you go!!!
GTJ
Re: Running code from text file.
O yer forgot to add, ive been experimenting with it..
I can't get it to work with objects:
i typed a command to put text in a textbox, it didn't 'see' the object, nor does it a form or anything??
Tell me if you get it to work!!!
GTJ
Re: Running code from text file.
I am fairly certain that this is only done with vbscript or similar. I was looking to do the same myself and found this (Not a download link, download on page):
http://www.planet-source-code.com/vb...52204&lngWId=1
That should help in figuring out how to do it.
This next link goes to a program called Hal. It has the function of editing it's brain script...I think that was it...so some of the scripts it has may give you ideas. I don't know, as in it has been a while since I've seen it.
http://desktopmates.com/AI/Hal.html