Hi Everyone,
I'm having alot of trouble trying to get a VBA file to run on Startup. I have read the articles on both the LA Solutions page and also AskInga. I have also read numerous threads on this board but cannot work out what i am doing wrong.
I have downloaded the example files and have imported them to an existing VBA Project.
The mvba Project is auto loaded through the PCF config variable and works fine.
A Class Module has been imported with the hook events
the CheckForRasters is a small routine i have written that when run either through a command in MicroStation or playing Direct in Visual Basic works with no issues.
I have also imported the ModMain
Based on the above, is there something that that i'm missing to stop this working? I have tried to replace the "CheckForRasters" with a msgbox to show if its activate the msgbox but it seems to skip the whole thing.
Using V8i SS2 - 08.11.07.443 but havent tested on SS3 and same problem.
Thanks,
Robert Golding said:A Class Module has been imported with the hook events
Remove the comments from the Debug statements to see if the class is loaded. You can see Debug output in the VBA Immediate window.
Regards, Jon Summers LA Solutions
Hi Jon,
Nothing shows in the Window when i open a different DGN file. I've also tried to add breakpoints in various parts of the file to see if it breaks but it doesn't touch it. I'm not sure why its not loading as i have followed the instructions from various sources.
The only difference i can see is that i am trying to import this procedure into an existing project, where the examples were separate projects.
Robert Golding said:Nothing shows in the Window when i open a different DGN file
It looks like you're testing within a large VBA project. Create a small project solely for testing the project load/unload and DGN open/close classes.
The DGN Open/Close class (clsOpenClose) requires registration in your app. as described in the comments. Which is your project's Main entry point? That is, what's the key-in to start your project?
clsOpenClose
Thanks for the reply.
I did import the files into a large project, there is 1 mvba file that this particular client build has. There is no main start point as it depends on which item is selected from the menus in MicroStation. The menus will be something like
vba run [Proj]Load.LoadSetup
That will run this in the mvba file
Sub LoadSetup() frmDrgSetup.Show End Sub
As suggested, I did remove all parts that were imported into the project and tried to load the file that i downloaded from your website. I found that it would work, but as soon as i referenced my project it would stop working.
Is there anything else that i need to do? Or is it literally as simple as just ensuring the new project is auto loaded within MicroStation?
Robert Golding said:is it literally as simple as just ensuring the new project is auto loaded within MicroStation?
Yes!
Robert Golding said:I did remove all parts that were imported into the project and tried to load the file that i downloaded from your website. I found that it would work, but as soon as I referenced my project it would stop working
What do you mean by 'as soon as I referenced my project it would stop working'? You should copy the modules into your VBA project. That is, there's a class provides the OnProjectLoad subroutine. MicroStation recognises the name of that method and executes that automatically. See Overview of MicroStation Events in VBA help.
OnProjectLoad
For DGN file open/close you must register a class that provides the WithEvents interface. Create that class in the OnProjectLoad handler, so it sticks around while your project is loaded. See OnDesignFileOpened Event in VBA help.
WithEvents
Create a small test VBA project to isolate the project load and DGN open/close functionality from your big project. I think you're distracting yourself with all that menu code and other stuff. It's really quite simple. Once you understand how the project load and DGN open/close work you'll find it easy to incorporate them into your main project.
Sprinkle debug statements throughout your event handlers so you can see what's happening as the project loads and you open & close DGN files and models.
Would there be anything else stopping this from running? All of my other routines are just called from commands within MicroStation. There are no other events or anything that i know of.
Hi Robert,
From what I read in this thread, I suspect one or more of your Project's source code files might not be compiling and producing "undefined behavior" often seen as "doing nothing". For your project source code please verify the following:
If there are no problems compiling the project you will see no response from the VBA Editor. If however, there are (undetected problems), the Editor will be sure to provide hints on what is required to be fixed (as individual incremental errors to fix).
Although I did not have a chance to look at Jon's project I did create a MicroStation VBA template project (Search: MSVBAEvents.mvba) that can be helpful in understanding and implementing VBA events and order executed. If you try and find this template example useful and would like to see any additional items added feel free to let me know and I will directly update that file linked above.
HTH,Bob
Hi Bob,
I have compiled the project and it has no issues. I have also gone through and ensured that each was Option Explicit.
I am still having an issue getting the "Autorun" features to work. I have marked them for Autoload within the Project Manager but when opening and closing a file MicroStation seems to ignore the class altogether? Any other ideas for me to try?
Robert Golding said:I have also gone through and ensured that each was Option Explicit
One of the VBA IDE's options is to ensure that Option Explicit is alway specified.
Robert Golding said:I am still having an issue getting the "Autorun" features to work
Loading and Running a VBA project are two different things. You are correctly using the Project Manager to specify auto-load. That brings your VBA project into MicroStation memory, but does not run it.
There are at least two ways to run a loaded VBA project: maually tell MicroStation to run a procedure using VBA RUN [project]module.procedure, or automatically.
VBA RUN [project]module.procedure
MicroStation recognises your function name OnProjectLoad. If MicroStation finds that function when your project is loaded, it runs it automatically. Do whatever you need to do in OnProjectLoad.
One thing you might do in OnProjectLoad is to create your DGN Events class.