Solved

Source Outside Project

Posted on 2003-11-29
11
368 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
ID: 9843610
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
ID: 9843806
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
ID: 9844221
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
ID: 9846426
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
ID: 9846433
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Accepted Solution

by:
rspahitz earned 75 total points
ID: 9846656
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
ID: 9847088
so....how do i tell it which file to get as the source?
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 9848137
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
ID: 9848238
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
ID: 9848258
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
ID: 9849054
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

919 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

16 Experts available now in Live!

Get 1:1 Help Now