Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Visual Basic Programming Code Examples

Visual Basic > Files Directories Drives Code Examples

How to shorten a long directory name.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
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.