VB icon

WraptIt

Email
Submitted on: 1/5/2015 7:40:00 AM
By: Chip Taylor (from psc cd)  
Level: Intermediate
User Rating: By 3 Users
Compatibility: ASP (Active Server Pages), VbScript (browser/client side)
Views: 950
 
     This is a function to provide word wrap capability in your ASP pages.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: WraptIt
' Description:This is a function to provide word wrap capability in your ASP pages.
' By: Chip Taylor (from psc cd)
'
' Inputs:Function takes a string, a column number, and a forced break boolean. If the forced break boolean is FALSE (default) then the string will wrap at the nearest end-of-word to the column number. If TRUE then the string will wrap at the column number regardless of end-of-word
'
' Returns:A string with embedded <br> tags to provide word wraps.
'**************************************

Function WrapIt(varString,varNumChar,boolBreak)
' Word Wraps a string varString at end of word nearest column position varNumChar
' If boolBreak is true then the wrap will take place at position varNumChar regardless
varString=Trim(varString)
 varSetBR = "<br>"
result=""
varString=Replace(varString,chr(13)+chr(10),chr(10))
while varString<>""
if len(varString)<=varNumChar then
line=varString
varString=""
else
varTemp1=left(varString,varNumChar)
iCount=InStrRev(varTemp1," ")
varInPlace=InStr(varTemp1,"chr(10)")
if (iCount=0) and not boolBreak then iCount=InStr(varString," ")
if (varInPlace=0) and not boolBreak then varInPlace=InStr(varString,chr(10))
if (varInPlace<iCount) and (varInPlace>0) then
finish=j-1
start=varInPlace+1
elseif iCount=0 then
finish=varNumChar
start=varNumChar+1
else
finish=iCount
start=iCount+1
end if
line=left(varString,finish)
varString=ltrim(mid(varString,start))
end if
'if result="" then result=line else
result=result&chr(10)&line
wend
	 if left(result,1) = chr(10) then
		result = right(result,(len(result)-1))
		 end if
WrapIt=Replace(result,chr(10),varSetBR)
		
end function


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.