470,573 Members | 1,826 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,573 developers. It's quick & easy.

Converting an Object to String

polymorphic
I need to convert a data object to string.

Currently, my script follows as:
strTitle = CStr(<%=mobjSystem.DescrShort %>)

When this is compiled it appears as:

strTitle = CStr(SOPs - Title1)

The error I get is that a '0' is expected. I've tried different variants with no success. The reason I want to convert it to string is to later pass it as part of a URL: Server.URLEncode(strTitle)

Any advice?

Thanks,
cj
Jan 8 '08 #1
4 13408
JamieHowarth0
533 Expert 512MB
Hi cj,

This code means that ASP will parse the value in mobjSystem.DescrShort as the unquoted parameter of CStr.
Take out the <%= and %> and ASP will then parse the value as a quoted string like so:
Expand|Select|Wrap|Line Numbers
  1. strTitle =  CStr(mobjSystem.DescrShort )
  2.  
which, when compiled, turns into:
Expand|Select|Wrap|Line Numbers
  1. strTitle = CStr("SOPs - Title1")
  2.  
The error "0" is expected is because you can't substract strings - your string contains the "-" and when this is turned into a parameter, ASP treats it as "SOPs" is a variable, "Title1" is a variable and it should subtract Title1 from SOPs.
Failing that, use this code instead:
Expand|Select|Wrap|Line Numbers
  1. strTitle = CStr("<%=mobjSystem.DescrShort%>")
  2.  
That way, you've put the quotes in for ASP to recognise the value as a string.

Hope it helps.

medicineworker
Jan 8 '08 #2
Hi cj,

This code means that ASP will parse the value in mobjSystem.DescrShort as the unquoted parameter of CStr.
Take out the <%= and %> and ASP will then parse the value as a quoted string like so:
Expand|Select|Wrap|Line Numbers
  1. strTitle =  CStr(mobjSystem.DescrShort )
  2.  
which, when compiled, turns into:
Expand|Select|Wrap|Line Numbers
  1. strTitle = CStr("SOPs - Title1")
  2.  
The error "0" is expected is because you can't substract strings - your string contains the "-" and when this is turned into a parameter, ASP treats it as "SOPs" is a variable, "Title1" is a variable and it should subtract Title1 from SOPs.
Failing that, use this code instead:
Expand|Select|Wrap|Line Numbers
  1. strTitle = CStr("<%=mobjSystem.DescrShort%>")
  2.  
That way, you've put the quotes in for ASP to recognise the value as a string.

Hope it helps.

medicineworker

That is a good point. It will not read strTitle = CStr("<%=mobjSystem.DescrShort%>"). The error reads "mobjSystem" required.
Jan 8 '08 #3
That is a good point. It will not read strTitle = CStr("<%=mobjSystem.DescrShort%>"). The error reads "mobjSystem" required.
OK, Here I think I have the answer:

What I think was happening is that when I was converting to string:
strTitle = CStr(<%=mobjSystem.DescrShort %>)

The result would be:

strTitle = SOPs - Research Pilot Brewery

This would result in an error: "Expected end of statement" - Error 0 .

When I used strTitle = CStr("<%=mobjSystem.DescrShort %>") with the Server.URLEncode then the mobjSystem object would not be recognized but literally. When I removed the Server.URLEncode(strTitle), and changed it to just strTitle THEN it worked.

One question: Is "Expected end of statement" - Error 0 a mathematical error? How did you know the "-" was being used as a substract?

Thanks much,
cj
Jan 8 '08 #4
Nicodemas
164 Expert 100+
No.

Just do this:

Expand|Select|Wrap|Line Numbers
  1. strTitle = CStr(mobjSystem.DescrShort)
  2.  
It'll work, as the others have pointed out. strTitle will then be whatever the value of mobjSystem.DescrShort is.

Your problem was that you had ASP delimiters (<%... %>) in your ASP code.
Jan 9 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Ajay | last post: by
1 post views Thread by bryja_klaudiusz[at]poczta[dot]fm | last post: by
6 posts views Thread by Martin Carolan | last post: by
3 posts views Thread by Wallace | last post: by
4 posts views Thread by gg9h0st | last post: by
1 post views Thread by Kevin S Gallagher | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.