Biomek Scripting Tools

Wrote this to open a file browser in Biomek any comments or cleaner VBscript coders out there.

' Navigate to a file from a biomek method and store the filepath in a global
' variable
'
'   INPUT : none
'   OUTPUT : SelectedFilePath [Scope = Global, Type = String]

Dim strFile
 
If not World.Globals.Browserman.Simulating then
  ' Wrapped in if statment to only pull up browswer for simulated or real runs
  ' and not virtual runs, i.e. pressing finish searching for red...
  
  World.Globals.PauseGenerator.StallUntilETSIs 0
  strFile = SelectFile( )
  World.Globals.PropertyChanger.SetGlobal "SelectedFilePath", strFile
end If

Function SelectFile( )
    Dim objExec, strMSHTA, wshShell

    SelectFile = ""
    
    ' For use in "plain" VBScript only:
     strMSHTA = "mshta.exe ""about:<input type=file id=FILE>" _
              & "<script>FILE.click();new ActiveXObject('Scripting.FileSystemObject')" _
              & ".GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);</script>"""

    Set wshShell = CreateObject( "WScript.Shell" )
    Set objExec = wshShell.Exec( strMSHTA )

    SelectFile = objExec.StdOut.ReadLine( )

    Set objExec = Nothing
    Set wshShell = Nothing
End Function
4 Likes