Normal Topic Re: Padding with spaces made easy (Read 4223 times)
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1350
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Padding with spaces made easy
Apr 14th, 2005 at 12:00am
Print Post Print Post  
I've made a small adjustment to the @Pad code. It now will also TRIM the length of a value if it is longer than the specified length.

If the Name element's data is longer than 32 characters, and you use @Pad(Name, 32, 1), @Pad will return the first 30 characters followed by ".." (two periods) to indicate that it has been trimmed.

Code
Select All
//########## Begin @Pad() Function ##########
Function @Pad(vStr as string, N as int, J as int) as string
var vA as string
if @Len(vStr) <= N
	{
	if J = 1
		vA = vStr + @Text(N - @Len(vStr), " ")

	if J = 2
		vA = @Text(N - @Len(vStr), " ") + vStr
	}
else
	vA = @Left(vStr, N - 2) + ".."

Return vA
End Function
//########## End @Pad() Function ##########
 

  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged