12. februar 2001 - 12:11Der er
19 kommentarer og 1 løsning
max words then .......
Hey there
I am trying to use the same kind of script the eksperten does on there site, where they have a link and if its to long then it changes to ...... at the end of the link like this example I am looking for..... any ideas Guzzie
Denne her er bedre .. den cutter ikke midt i et ord:
Function CutString (strString, intCut) If Not Len(strString) > intCut Then Exit Function If Len(strString) < intCut Then CutString = strString: Exit Function
If Mid(strString, intCut + 1, 1) = Chr(32) Then CutString = Left(strString, intCut): Exit Function
intIndex = InStrRev(strString, Chr(32))
Select Case intIndex Case 0: CutString = Left(strString, intCut) & \"...\" Case 1: CutString = Left(strString, intIndex) & \"...\" End Select End Function
I am using a simple db and have various columes shown I see that the example jimmidreng came with used a Response.write is there anyway that I can avoid using a Response.write heres an example of my script <tr> <td><b><%=name%></b></td> </tr> <tr> <td><%=info%></td> </tr> how would I get <%=info%> only to show a couple of words thanks again Guzzie
<% Function CutString (strString, intCut) If Not Len(strString) > intCut Then Exit Function If Len(strString) < intCut Then CutString = strString: Exit Function
If Mid(strString, intCut + 1, 1) = Chr(32) Then CutString = Left(strString, intCut): Exit Function
intIndex = InStrRev(strString, Chr(32))
Select Case intIndex Case 0: CutString = Left(strString, intCut) & \"...\" Case 1: CutString = Left(strString, intIndex) & \"...\" End Select End Function %> <tr> <td><b><%=name%></b></td> </tr> <tr> <td><%=CutString(info, 20)%></td> </tr>
Will show a max of 20 chars. and won\'t cut in a word.
</head> <body> <link rel=\"stylesheet\" style=\"text/css\" href=\"styles_old.css\"> <table valign=\"top\" align=\"left\" width=\"550\" cellpadding=\"5\" cellspacing=\"5\"> <% Function CutString (strString, intCut) If Not Len(strString) > intCut Then Exit Function If Len(strString) < intCut Then CutString = strString: Exit Function
If Mid(strString, intCut + 1, 1) = Chr(32) Then CutString = Left(strString, intCut): Exit Function
intIndex = InStrRev(strString, Chr(32))
Select Case intIndex Case 0: CutString = Left(strString, intCut) & \"...\" Case 1: CutString = Left(strString, intIndex) & \"...\" End Select End Function %> <% Set Conn = Server.CreateObject(\"ADODB.Connection\") Conn.Open \"DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=\" & server.MapPath(\"media.mdb\")
SQLstmt = \"SELECT * FROM listall ORDER BY name;\"
Set rs = conn.Execute(SQLstmt)
%> <% DO WHILE NOT rs.EOF id = rs(\"Id\") name = rs(\"name\") info = rs(\"info\") %> <tr> <td width=\"12\" height=\"12\" valign=\"middle\" align=\"left\" ><a href=\"vis_data_alt.asp?Id=<%=Id%>\"><img width=\"9\" height=\"9\" border=\"0\" src=\"breast.jpg\"></a></td><td valign=\"top\"><b><%=name%></b></td> <td align=\"left\"><%=CutString(info, 32)%></td> </tr> <% rs.MoveNext LOOP RS.Close Response.Write \"<br>\"
conn.Close Set conn = nothing Set SQLstmt = nothing %> </table>
You forgot to insert my function .. insert the following at the top of your document:
<% Function CutString (strString, intCut) If Not Len(strString) > intCut Then Exit Function If Len(strString) < intCut Then CutString = strString: Exit Function
If Mid(strString, intCut + 1, 1) = Chr(32) Then CutString = Left(strString, intCut): Exit Function
intIndex = InStrRev(strString, Chr(32))
Select Case intIndex Case 0: CutString = Left(strString, intCut) & \"...\" Case 1: CutString = Left(strString, intIndex) & \"...\" End Select End Function %>
<% Function CutString (strString, intCut) If Not Len(strString) > intCut Then Exit Function If Len(strString) < intCut Then CutString = strString: Exit Function
If Mid(strString, intCut + 1, 1) = Chr(32) Then CutString = Left(strString, intCut): Exit Function
intIndex = InStrRev(strString, Chr(32))
Select Case intIndex Case 0: CutString = Left(strString, intCut) & \"...\" Case 1: CutString = Left(strString, intIndex) & \"...\" End Select End Function %> <html>
Try to delete the first line from the function, this one: If Not Len(strString) > intCut Then Exit Function
If the string is shorter the MAX the function returen an empty string, which is the same as no text.
Or try my function: <% Function CutString (strString, intCut) if len(strString) > intCut then posstart=instr (intCut, YouString, \" \") if (posstart <> 0) then CutString = Left(YouString, posstart) & \"...\" Exit Function end if end if CutString = YouString End function &>
eagleeye:> it\'s strange .. the functions works perfectly on a site of my own .. but i can see that i miss a \"CutString = strString:\" in the first line. .
<% Function CutString (strString, intCut) If Not Len(strString) > intCut Then CutString = strString: Exit Function If Len(strString) < intCut Then CutString = strString: Exit Function
If Mid(strString, intCut + 1, 1) = Chr(32) Then CutString = Left(strString, intCut): Exit Function
intIndex = InStrRev(strString, Chr(32))
Select Case intIndex Case 0: CutString = Left(strString, intCut) & \"...\" Case 1: CutString = Left(strString, intIndex) & \"...\" End Select End Function %>
This is my function, one more time. I have found one error in my function. I have just testet it and it is working on my site, pleace try again.
<% Function CutString (YouString, intCut) if len(YouString) > intCut then posstart=instr (intCut, YouString, \" \") if (posstart <> 0) then CutString = Left(YouString, posstart) & \"...\" Exit Function end if end if CutString = YouString End function %>
thank V much thats very nice it works a treat :) Guzzie
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.