Results 1 to 15 of 15

Thread: Running code from text file.

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    7

    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:
    1. 'Textbox text:  Msgbox "Sup", vbOkonly
    2. Private Sub Command1_Click()
    3.        'runcode from textbox"
    4. End Sub

  2. #2
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    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
    My Blog.

    Ryan Jones.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Running code from text file.

    I do this with saved queries, and it is pretty simple. Something like
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim sSQL As String
    3. Open "c:\DeleteQuery.txt" For Input As #1
    4.      Line Input #1, sSQL
    5. Close #1
    6. adoRs.Execute sSQL
    7. End Sub

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    7

    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?
    Last edited by OuTLawZ-GoSu; Apr 11th, 2005 at 02:00 PM.
    -DrE-

    OuTLawZ Fo LiFe MoThA FuKa....

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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:
    1. Private Sub Command1_Click()
    2. Msgbox Text1.Text
    3. 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:
    1. Private Sub Command2_Click()
    2. Dim strTextFromFile As String
    3. Open "c:\test10.txt" For Input As #1
    4.      Line Input #1, strTextFromFile
    5. Close #1
    6. MsgBox strTextFromFile
    7. End Sub
    And the message box popped up what was in the text file.

  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    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.

  7. #7
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    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 ...
    "It's cold gin time again ..."

    Check out my website here.

  8. #8

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    7

    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:
    1. Private Sub Command1_Click()
    2. GetCode  textbox.text
    3. 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?
    Last edited by OuTLawZ-GoSu; Apr 11th, 2005 at 02:46 PM.
    -DrE-

    OuTLawZ Fo LiFe MoThA FuKa....

  9. #9
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    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.
    "It's cold gin time again ..."

    Check out my website here.

  10. #10
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    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 ..

  11. #11

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    7

    Re: Running code from text file.

    I found this on one of the other forums, thx anyway though.

    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:
    1. Dim MyScript As New MSScriptControl.ScriptControl
    2. MyScript.Language = "VBscript"
    3. 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.
    4. MyScript.AddCode <your VBAcode As a string"
    5. 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
    -DrE-

    OuTLawZ Fo LiFe MoThA FuKa....

  12. #12
    Addicted Member
    Join Date
    Mar 2005
    Posts
    158

    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?

  13. #13
    Hyperactive Member
    Join Date
    May 2005
    Location
    England
    Posts
    283

    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

  14. #14
    Hyperactive Member
    Join Date
    May 2005
    Location
    England
    Posts
    283

    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

  15. #15

    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

    The Storm has arrived...Are you ready?

    Noteidn't see anything about no images...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width