devxlogo

Trimmed to Fit

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
See also  How to Block Websites During Certain Hours on a Mac Computer
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist