[V8i-SS2 VBA] reading variable from un-opened VBA Projects

Hi Folks,

I am writing a utility to  read utility versions for all my MVBA Projects. Will I need to open all in this code in order to do this?

I have highlighted where I got to so far.

 

' ---------------------------------------------------------------------
'   GetToolVersions
'   Lists all strVERSION values for all MVBA Utilities
'
'   Set a reference to the Microsoft Visual Basic for Applications
'   Extensibility 5.3 library (in Tools | References...)
'   VBIDE is the code name of this library.
' ---------------------------------------------------------------------
Public Sub GetToolVersions()
    '   Check for KeyinArguments
    Dim args()              As String
    Dim nArgs               As Integer
    args = Split(application.KeyinArguments, ",")
    nArgs = 1 + UBound(args) - LBound(args)
    If (1 < nArgs) Then
        Dim UName           As String
        Dim PWord           As String
        UName = args(1)
        PWord = args(2)
    Else
        '   Wrong number of arguments
    End If
   
    '   Prepare code project definitions
    Dim oVBE                As VBIDE.VBE
    Set oVBE = VBE
    Dim oProject            As VBIDE.VBProject
    Dim oProjects           As VBIDE.VBProjects
    Set oProjects = VBE.VBProjects
    Dim vbaAutoloads        As String
    Dim vbaProjects()       As String
    '   VBA requires the following as a variant and not a string
    Dim vbaProject          As Variant
   
    '   Get an array of AutoLoad VBA Project Names
    With ActiveWorkspace
        If .IsConfigurationVariableDefined("MS_VBAAUTOLOADPROJECTS") Then
            vbaAutoloads = .ConfigurationVariableValue("MS_VBAAUTOLOADPROJECTS", True)
        End If
        If .IsConfigurationVariableDefined("MS_VBAREQUIREDPROJECTS") Then
            vbaAutoloads = vbaAutoloads & ";" & .ConfigurationVariableValue("MS_VBAREQUIREDPROJECTS", True)
        End If
    End With
    vbaProjects = Split(vbaAutoloads, ";")
   
    '   Check each VBA project from list of AutoLoad VBA's
    Dim Count               As Long
    For Each vbaProject In vbaProjects
        '   Get MVBA as path and fullname
        Dim strName         As String
        Dim arrNames()      As String
        Dim intIndex        As Integer
        Dim PrjName         As String
        Dim strVersion      As String
        strName = vbaProjects(Count)
        arrNames = Split(strName, "\")
        intIndex = UBound(arrNames)
        PrjName = arrNames(intIndex)
        Debug.Print "File name: " & PrjName
        '   Get Procedure > Module constant strVERSION
        Dim oProj As VBProject
        Set oProj = vbaProject
        strVersion = oProj.EE_Header.strVersion
        Debug.Print "Version: " & strVersion
        Count = 1 + Count
    Next vbaProject
End Sub

Parents
  • Unknown said:
    I am writing a utility to  read utility versions for all my MVBA Projects. Will I need to open all in this code in order to do this?

    To read a file, whether it's Excel, Word, DGN or VBA, you must first open it.  It looks like you want to read some data in another VBA project, in which case that project must be...

    1. Accessible (i.e. MicroStation can find it using MS_VBASEARCHDIRECTORIES)
    2. Loaded into MicroStation's list of VBA projects

    I guess your question is really "Can I read a variable in another project without starting and running that project?" The answer is 'no'.  One solution might be to provide a GetVersion method in each project, that returns that project's data of interest...

    ' Code in OtherProject
    Public Function GetVersion () As String

      GetVersion = strVersion
    End Function

    Now you can execute that function with this call from your information-harvesting code...

    ' Code in InformationHarvester project
    Dim otherProjectVersion As String

    otherProjectVersion  = [OtherProject]module1.GetVersion

    That statement of course loads the other project, but it's not the other project's main entry point (by convention, Main()) so it does not fire up the entire project.  However, if the other project does some stuff automatically when it's loaded (i.e. an OnProjectLoad event handler) you can't prevent that happening.

     
    Regards, Jon Summers
    LA Solutions

    Answer Verified By: cweber 

  • Thankyou all for the feedback.

    I suspected that I would have to open each project, but was wondering whether there was another way around it.

    I believe that Jon's suggestion will be the simplest to implement. It also overcomes an issue with supplying a password when required.

    I had implemented something similar to what DanPaul offered once when dealing with ProjectWise. I deprecated it in the end as integration with MicroStation is nowhere near as good as it needs to be; I experienced many issues that only delving into PW API would resolve.

Reply
  • Thankyou all for the feedback.

    I suspected that I would have to open each project, but was wondering whether there was another way around it.

    I believe that Jon's suggestion will be the simplest to implement. It also overcomes an issue with supplying a password when required.

    I had implemented something similar to what DanPaul offered once when dealing with ProjectWise. I deprecated it in the end as integration with MicroStation is nowhere near as good as it needs to be; I experienced many issues that only delving into PW API would resolve.

Children