Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
  • Welcome
  • Products
  • Support
  • About
  • More
  • Cancel
MicroStation Programming
  • Product Communities
  • Developers and Programming
  • MicroStation Programming
  • More
  • Cancel
MicroStation Programming
MicroStation Programming - Wiki Debugging
    • Sign in
    • MicroStation Programming - Wiki
    • -MicroStation CONNECT Edition
      • +MicroStation SDK
      • +MicroStation MDL
      • -MicroStation VBA
        • +MVBA FAQ
        • -MVBA Topics
          • CRUD example
          • Debugging
          • Documentation
          • Migration from VBA 6.x to 7.x
          • +MVBA Transforms
          • Network Shared Projects
          • Object model
          • Simple example with object library
          • Simple example with recording code
          • VBA Editor
          • VBA Integration with Applications
      • +Training
      • +Code Examples and Utilities
      • +Code Snippets
    • +MicroStation V8

     
     Questions about this article, topic, or product? Click here. 

    Debugging

    Debugging in MicroStation VBA – Visual Basic for Application

    VBA is providing a full IDE (integrated development environment) to allow access to all required components like object library, debugger and documentation from the IDE.

    VBA is integrated with Microstation and there are several ways to get access to the VBA tools.

    VBA is integrated in the MicroStation Utilities Ribbon Tab Macros and can be accessed from here:

    Also the main keyin “macro”  allows to direct access to create, edit, execute VBA and BMR macros:

    The additional shortcut ALT-F11 directly opens the VBA editor. If there is no VBA project load ALT-F11 returns with an entry to the Message center to remind loading a VBA project before opening the VBA editor. This can be done using the VBA Ribbon entries “VBA Manager” or “Open Macros”

    The open VBA Editor may look like this and the VBA project Explorer is listing all loaded projects, by default on the left side:

    The module, class or userform content is displayed by default on the right side of the Editor

    The “Debug” menu shows all options which can be used to debug a project:

    Breakpoints can be added or removed with a single click into the light gray column left to the source code and are marked with a dark red point and highlighted code line:

    TIP: Alternately for both Experienced VBA developers or those just Getting Started with Microsoft VBA there may be times when Debugging Microsoft VBA Applications using a "STOP" statement in your code may work best. This can be helpful during certain Microsoft and/or MicroStation VBA specific workflows, like: e.g. Launching VBA Applications using the OnProjectLoad event; where opening the Microsoft VBA Editor to manually set a BreakPoint (Insert or Toggle) as described in this topic may not be possible or convenient.

    There are different methods to execute the VBA code:

    If the MVBA project filename is stored in a folder listed in the MicroStation (MS) configuration variable MS_VBASEARCHDIRECTORIES, the following keyin can be used to start a subroutine:

    macro vba run [project]module.subroutine

    The keyin

    vba run [project]module.subroutine

    from V8i and previous versions can still be used for compatibility reasons

    If the VBA project is stored at any other location, the project file first needs to be loaded in order to be executed, example:

    [macro] vba load d:\programming\vba7projects\test.mvba [macro] vba execute [test]textstyletest.textstylesave

    (the keyword macro is optional as well for these keyins)

    If a breakpoint is set and during the execution a breakpoint is reached, the execution halts at this position, this is marked with a yellow highlighted line of code like this:

    This halt allows to verify the content of variables listed in the windows for “locals” or “Watches”:

     

    The execution can be continued using the play icon in the VBA editor shortcuts or F5:

     

    The play icon or F5 also can be used to start the execution of a VBA subroutine, the position of the cursor decides which subroutine is started. If nothing is marked, a dialog box with loaded macros opens to allow the user to select from:

     

    Context sensitive help for VBA keywords can be reached using the F1 key. It is important to notice, that 2 different VBA help files are available, one for the general VBA commands and one for the MicroStation related commands. Which of these help files are opened depends on the position of the cursor. E.g. the cursor is positioned in the source code on the keyword “ActiveDesignfile” a click on F1 opens the help for the MicroStation keyword ActiveDesignFile:

    Please note the header of the Help file points to MicroStation VBA documentation.

    In any other cases the general VBA help is opened, like here with a previous click on the keyword “Dim”:

      

     

    The VBA also allows to review the complete object library of the referenced libraries. From the menu “View” > Object Browser or F2 the Object libraries are listed like here:


     

    From the drop down list a specific library can be selected to obtain the details from. All classes with available properties and methods are listed. The search field allows to search for a class, property or method. E.g. the search for “textstyles” and click on method “Find” also provides the function declaration for the method Find:

      

     

    The context sensitive help also works in this view and the key F7 let the user come back to the code view.

    • VBA Programming
    • VBA
    • VBA Documentation
    • Share
    • History
    • More
    • Cancel
    • Artur Goldsweer Created by Bentley Colleague Artur Goldsweer
    • When: Fri, May 22 2020 6:32 AM
    • Robert Hook Last revision by Bentley Colleague Robert Hook
    • When: Thu, Sep 9 2021 8:18 AM
    • Revisions: 2
    • Comments: 0
    Recommended
    Related
    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2021 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies