DirListNav




Const vbKeyEnterKey = 13

Public Function CompletePath(C As Control) As String
On Error Goto CPErr
If Right(C.Path, 1) <> "\" Then 'Add trailing backslash
CompletePath = C.Path & "\"
Else'Trailing backslash already present
CompletePath = C.Path
End If
Exit Function
CPErr:
MsgBox Err.Description & " in Function CompletePath()", , App.Title
CompletePath = ""
End Function

Public Function CompletePathString(PathString As String) As String
On Error Goto CPErr
If Right(PathString, 1) <> "\" Then 'Add trailing backslash
CompletePathString = Trim(PathString) & "\"
Else'Trailing backslash already present
CompletePathString = Trim(PathString)
End If
Exit Function
CPErr:
MsgBox Err.Description & "Function CompletePathString()", , App.Title
CompletePathString = ""
End Function

Sub DirKeyPress(DirListBox As Control, KeyAscii As Integer)
Dim P% ' Stores the current ListIndex of the DirListBox control
On Error Resume Next
Static OP% 'Stores old path index. Used when this Sub is called again.
If KeyAscii = vbKeyEnterKey Then
P% = DirListBox.ListIndex
If P% <= -1 Then 'New path is parent of previous one
DirListBox.Path = DirListBox.List(P%)
OP% = DirListBox.ListIndex
Else'New path is one directory deeper than previous one
DirListBox.Path = DirListBox.List(P%)
End If
End If
DirListBox.Refresh
OP% = DirListBox.ListIndex
End Sub
Inputs:
Any required inputs are commented in the
Declarations section of the file.

Returns:
Any Returns are commented in the Declarations
section of the file.

This BAS file contains functions for use with the DirListBox
control.

The DirKeyPress() sub allows navigationof the standard VB
Directory Listbox control using the arrow and Enter keys
Usage:

in the Directory Listbox Keypress event, place this code

DirKeyPress Dir1, KeyAscii
Replace "Dir1" with the name of your DirListBox control
The code will do the rest

The CompletePath() function completes the path of a
Directory Listbox control by appending the trailing backslash
if needed, and returning the path as a String

Usage:
Anywhere you need it in your code
YourVariable=CompletePath(Dir1)

Replace "YourVariable" with the name of your variable
(must be a string type) and "Dir1" with the name of your
DirListBox control.

The CompletePathString() function completes the path of
a String variable passed to it by appending the trailing
backslash if needed, and returning the path as a String

Usage:
Anywhere you need it in your code

YourVariable=CompletePath(YourStringVariable)

Replace "YourVariable" with the name of your variable
(must be a string type) and "YourStringVariable" with the name
of the path string you want to complete.










( dirlistnav.html )- by Paolo Puglisi - Modifica del 17/12/2023