Source Outside Project

I want the source of a VB project to be outside the project...for example....when the VB project is compiled, i want it to get its source from a text file....

It would be as if the code in the text file is in the compiled VB application.

would i have to open the file for binary or what?

the text file would contain code such as...

Sub InitForm()
End Sub

Sub InitSound()
End Sub

and whatever is in that text file is opened and added to the source of a form. can someone please help me?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You might have to make a batch file to compile your project.
I'm not sure how to do this, but the compiler is named 'C2' and is in the VB folder.
I'm not sure why you want to include something from outside of a project since, by definition, a project is a collection of code files used for an application.  This means that the textfile that you want to include is, by definition, part of the project.

So maybe what you want is to have your project dynamically include an external file of code?

This is not really as difficult as is seems, but it is indeed dangerous.

All you really need to do is to add a module to your project with a specific name ending with a .bas extension.

Any time you want to use a file with different code, just close the project, replace the file, and re-open the project then compile it.

If you want to perform the compile from outside of the VB-IDE, then you can simply locate the VB compiler (which depends on the version of VB) and run it with the proper command-line switches (many of which you can view by simply entering the compiler name with no parameters.)
Gamemaster328Author Commented:
im not sure i understand but....i would like to have the application(already compiled) to get codes from a text file outside the .exe file, such as inside a folder.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

If you want a compiled code to run external code then your best bet is to build that code into a dll and compile the dll.

If you want it to interpret code on the fly, you'll need to insert the scripting engine into the original project to have it read and interpret the code.  This is subject to huge potential error situations, so make sure you have plenty of error-trapping in place.
Gamemaster328Author Commented:
how do i do that? (not the dll. i want to be able to change the code without having to recompile over and over. that's the purpose of the outside source.
I really haven't used the feature much and don't have VB6 installed on this machine, but try going to the reference window from the menus, then select the MS Script object.

Once you've done that, add some code like this to a sub:

Dim objSource as MSScript 'or whatever the script class is

Set objSource = New MSScript

objSource.[execute] strExternalSource

Set objSource = nothing

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gamemaster328Author Commented: do i tell it which file to get as the source?
You'll probably want to add a Common Dialog Control and use that to allow the user to get it; if you already know it, simply retrieve it:

open "thefile.txt" for input as #1
strExternalSource = input$(lof(1), #1)
close #1

Gamemaster328Author Commented:
I am having trouble looking for the MS Script Object in the reference window.

Is it called:
Microsoft Script Control 1.0
Microsoft Script Runtime 1.0
Micfosoft Scriptlet Library

i ask because if i place this code OUTSIDE of a sub, i am getting an error on:
"Invalid outside proceedure"
Dim objSource as MSScript 'or whatever the script class is
(Set) objSource = New MSScript
objSource.[execute] strExternalSource
Set objSource = nothing

the "Set" in the parenthesis.

if i set this code inside the Form_Load() private sub, it errors:
"User defined-type not defined"
Dim (objSource as MSScript) 'or whatever the script class is
Set objSource = New MSScript
objSource.[execute] strExternalSource
Set objSource = nothing
Gamemaster328Author Commented:
i tried it and put it on a separate sub called InitScript()

I called it on the Form_Load() and it created no errors. The only error it creates is when i try to call InitForm(), which is in the text file. how would i be able to call subs inside the text file?
I'm not sure that you could call a sub inside the textfile since the compiler wants to know about all procedures at design time.

Again, I've never really used it extensively, so you may want to drop another Q (referencing this) and see if any experts respond.  You could title it something like "Using the VB Script Engine"

At this point, maybe it's time to ask why you need to have a file of external sourcecode that is interpreted at run-time.  This is done using VBScript in webpages, but typically not in compiled applications.

Maybe you should look into creating the app as an ActiveX application.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.