It is a Friday and I appear to have low firing neurons today. I believe the following should be simple, but I am not seeing it?
I have a function in every VBA project:
Public Function GetVersion() As String GetVersion = strVersionEnd Function
I then created a single utility to get version numbers for all vba projects.
Lets say I have a vba project called "myproject" and via a loop, this is loaded into a local variable, such that PrjName = "myproject"
The following code line returns the concatented string:
ProjectVersion = PrjName & ".GetVersion"Debug.Print "Version: " & ProjectVersion
However, I actually want the value from this string combination. How can I get the value?
For Example; this code directly reads the value of a variable from a vba project as required:
ProjectVersion = myproject.GetVersion
http://communities.bentley.com/products/microstation/microstation_programming/f/343173/p/91496/262350.aspx#262350
Hi,
ProjectVersion = PrjName & myproject.GetVersion
--Robert
Hi Robert,
As PrjName = myproject, your suggestion would result in the value myprojectmyproject.GetVersion being entered into the variable ProjectVersion.
What I am after is the value that a function GetVersion() returned from another project.
As I am looping through project names, I load PrjName with each project name, one at a time. When combining the projectname from this variable value with the function name, I get the string back not the value. Not particularly surprising, it is just that I cannot grasp how to cause the concatenated string to be treated as a call to the project > function.
I have not looked into this too much. Would you share your code with me? If I understand how you get your project names, then perhaps I could look at how to get this value.
Two of my quick thoughts--I think I've seen some code for a vba writing another vba... If you have the project name, you could have your vba write a vba to get the results from each project and return that value.
The other idea would be to use the .SendKeyIn to send a text line to Mstn ("vba run theOtherProjectName.GetVersion")--the trick is to get the value back from that...
Perhaps you can use mdlVBA_runProcedure:
Declare Function mdlVBA_runProcedure Lib "stdmdlbltin.dll" ( ByVal pResult As String , ByVal resultLength As Long , ByVal pProjectName As String , ByVal pModuleName As String , ByVal pProcedureName As String , ByVal nArguments As Long , ByRef pArguments As Long ) As Long
This seems to work...
Option Explicit'----------------------------------------------------------------------------' MDL function declarations must be at the beginning of the VBA module' that uses them'----------------------------------------------------------------------------Declare Function mdlVBA_runProcedure Lib "stdmdlbltin.dll" ( _ ByVal pResult As String, _ ByVal resultLength As Long, _ ByVal pProjectName As String, _ ByVal pModuleName As String, _ ByVal pProcedureName As String, _ ByVal nArguments As Long, _ ByRef pArguments As Long) As Long'---------------------------------------------------------------------------- Private Const strMODULE_NAME As String = "modMain"'---------------------------------------------------------------------------- Public Const strVERSION As String = "13.10.15"'----------------------------------------------------------------------------' GetForeignVersion' Get the version of another VBA project. This works only if:' 1 the other project has a module 'EE_Header'' 2 module 'EE_Header' contains a function returning a string named 'GetVersion''----------------------------------------------------------------------------Public Sub GetForeignVersion() Const Project As String = "EE_CommonUtilities2" Dim foreignVersion As String foreignVersion = GetProjectVersion(Project) Debug.Print "Project '" & Project & "' version: " & foreignVersionEnd Sub'----------------------------------------------------------------------------' GetProjectVersion' Wraps MDL function mdlVBA_runProcedure declared at beginning of module'----------------------------------------------------------------------------Private Function GetProjectVersion(ByVal projectName As String) As String Const SUCCESS As Long = 0 Const BufferLength As Long = 32 Dim result As String result = Space(BufferLength) Dim length As Long length = BufferLength If SUCCESS = mdlVBA_runProcedure( _ result, length, _ projectName, _ "EE_Header", _ "GetVersion", 0, 0) Then GetProjectVersion = result Else Dim msg As String msg = "Unable to execute EE_header.GetVersion in project '" & _ projectName & "'" ShowMessage msg, msg, msdMessageCenterPriorityError, True End If End Function'----------------------------------------------------------------------------
Regards, Jon Summers LA Solutions
Answer Verified By: cweber
Thankyou everyone for the help :)
I did add extra code to also include other Workspace-Project VBA files. I had to load and unload them for this, but everything works great now.