Running project from a network server?

#1
Is it possible to create a folder on a network server to hold my VBA projects and run them from there on about 10 different computers? I have been installing my projects on each computer in the common projects file, but it's starting to get hard to maintain. Whenever I make a revision to a project I have to reinstall it on all of the computers.

#2
bennieo,

There are various methods that you can use - it depends on the level of security you need.

It sounds like you code for internal CAD users and if this is so, here is one option.

You can access the VBA IDE and use an event to install the modules, forms or class modules from your server's location.

An event such as starting ICAD on the users machine will load your code into say the default drawing's IDE or even the CommonProjects.vbi file.

You will need to set a reference to the VBA IDE on each users version of ICAD and you can set this in the CommonProjects.vbi. Another option is to create an Add-In that auto-loads when the users start ICAD and loads your code.

To reference the VBA IDE, open the VBA IDE and select a project, say, CommonProjects.
Select Tools-->References from the pull-down menu. Scroll down and tick the box adjacent to "Microsoft Visual Basic For Applications Extensibility 5.3" then close the references form.

Now all the objects of the VBAIDE are available to you. You can even write code that writes code, this is sometimes quite a handy option if you find yourself re-typing in the same code all the time, such as error trapping code.

Yep there's nothing like programming the programming environment.




------------------
Regards
John Finlay

#3
I'm not sure I understand what I need to do. Are you saying that I need to write a module that will run when ICAD starts up. Then it will import all of my files from the server and put them into the CommonProjects.vbi?

Would you be willing to provide an example on how to do that or at least help me through it? It sounds a little advanced for my current skill level.

Thanks

#4
bennieo,

Yes that's what I’m saying as one option and I will help you through it.

So to get started we need to open the VBA IDE and select CommonProjects in your project window.

Insert a new module and place a sub named InsertOneModule in the code window.

Now select Tools-->References.. from the pull-down menu in the IDE. You should see three ticked references:
1/ Visual Basic for Applications
2/ IntelliCAD 2001 Object Library
3/ OLE Automation
These three are standard and 1 and 2 are required - try un-ticking these and an error message will appear.

Now scroll down to: Microsoft Visual Basic for Applications Extensibility 5.3 - tick the box adjacent to this and select OK to close the references window.

Now that we have a reference to the VBA IDE within our CommonProjects.vbi file it will continue to be referenced every time we use code in our CommonProjects.

So lets look at what we can do with the reference by looking at the objects exposed to us by the reference. Open the Object Browser and select the combo box where <All Libraries> are displayed and select the VBAIDE Library.

We now have the Objects, Properties, Methods and Events of the VBAIDE at our disposal!

Go-on have a look around, you will see Objects like VBComponents with an Import function and a Remove method.

You will need to export each of your modules, forms or class modules (VBComponents) that make-up your CommonProjects file. There is value doing this because they become smaller when each file is exported; Why? you ask! because it removes some of your redundant testing code and only leaves the VBA 'P' code required to compile and run the VBComponent.

Save the VBComponents in a separate file on your server and tomorrow we will write the code to Remove the VBComponents and Import new VBComponents from your server. This will mean any changes will be able to be updated at any time.




------------------
Regards
John Finlay

#5
John,
Here is what I've got so far:

Sub InsertOneModule()

Dim AddCompArray(0 To 10) As String 'Make array that will hold VBA components
Dim OldCompArray(0 To 10) As VBComponent 'Array to hold components to be removed
Dim i As Integer

'Existing components to be removed
OldCompArray(0) = "browsefolder.bas"
OldCompArray(1) = "fileopen.bas"

For i = 0 To 1 'The second number must match highest in component array
Application.VBE.ActiveVBProject.VBComponents.Remove (OldCompArray(i))
Next i

'Add new components here
AddCompArray(0) = "J:\DWG\VBA\browsefolder.bas"
AddCompArray(1) = "J:\DWG\VBA\fileopen.bas"

For i = 0 To 1 'The second number must match highest in component array
Application.VBE.ActiveVBProject.VBComponents.Import (AddCompArray(i))
Next i


End Sub


I am able to import the components but I haven't been able to remove them. Also, how can I check to see if the component exists in the CommonProjects.vbi so that I can avoid removing something that is not there?

[This message has been edited by bennieo (edited 10-23-2003).]

#6
I fount this in the help file, but haven't been able to figure out a way to control what is being removed.

Debug.Print Application.VBE.ActiveVBProject.VBComponents(4).Name


Application.VBE.ActiveVBProject.VBComponents.Remove Application.VBE.ActiveVBProject.VBComponents(4)

#7
bennieo,

Let's look at code to remove a module if it exists.

Function RemoveComponent(myCompName As String) As Boolean
' This Function will remove a Component such as a Module, Class Module
' or Form
Dim objRemoveComp As VBComponent

' Set the RemoveComponent Boolean to False as a default
RemoveComponent = False

' Remove the Componente named myCompName
For Each objRemoveComp In VBE.ActiveVBProject.VBComponents
If StrComp(objRemoveComp.Name, myCompName, vbBinaryCompare) = 0 Then
Application.VBE.ActiveVBProject.VBComponents.Remove objRemoveComp
RemoveComponent = True
End If
Next
End Function

All that happens is the function accepts the components name as an argument, uses a "For Each Next" loop to loop through each Component in the VBComponents collection. It tests the name of the Component using String Compare and if the name exists it removes the Component. It sets the Function Name to True meaning that it has found a Component with that name

To test the Function try:
Sub Test()
MsgBox "RemoveComponent = " & RemoveComponent("modTest")
End Sub

Where modTest is the name of the Component.

------------------
Regards
John Finlay

#8
bennieo,

Now let's look at adding a Component. We have to be carefull and test that it is not already installed because the VBAIDE will add an incrementing number to the Component and add it. This will result in additional Components cluttering up our ComonProjects file.

Code to add a component:

Function AddComponent(myCompName As String, myPathName As String) As Boolean
' This Function will add a Component such as a Module, Class Module
' or Form only if the Component is not installed. If we try to add
' another Component with the same name the VBAIDE will add a 1 to
' the name because each Component must have a unique name. This could
' result in the possibility of having non-required multiple Components.
Dim objAddComp As VBComponent
AddComponent = True

' Test for the existance of Component myCompName and if it exists
' then make AddComponent = False
For Each objAddComp In VBE.ActiveVBProject.VBComponents
If StrComp(objAddComp.Name, myCompName, vbBinaryCompare) = 0 Then
AddComponent = False
End If
Next

' Import the Component if AddComponent is True
If AddComponent = True Then
Application.VBE.ActiveVBProject.VBComponents.Import (myPathName)
End If

End Function

This is simmilar to the RemoveComponents Function using a Loop to test for the name.

To test the Function try:

Sub TestAdd()
Dim myCompLocation As String
' This is the Location and name of the component we want to add
' you need to add your own location
myCompLocation = "Z:\My Documents\ICAD Test\modTest.bas"
' The Function will return True if the Component is added and False
' if
MsgBox "AddComponent = " & AddComponent("modTest", myCompLocation)
End Sub

We now have the Functions to Remove and Add Components.

All we need now is to create the Function Calls code and some sort of event that will call this code when we start ICAD.

Try to post some code for this and if you have trouble I will assist.

------------------
Regards
John Finlay

#9
Thanks for your help.

I've been thinking about this project and have decided to go another route. Instead of running my update module when ICAD starts, I'm going to have it run from a form.

The reason for doing this is that my program contains file paths that are specific to each user. If the import process was automatic the user would have to change these paths every time they start ICAD. By running from a form, I can let everyone know when updates are available and they can run the update module.

This creates a new problem for me. After the components are imported I need to be able to replace the default paths with the user's path. For example:

myPath = "C:\My Documents\MYdwgs\"
needs to be replaced with
myPath = "C:\My Documents\USERdwgs\"

This change needs to be permanent (untill the user updates again).

I found this in the help file, but again I don't understand how it controls which module the code will go in and where it will be located.

For I = 1 to 26
Application.VBE.CodePanes(1).CodeModule.InsertLines I, Mid$("abcdefghijklmnopqrstuvwxyz", 1, I)
Next I
For I = 1 to 13
Application.VBE.CodePanes(1).CodeModule.ReplaceLine 2*I, Mid$("abcdefghijklmnopqrstuvwxyz", 1, I)
Next I

#10
bennieo,

I do not know exactly what you are doing, but could you store the user paths in and ini file or in the registry? I store various settings in ini files.

ssc

#11
bennieo,

You now have complete control over the programming environment.

This means that you can find paths in your code and replace your code with the correct paths based on your user's name. This can be activated in the users machine after automatically installing your forms and modules.

All you have to do is obtain the paths as strings prior to removing the components and use code to alter the paths in your code after adding the new components.



------------------
Regards
John Finlay