Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Truncation

Status
Not open for further replies.

manicleek

Technical User
Joined
Jun 16, 2004
Messages
143
Location
GB
Can anyone help me with some code to truncate a field of text.

the field is called "Desc"

Thanks
 
Try this:

<%=(Left(rs("Desc"),25))%>

the above code truncates your desc field and shows the first 25 characters...you change this to the number of character you want to show...

-VJ
 
I put that in but for some reason all it prints is 25 question marks

Any idea what thats about?
 
The code now looks like:

Code:
<% If OnMenuReview("Approved") = "True" then 
											IsReview = "True" %><tr>
                                              <td> <strong>Review <%=ReviewCount%>: <font color="#990033">											
											  <%=OnMenuReview("ReviewTitle")%></font></strong>
											  <BR> <%= Left.(OnMenuReview("ReviewDesc"),25)%>
											  <BR><font color="#000000">Review Created by <%=OnMenuReview("CreatedBy")%></font> </td>
                                            </tr>
											<% ReviewCount = ReviewCount + 1 %>
											<% End If %>

If it helps, before the truncation the field was displayed using:

Code:
<%Response.BinaryWrite(OnMenuReview("ReviewDesc"))%>

ReviewDesc is the name of the field, its a blob field in a mysql db, got it wrong before
 
U had

<%= Left.(OnMenuReview("ReviewDesc"),25)%>

a dot after the Left

remove it

it should be

<%= Left(OnMenuReview("ReviewDesc"),25)%>

-VJ
 
sorry, the . isn't there, that was left over from when I was fiddling with it.

The error is still there though
 
Try that additional parenthesis....

Code:
<% 
If OnMenuReview("Approved") = "True" 
then 
IsReview = "True" 
%>
<tr>
<td> <strong>Review <%=ReviewCount%>: <font color="#990033">                                           <%=OnMenuReview("ReviewTitle")%>
</font></strong>
<BR> 
<%= [b](Left(OnMenuReview("ReviewDesc"),25))[/b]%>
<BR><font color="#000000">Review Created by 
<%=OnMenuReview("CreatedBy")%>
</font> </td>
</tr>
<% ReviewCount = ReviewCount + 1 %>
<% End If %>

and do you get the whole ReviewDesc when you dont use the Left function....What actually your ReviewDesc field consists of?

-VJ
 
Still have the question marks

The field is a blob field and contains reviews of a company

I don't know if it matters but it contains html tags for formatting
 
Ok give this a try:

<%= Server.HTMLEncode(Left(OnMenuReview("ReviewDesc"),25))%>


-VJ
 
No, now I get boxes instead of question marks :)
 
pass the value of the blob field to a variable then do the work on the variable and response write out the after effects

like this :

<%
blah = OnMenuReview("ReviewDesc")
%>
<%= Left(blah,25)%>


memo's and blobs are handled and passed differently than regular fields, regular fields are passed directly across and stored in server memory, blobs are not sent due the randomness of size, something about sending 1000 records with a meg data in each blob is part of the reason ...
so you need to actively assign the value out to something else that hold it, if you weren't already going to truncate it i would suggest you :

dim blah(0)
blah(0) = OnMenuReview("ReviewDesc")


this is because array items can store a LOT more data in them than a string variable which i think the cutoff is somewhere around 1kb (1024 chars) and would truncate there instead



[thumbsup2]DreX
aKa - Robert
 
Ok, Now I'm getting


Microsoft VBScript runtime error '800a000d'

Type mismatch

/qfol/Qfol-Latest/moreResults.asp, line 207


with line 207 being the <%= Left(descriptiontext,25)%>
code

I have put in the variable as

Code:
<%
dim descriptiontext(0)
descriptiontext(0) = OnMenuReview("ReviewDesc")
%>
 
Use the replace() function to pull out the garbage data.
 
Sorry, I'm fairly new to this

How would I use that function in this case?
 
if you want this

<%= Left(descriptiontext,25)%> to work

change your code to:

<%
dim descriptiontext
descriptiontext= OnMenuReview("ReviewDesc")
%>


-VJ

 
manicleek (TechnicalUser) Jun 30, 2004
Ok, Now I'm getting
Microsoft VBScript runtime error '800a000d'
Type mismatch
/qfol/Qfol-Latest/moreResults.asp, line 207
with line 207 being the <%= Left(descriptiontext,25)%>
code
I have put in the variable as
Code:
<%
dim descriptiontext(0)
descriptiontext(0) = OnMenuReview("ReviewDesc")
%>

you got that error because you hadn't changed all the occurences out for the variable that you had changed :
with line 207 being the <%= Left(descriptiontext,25)%>
line 207 needs to be <%= Left(descriptiontext(0),25)%>

[thumbsup2]DreX
aKa - Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top