Solved

Source Outside Project

Posted on 2003-11-29
11
367 Views
Last Modified: 2010-05-01
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?
0
Comment
Question by:Gamemaster328
  • 5
  • 5
11 Comments
 
LVL 1

Expert Comment

by:TheBest
Comment Utility
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.
0
 
LVL 22

Expert Comment

by:rspahitz
Comment Utility
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.)
0
 

Author Comment

by:Gamemaster328
Comment Utility
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.
0
 
LVL 22

Expert Comment

by:rspahitz
Comment Utility
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.
0
 

Author Comment

by:Gamemaster328
Comment Utility
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.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 22

Accepted Solution

by:
rspahitz earned 75 total points
Comment Utility
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
0
 

Author Comment

by:Gamemaster328
Comment Utility
so....how do i tell it which file to get as the source?
0
 
LVL 22

Expert Comment

by:rspahitz
Comment Utility
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

0
 

Author Comment

by:Gamemaster328
Comment Utility
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
--------------------------------------------------------------------
0
 

Author Comment

by:Gamemaster328
Comment Utility
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?
0
 
LVL 22

Expert Comment

by:rspahitz
Comment Utility
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.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now