Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Response.Write Syntax

Status
Not open for further replies.

JonathanG6SWJ

Programmer
Joined
Jan 18, 2005
Messages
39
Location
GB
Having jumped in the deep end with ASP I'm stuck with a syntax problem (no doubt down to pure ignorance!!)

My Code

Response.Write ("<td width=400 align=center valign=middle style='background-color: rgb(170,189,255)' height=1><font face=Gill Sans><p align=left><%=QArray(Offset)%></p></font></td>")

The error stems from the variable <%QArray(Offset)%> bit of the code but I'm lost

Can anyone help
Thanks in anticipation>
Jonathan
 
shouldnt that be

<%=QArray("Offset")%>

missing quotes...

-L
 
L Thanks for hint

Tried this
<%=QArray("Offset")%>
and got error >VBScript compilation error 1033 :
Unterminated string constant

Changed Offset to an integer 2
<%=QArray("2")%> or <%=QArray(2)%>

But still get "Unterminated string constant" error message

I have used '' successfully with Response.Write ("<td width='1%'>"). But I've tried ' in just about every position without success.

I guess the code is trying to %> from being misinterrupted


Jonathan

 
Try this:

Response.Write ("<td width=400 align=center valign=middle style='background-color: rgb(170,189,255)' height=1><font face=Gill Sans><p align=left>QArray(Offset)</p></font></td>")

-L
 
Lothario - many thanks

Tried
...align=left>QArray(Offset)</p></font></td>")
and get text QArray(Offset) appear rather than the value from the array.

Tried
a....lign=left>QArray("Offset")</p></font></td>")
get error
VBScript compilation error 1002 :Syntax error

Oh boy sometimes I just hate syntax problems

Jonathan



 
How about this:

Response.Write "<td width=400 align=center valign=middle style='background-color: rgb(170,189,255)' height=1><font face=Gill Sans><p align=left>&QArray("Offset)&</p></font></td>"

removed braces...
added &

-L

 
Try:

Code:
Response.Write ("<td width=400 align=center valign=middle  style='background-color: rgb(170,189,255)' height=1><font face=Gill Sans><p align=left>[b][blue]" & QArray(Offset) & "[/blue][/b]</p></font></td>")

This is assuming that QArray is an array, and Offset is an integer variable

Earnie Eng
 
missed one quote...it should be &QArray("Offset")&

-L
 
How about using double quotes where they're supposed to be:
Code:
Response.Write "<td width=[red]""[/red]400[red]""[/red] align=[red]""[/red]center[red]""[/red] valign=[red]""[/red]middle[red]""[/red] style=[red]""[/red]background-color:rgb(170,189,255)[red]""[/red] height=[red]""[/red]1[red]""[/red]><font face=[red]""[/red]Gill Sans[red]""[/red]><p align=[red]""[/red]left[red]""[/red]>" & QArray(Offset) & "</p></font></td>"

Lee
 
Response.Write simply outputs to the web browser a string. What you seem to be doing here is ouputting three strings:

html code
"<td width=400 align=center valign=middle style='background-color: rgb(170,189,255)' height=1><font face=Gill Sans><p align=left>"


embed the value of QArray at the given offset
QArray(Offset)


html code
"</p></font></td>"


Take care that you surround all your literal strings (the first and third example) with doublequotes and properly concatenate them with the [blue]&[/blue] symbol.



Earnie Eng
 
Earnie,

I am positive that this would work with the quotes around the QArray(Offset)

Code:
Response.Write "<td width=400 align=center valign=middle  style='background-color: rgb(170,189,255)' height=1><font face=Gill Sans><p align=left>& QArray("Offset")& </p></font></td>"

-L
 
L, that would depend on what QArray is... Thus far I've been assuming it is a variable of type array... if it was a recordset, then, yes, the quotes around "Offset" are necessary.

The problem with the Response.Write would cause an error for the following reason:

Code:
Response.Write [green]"<td width=400 align=center valign=middle  style='background-color: rgb(170,189,255)' height=1><font face=Gill Sans><p align=left>& QArray("[/green]Offset[blue]")& </p></font></td>"[/blue]

The string you are passing to the Response.Write command above consists of three parts:
- a string (in green)
- a variable, offset (in black)
- a string (in blue)

The server will throw an error becuase Response.Write expects only one string as its input, and is confused since the three elements aren't tied together with a [blue]&[/blue] symbol.

if QArray is an array, then no quotes are necessary if Offset is a number

if QArray is a recordset, and offset is the name of a field in the recordset, then the quotes around "offset" are necessary

Earnie Eng
 
well the most efficient way would simply be

Code:
<td width="400" align="center" valign="middle" style="background-color: rgb(170,189,255);" height="1">
<font face="Gill Sans">
<p align=left>
<%=QArray(Offset)%>
</p>
</font>
</td>



Chris.

Indifference will be the downfall of mankind, but who cares?
A website that proves the cobblers kids adage.
Nightclub counting systems

So long, and thanks for all the fish.
 
Thanks to all of you for your help.

QArray was an array and Offset was an integer.

Mission accomplished for now -scary - it WORKS!!!!!!!!!

Regards
Jonathan.

No doubt see you guys further down the electricity bill!
 
Right on! I'm glad you got it working!

I agree with Chris... rather than Response.Writing all your HTML, a more efficient way (and more maintainable if you use dreamweaver or some html editor) to do things is leave your HTML code outside the ASP Block, and use the

<%= %> block to insert your ASP variables into html...

I just took your code example and ran with it instead of cleaning things up...

Earnie Eng
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top