Solved

Source Outside Project

Posted on 2003-11-29
11
369 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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
 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSRS expression Issue finding a string 10 79
TT Auto Dashboard 13 92
fso.FolderExists("\\server\HiddenFolder$") 4 66
backup program with robocopy 6 19
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

809 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