Link to home
Start Free TrialLog in
Avatar of hnEE
hnEEFlag for Afghanistan

asked on

Concatenate response.write statements

Hi Experts

We have the following code that outputs the correct information in the browser. What is the best way (with example please) to turn this into one complete variable.

Thanks for your time.
<%
While (NOT WA_eCart_EOF(GSDeCart))
	Response.Write(WA_eCart_DisplayInfo(GSDeCart, "Quantity"))
	Response.Write("x&nbsp;")
	Response.Write(WA_eCart_DisplayInfo(GSDeCart, "Description"))
Set GSDeCart = WA_eCart_MoveNext(GSDeCart)
	If NOT WA_eCart_EOF(GSDeCart) Then 
		Response.Write(",&nbsp;") 
	Else
		Response.Write(".")
	End If
Wend
%>

Open in new window

Avatar of szaranger
szaranger

is this what you are trying to achive:

While (NOT WA_eCart_EOF(GSDeCart))
        Response.Write(WA_eCart_DisplayInfo(GSDeCart, "Quantity") & "x " &   WA_eCart_DisplayInfo(GSDeCart, "Description")
Avatar of Guy Hengel [angelIII / a3]
small correction:
Dim next_character 
next_character = ""
While (NOT WA_eCart_EOF(GSDeCart))
   Response.Write(WA_eCart_DisplayInfo(GSDeCart, "Quantity") & "x " &   WA_eCart_DisplayInfo(GSDeCart, "Description" & next_character)
   next_character = ","
Wend
Response.Write(".")

Open in new window

Avatar of hnEE

ASKER

Hi Experts

I may not have explained myself correctly.

The code in our example works correctly. It shows in the browsers exactly what it should. However, say it renders out "1x Dog, 2x Cat."

We would like to turn that output into a variable:

myVar = "1x Dog, 2x Cat."

I hope this make is clearer.

Thanks for your time
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hnEE

ASKER

Hi angelIII

Your response was very close - but showed me the basic idea. This got us what we needed in the end. Does that look okay to you?

Thanks for your help
Dim result
Dim next_character 
next_character = ", "
While (NOT WA_eCart_EOF(GSDeCart))
   result = result & WA_eCart_DisplayInfo(GSDeCart, "Quantity") & "x " &   WA_eCart_DisplayInfo(GSDeCart, "Description") & next_character
   If WA_eCart_EOF(GSDeCart) Then 
		next_character = ", " 
	Else
		next_character = "."
	End If
Set GSDeCart = WA_eCart_MoveNext(GSDeCart)
Wend
Set GSDeCart = WA_eCart_MoveFirst(GSDeCart)
Response.Write(result)

Open in new window

not wrong.
but not optimal :)

check out the stringbuilder class to reduce the string concatenation "overhead":
http://msdn.microsoft.com/en-us/library/ms972323.aspx