Avatar billede guzzie Nybegynder
12. februar 2001 - 12:11 Der 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
Avatar billede jimmidreng Nybegynder
12. februar 2001 - 12:14 #1
This is how it\'s done:

If Len(StrText) > 200 Then
StrText = Left(StrText,200) & \"...\"
End If
Response.write(StrText)

/Jimmi
Avatar billede winkill Nybegynder
12. februar 2001 - 12:16 #2
Here\'s a short example...
/Troels :o)

ShortText = ChopText(\"This is way too long!\", 6)
\' ShortText should now be \"This i...\"

Function ChopText(Text, MaxLength)
  If Len(Text) > MaxLength Then
    ChopText = Left(Text, MaxLength) & \"...\"
  Else
    ChopText = Text
  End If
End Function
Avatar billede eagleeye Praktikant
12. februar 2001 - 12:27 #3
posstart=instr (Max_length, YouString, \" \")
if (posstart <> 0) then
  outtext = Left(YouString,posstart) & \"...\"
else
  outtext = YouString
end if

eksemple:
If String is \"What to do with the drunken DJ\"
Max__length = 9.
The output will be \"What to do...\"
Avatar billede tdaugaard Nybegynder
12. februar 2001 - 12:28 #4
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
Avatar billede guzzie Nybegynder
12. februar 2001 - 12:29 #5
Hi Again

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
Avatar billede tdaugaard Nybegynder
12. februar 2001 - 12:29 #6
okay .. jeg havde ikke set eagleeye\'s svar .. men nu har guzzie da noget at vælge i mellem :-)
Avatar billede guzzie Nybegynder
12. februar 2001 - 12:30 #7
hello tdaugaard :)
Avatar billede tdaugaard Nybegynder
12. februar 2001 - 12:30 #8
<%
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.
Avatar billede guzzie Nybegynder
12. februar 2001 - 12:35 #9
thanks for your help guys
tdaugaard´s answer was perfect
Avatar billede tdaugaard Nybegynder
12. februar 2001 - 12:39 #10
:-)
Avatar billede guzzie Nybegynder
12. februar 2001 - 14:22 #11
hey there tdaugaard
I have added a few more inserts into my db
now everything is shown but not the colume where only a few words should be shown

heres the script

<html>

<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">
<meta name=\"GENERATOR\" content=\"Microsoft FrontPage 4.0\">
<meta name=\"ProgId\" content=\"FrontPage.Editor.Document\">
<title>Vis adresser</title>

</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>


</body>
Any Idea
Guzzie :=)
Avatar billede tdaugaard Nybegynder
12. februar 2001 - 14:24 #12
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
%>
Avatar billede guzzie Nybegynder
12. februar 2001 - 14:33 #13
hmmm still nothing :(

<%
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>

<head>
</head>
<body>
<link rel=\"stylesheet\" style=\"text/css\" href=\"styles_old.css\">
<table valign=\"top\" align=\"left\" width=\"550\" cellpadding=\"5\" cellspacing=\"5\">
<%
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\" ><img width=\"9\" height=\"9\" border=\"0\" src=\"breast.jpg\"></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>
</body> 
Avatar billede guzzie Nybegynder
12. februar 2001 - 14:35 #14
here the link
there should be a description next to the diffrent words

http://www.guzzie.dk/mediascope/main.asp
Avatar billede been Nybegynder
12. februar 2001 - 14:49 #15
Med på en lytter !
Avatar billede eagleeye Praktikant
12. februar 2001 - 14:51 #16
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
&>
Avatar billede tdaugaard Nybegynder
12. februar 2001 - 16:30 #17
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
%>
Avatar billede guzzie Nybegynder
12. februar 2001 - 16:46 #18
hmmm me have tried them all and none of them work ?
sniff
Guzzie
Avatar billede eagleeye Praktikant
12. februar 2001 - 19:06 #19
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
%>
Avatar billede guzzie Nybegynder
12. februar 2001 - 20:38 #20
thank V much
thats very nice
it works a treat :)
Guzzie
Avatar billede Ny bruger Nybegynder

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.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester