Segments: Shortcuts

Introduction
This article demonstrates simple scripts to turn DesktopX objects into shortcuts.

Single Target
Insert the script below into an object. Drag and drop a file onto the object. Left-click to open the shortcut.

Dim FilePath

Sub Object_OnDropFiles(files) 'If a number of files are selected, choose the first one getonefile= Split(files, "|") getfirstfile = LBound(getonefile) FilePath = getonefile(getfirstfile) End Sub

'--Go to selected target on L-click Sub Object_OnLbuttonUp(x,y,dragged) If Not dragged Then On Error Resume Next Set Sh = CreateObject("WScript.Shell") Sh.Run (Chr(34)& FilePath & Chr(34)) Set Sh = Nothing End If End Sub

Multiple Targets
Dim gettargets

Sub Object_OnDropFiles(files) 'Put files into array gettargets= Split(files, "|") End Sub

'--Open targets on L-click Sub Object_OnLbuttonUp(x,y,dragged) If Not dragged Then For x = 0 To UBound(gettargets) On Error Resume Next Set Sh = CreateObject("WScript.Shell") Sh.Run (Chr(34)& gettargets(x) & Chr(34)) Set Sh = Nothing Next End If End Sub

Browse for Shortcut
Insert the script below. Right-click on object to browse for target. Left-click on object to open shortcut.

Dim FilePath

'--Go to selected target on L-click Sub Object_OnLbuttonUp(x,y,dragged) If Not dragged Then On Error Resume Next Set Sh = CreateObject("WScript.Shell") Sh.Run (Chr(34)& FilePath & Chr(34)) Set Sh = Nothing End If End Sub

'--Browse for target on R-click Function Object_OnRButtonUpEx(obj,x,y,dragged) If Not dragged Then Object_OnRButtonUpEx = True Opendialog End If End Function

'--Function to open folders dialog Sub Opendialog selectedfile = System.FolderDialog("", "", &H4000)'--Browse for all folders If selectedfile <> "" Then '--Only set target if user selects something FilePath = selectedfile End If End Sub

Comments/Suggestions
None right now.