devxlogo

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

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Five Early Architecture Decisions That Quietly Get Expensive

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.