Varför funkar inte det här:
Response.Write left(format(Message),200)
när
Response.Write left(Message,200)
fungerar. Hur ska jag göra för att lägga till formatfunktionen?
5 svar · 171 visningar · startad av i-or
Varför funkar inte det här:
Response.Write left(format(Message),200)
när
Response.Write left(Message,200)
fungerar. Hur ska jag göra för att lägga till formatfunktionen?
Oj, var lite otydlig där. Format är en funktion som jag själv lagt in.
Jag förstår. Anropet ser rätt ut.
Får du något fel?
Hur ser koden för din format ut?
------------------
essentitia preter non sans multiplicandum
Jag får inget felmeddelande. Hela "Message" skrivs ut istället för bara de 200 första bokstäverna.
Om jag skriver så här:
Response.Write format(Message)
fungerar det också.
Koden för format ser ut så här:
<%
Dim strText, iLength, iPos1, iPos2, iWordLength
Function format(strText)
iPos1 = 1
iPos2 = 1
iWordLength = 0
Do Until iPos2 = Len(strText)
iPos2 = iPos2 + 1
iWordLength = iWordLength + 1
If Mid(strText,iPos2,1) = " " Then
iWordLength = 0
End if
If iWordLength > 35 Then
strText = Mid(strText,1,iPos1-1)_
& Mid(strText,iPos1,iPos2-iPos1)_
& " " & Mid(strText,iPos2,Len(strText)-iPos2+1)
iPos1 = iPos2
iPos2 = iPos2 + 1
iWordLength = 0
End If
Loop
Response.Write strText
End Function
%>
En funktion returnerar ett värde, så du skall inte ha en response.write i den utan du tilldelar funktionsnamnet det värde du vill returnera.
<%
Dim strText, iLength, iPos1, iPos2, iWordLength
Function format(strText)
iPos1 = 1
iPos2 = 1
iWordLength = 0
Do Until iPos2 = Len(strText)
iPos2 = iPos2 + 1
iWordLength = iWordLength + 1
If Mid(strText,iPos2,1) = " " Then
iWordLength = 0
End if
If iWordLength > 35 Then
strText = Mid(strText,1,iPos1-1)_
& Mid(strText,iPos1,iPos2-iPos1)_
& " " & Mid(strText,iPos2,Len(strText)-iPos2+1)
iPos1 = iPos2
iPos2 = iPos2 + 1
iWordLength = 0
End If
Loop
[b]
format = strText
[/b]
End Function
%>
------------------
essentitia preter non sans multiplicandum