Trimmed to Fit

This piece of code trims long file names to fit into forms captions, text boxes, and other limited spaces. The code allows you to specify the number of characters a file name must be before it performs the trimming. For example, if the label can hold 50 characters, then you would type LongDirFix(nFile,50). It’s as simple as that. Here’s the code:

 Function LongDirFix(Incomming As _	String, Max As Integer) As StringDim i As Integer, LblLen As Integer, StringLen As IntegerDim TempString As StringTempString = IncommingLblLen = MaxIf Len(TempString) <= LblLen Then	LongDirFix = TempString	Exit FunctionEnd IfLblLen = LblLen - 6For i = Len(TempString) - LblLen To Len(TempString)	If Mid$(TempString, i, 1) = "" Then Exit ForNextLongDirFix = Left$(TempString, 3) + _	"..." + Right$(TempString, Len(TempString) - (i - 1))End Function
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: