Results 1 to 13 of 13

Thread: *Solved* [Load vb code and exec it?]

  1. #1

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972

    Question *Solved* [Load vb code and exec it?]

    Hi all,
    i don't even know how to start explaining this...

    let's see...i'd like to make a exe that loads a vbs or a txt or any kind of file containing vb code

    VB Code:
    1. Private Sub callMe()
    2.  MsgBox "U called the private sub callMe", vbInformation
    3. End Sub

    For exemple if i had that code in a txt, after loading it the program should exec or call that sub.

    I'm lost in here
    Last edited by TDQWERTY; Aug 22nd, 2004 at 12:09 PM.
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  2. #2
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Add the Microsoft Script Control.

    To use it:
    VB Code:
    1. msscript.Language="VBScript" 'or JSScript
    2. msscript.addcode "msgbox ""hello"""

    Adding objects:

    VB Code:
    1. [b]public[/b] sub Test(str as string)
    2.     MsgBox str
    3. End Sub
    4.  
    5. Private Sub form_load()
    6.     msscript.Language = "VBScript" 'or JSScript
    7.     msscript.AddObject "Whatever", Me 'adds an object called 'Whatever' which is actually the Form.
    8.     msscript.AddCode "Call Whatever.Test(""helloooo"")"
    9. End Sub
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  3. #3

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972
    I see..so i supose that i can't just load a txt containing a sub and just call it, right?
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  4. #4
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Of course you can... you just need some text of the code. Open the file and pass it through with ScriptControl.AddCode
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  5. #5

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972
    I think that u'r not understanding me well, i'l like to have a txt file containing several subs and i'd like to read the text file and call the subs that that text tile had inside (i know the sub names)
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  6. #6
    Fanatic Member
    Join Date
    Dec 2002
    Location
    North Carolina
    Posts
    734
    So basically you want to create a module that resides in a text file?

  7. #7
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Yeh it works you just don't know how it works. I'll show some code:
    VB Code:
    1. Private Sub Form_Load()
    2.     Dim file As String
    3.    
    4.     Open "D:\code.txt" For Input As #1
    5.     file = Input$(LOF(1), 1)
    6.     Close #1
    7.    
    8.     MSscript.AddCode file
    9.     MSscript.Run "SayThis", "Hello"
    10.     MsgBox MSscript.Run("Add", 5, 6)
    11. End Sub

    My code.txt contains this:
    Code:
    public sub SayThis(someStr)
    msgbox someStr
    end sub
    
    public function Add(Num1, Num2)
    add=num1+num2
    end function
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  8. #8

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972
    WOW! damn!
    Wonderfull job! I really would love to do that before!
    It's time to get my hands to work over opensource programs now!
    Thanks alot for your help. Now my brain is clear as water!
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  9. #9
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    You should know that it is just VBScript, not VB. There are many limitations to it.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  10. #10

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972
    ok, thanks for telling me i don't think it will be a problem. It will just be used for some subs, calcs and nothing very hard.
    i just hate to keep rebuilding the exe so many times for some little changes.
    thx again
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  11. #11

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972
    o..an other question, may i use that for javascript also?
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  12. #12
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Yes, you just need to set the Language property like I shows you in the first post.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  13. #13

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972
    ok!
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

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