• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

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

0
hnEE
Asked:
hnEE
  • 3
  • 2
1 Solution
 
szarangerCommented:
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")
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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

0
 
hnEEAuthor Commented:
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
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
yes, that is possible also:
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)
   next_character = ","
Wend
Response.Write(result & ".")

Open in new window

0
 
hnEEAuthor Commented:
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

0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now