webForumDet fria alternativet

problem

5 svar · 171 visningar · startad av i-or

i-orMedlem sedan nov. 2001308 inlägg
#1

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?

LarsGMedlem sedan dec. 200012 465 inlägg
#2

format finns inte i vbscript.

------------------
essentitia preter non sans multiplicandum

i-orMedlem sedan nov. 2001308 inlägg
#3

Oj, var lite otydlig där. Format är en funktion som jag själv lagt in.

LarsGMedlem sedan dec. 200012 465 inlägg
#4

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

i-orMedlem sedan nov. 2001308 inlägg
#5

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
%>
LarsGMedlem sedan dec. 200012 465 inlägg
#6

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

Genererad på 383 ms · cache AV · v20260730165559-full.f96bc7eb