Truncate Names - With the advent of long file and path names it is sometimes necessary to truncate the names so they will 'fit' in a specified message or label caption. I needed to do this recently so I posted a request in a news group and received a reply [from John Hamaker, firstname.lastname@example.org] which demonstrates using the DrawText API to perform the function. So I created a demo program to show not only how to use the API to truncate a path/file combination but any text string. It becomes the tip-of-the-month.
The Demonstration Program
This example uses flag DT_PATH_ELLIPSIS to truncate the long file/path name inserting ellipsis before the file name.
This example uses flag DT_WORD_ELLIPSIS to truncate the right portion of the string. You could use this function to truncate a string that is too long.
Calling function TruncateLongPathAndFile
Format sResult = TruncateLongPathAndFile(sString, lLength, bPath) Sample sResult = TruncateLongPathAndFile("c:\My Long Folder1\My Long Folder2\My Long File.txt", 45, True" sString The string to be truncated. lLength The truncation length. A long integer. bPath Set to True to use DT_PATH_ELLIPSIS or False to use DT_WORD_ELLIPSIS.
Help Uses modConnectToWebSite
The application uses modConnectToWebSite.bas to display this page. For details on the use of that module click here.
Download VB Code
Click here to download the VB 6 Source Code [14k].
Download As Word 97 Document
Click here to download this page as a zipped Word 97 Document [25k].
Previous Tip Tip Index Next Tip