|
-
Aug 21st, 2004, 03:40 PM
#1
Thread Starter
Fanatic Member
*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:
Private Sub callMe()
MsgBox "U called the private sub callMe", vbInformation
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.
-
Aug 21st, 2004, 04:00 PM
#2
The picture isn't missing
Add the Microsoft Script Control.
To use it:
VB Code:
msscript.Language="VBScript" 'or JSScript
msscript.addcode "msgbox ""hello"""
Adding objects:
VB Code:
[b]public[/b] sub Test(str as string)
MsgBox str
End Sub
Private Sub form_load()
msscript.Language = "VBScript" 'or JSScript
msscript.AddObject "Whatever", Me 'adds an object called 'Whatever' which is actually the Form.
msscript.AddCode "Call Whatever.Test(""helloooo"")"
End Sub
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Aug 21st, 2004, 04:10 PM
#3
Thread Starter
Fanatic Member
I see..so i supose that i can't just load a txt containing a sub and just call it, right?
-
Aug 21st, 2004, 05:26 PM
#4
The picture isn't missing
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  .
-
Aug 22nd, 2004, 08:46 AM
#5
Thread Starter
Fanatic Member
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)
-
Aug 22nd, 2004, 11:25 AM
#6
Fanatic Member
So basically you want to create a module that resides in a text file?
-
Aug 22nd, 2004, 11:34 AM
#7
The picture isn't missing
Yeh it works you just don't know how it works. I'll show some code:
VB Code:
Private Sub Form_Load()
Dim file As String
Open "D:\code.txt" For Input As #1
file = Input$(LOF(1), 1)
Close #1
MSscript.AddCode file
MSscript.Run "SayThis", "Hello"
MsgBox MSscript.Run("Add", 5, 6)
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  .
-
Aug 22nd, 2004, 11:43 AM
#8
Thread Starter
Fanatic Member
-
Aug 22nd, 2004, 11:59 AM
#9
The picture isn't missing
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  .
-
Aug 22nd, 2004, 12:12 PM
#10
Thread Starter
Fanatic Member
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
-
Aug 22nd, 2004, 12:15 PM
#11
Thread Starter
Fanatic Member
o..an other question, may i use that for javascript also?
-
Aug 22nd, 2004, 12:20 PM
#12
The picture isn't missing
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  .
-
Aug 22nd, 2004, 01:03 PM
#13
Thread Starter
Fanatic Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|