All our programs are located on a network drive in folders named after the first digit in the partnumber (programname).
As we are closing in on nearly 1000 programs, there can be a multitude of eyeballing the folders until the specific program
are found.
Option Explicit Dim objFSO, objFolder, objShell, strDirectory, firstchar, InputFolder, found, serverpath, objDLG Dim PCDApp, PCDPartPrograms, PCDPartProgram 'Dialog for programname/partnumber InputFolder = InputBox("Enter programname/partnumber: ", "Search program") 'Get the first char in part/programname firstchar = Left(InputFolder, 1) 'Hardcoded absolute serverpath = "\\server\searchpath\to\your_server\root\_PC-DMIS\Program" 'Assign searchpath using the first char in part/programname Select Case firstchar Case "1" strDirectory = serverpath & "\1-\" & InputFolder Case "2" strDirectory = serverpath & "\2-\" & InputFolder Case "3" strDirectory = serverpath & "\3-\" & InputFolder Case "4" strDirectory = serverpath & "\4-\" & InputFolder Case "5" strDirectory = serverpath & "\5-\" & InputFolder Case "6" strDirectory = serverpath & "\6-\" & InputFolder Case "7" strDirectory = serverpath & "\7-\" & InputFolder Case "8" strDirectory = serverpath & "\8-\" & InputFolder Case "9" strDirectory = serverpath & "\9-\" & InputFolder End Select If InputFolder = "" Then WScript.Quit End If 'Create filesystemobject Set objFSO = CreateObject("Scripting.FileSystemObject") 'Check if the folder exists If objFSO.FolderExists(strDirectory) Then Set objFolder = objFSO.GetFolder(strDirectory) 'WScript.Echo InputFolder & " found!" found = 1 Else WScript.Echo InputFolder & " was not found!" found = 0 End If 'If the folder existed, open it in Windows Explorer so the user can easily access the files in it If (found = 1) then Set objShell = CreateObject("WScript.Shell") objShell.run ("Explorer" &" " & strDirectory & "\" ) 'Create the Open dialog, but pause 500 ms so it gets focus WScript.Sleep 500 Set objDLG = CreateObject("UserAccounts.CommonDialog") objDLG.Filter = "PC-DMIS Programs|*.PRG|All files|*.*" objDLG.FilterIndex = 1 objDLG.InitialDir = strDirectory 'Show the Open dialog objDLG.ShowOpen 'If a program were chosen in the Open dialog, open it in PC-DMIS If objDLG.FileName <> "" Then Set PCDApp = CreateObject("PCDLRN.Application") Set PCDPartPrograms = PCDApp.PartPrograms PCDPartPrograms.Open objDLG.FileName, "CMM1" MsgBox "Program loaded in PC-DMIS.", vbInformation, "Info" End If 'Cleanup Set PCDPartPrograms = nothing Set PCDApp = nothing End If 'Finish WScript.Quit
Example:
My part is name 12345, so I create a folder in the '\\server_path\1-' folder named '12345'. I save my program in this folder.
When running the script, I enter the programname (12345) and the script searches '\\server_path' for the '1-' folder
(as the partname I entered begins with a '1'). It then opens the '\\server_path\1-' folder and looks for '12345'.
If found it will display an open dialog, listing all .PRG's found in that directory. Additionally, Windows Explorer will open
the folder to display the files in it, good if you have setup instructions located there too.
As always, tweak it to suit your needs.