Visual Basic > Files Directories Drives
How to shorten a long directory name.
How to shorten a long directory name. ' This function will shorten a directory name to the ' length passed to the Max parameter. ' Add the function: Function LongDirFix (TargetString As String, Max As Integer) As String Dim i, LblLen, StringLen As Integer Dim TempString As String TempString = TargetString LblLen = Max If Len(TempString) <= LblLen Then LongDirFix = TempString Exit Function End If LblLen = LblLen - 6 For i = Len(TempString) - LblLen To Len(TempString) If Mid$(TempString, i, 1) = "\" Then Exit For Next 'On one line: LongDirFix = Left$(TempString, 3) & "..." & Right$(TempString, Len(TempString) - (i - 1)) End Function ' Example: Dim DirName As String DirName = "C:\DICKENS\DIVISION\RESTRNT\PAYROLL\JONES_D" Label1.Caption = LongDirFix(DirName, 32) ' The second paramater is the max length of the returned string.
Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows