It is possible to set variable for CMM-Manager file-path and/or version number. This variable could then be displayed in Report Header, Report User Note, or simply displayed for user as MsgBox() during program running.
The GetAbsolutePathName() method can be used to find the File Path of currently running CMM-Manager application. Once path is known the GetFileVersion() function is used to get file version details. The complete VB Script below can be added to CMM-Manager Program, the end result is VB Variables CurrentPath and CMMMgrVersion that contain file-path and file version respectively.
Example MsgBox() that displays info about file-path and version for currently running CMM-Manager
application.
- Dim FSO
- Set fso = CreateObject("Scripting.FileSystemObject")
- CurrentFolder= FSO.GetAbsolutePathName(".")
- CurrentPath = CurrentFolder + "\CMMMgr.exe"
- 'fallback - in case VB Engine does not find CMMMgr.exe successfully
- If FSO.FileExists(CurrentPath) Then
- Else
- MyMsg = MsgBox("Could not find CMM-Manager filepath" & Chr(13) & "Please locate CMMMgr.exe manually", 16)
- Set objWShell = CreateObject("WScript.Shell")
- Set ChooseFile = objWShell.Exec( "mshta.exe ""about: <input type=file id=X><script>X.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(X.value);close();resizeTo(0,0);</script>""" )
- CurrentPath = ChooseFile.StdOut.ReadAll
- ChrPos = InStr(CurrentPath, Chr(13))
- ChrPos = ChrPos -1
- CurrentPath = Left(CurrentPath, ChrPos)
- End If
- CMMMgrVersion = FSO.GetFileVersion(CurrentPath)
- MsgBox("CMM-Manager Path:"& Chr(13) & CurrentPath & Chr(13) & "CMM-Manager Version: " & CMMMgrVersion)
In case the FSO.GetAbsolutePathName(".") does not return a valid path, there is a fallback that allows user to select CMMMgr.exe manually as shown below:
It's also possible to pick a file folder. Depending on the application, it may useful to specify a folder vs. a file.
VB Script looks like this:
- Dim objFolder, objShell
- Set objShell = CreateObject("Shell.Application")
- Set objFolder = objShell.BrowseForFolder(0, "Please select the folder.", 1, "")
- MyFolder = objFolder.Self.path
- MsgBox("You picked the folder:" + Chr(10) + MyFolder)
Remember - any VB Variable can be saved to Report Header or Report User Notes