473,499 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting an Object to String

polymorphic
28 New Member
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 14167
JamieHowarth0
533 Recognized Expert Contributor
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
polymorphic
28 New Member
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
polymorphic
28 New Member
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 Recognized Expert New Member
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

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

Similar topics

1
2400
by: Ajay | last post by:
hi! how do i go about converting a Python object or tuple to a string. i am currently doing import cPickle as pickle str = pickle.dumps(obj) is thate efficient? is that the best way to do...
1
4107
by: bryja_klaudiusz[at]poczta[dot]fm | last post by:
Hi, How to convert object to string? I try procedure like this (when I have byte array I convert it to string): public byte ObjectToByteArray(Object obj) { MemoryStream fs = new...
6
1343
by: Martin Carolan | last post by:
Hi there, I have an interface (called AuthenticationInterface) shown below: Public Interface AuthenticationInterface Function IsLoggedIn() As Boolean Function Authenticate(ByVal User As...
3
28514
by: Wallace | last post by:
Hai, Can anyone tell how to convert an object into string? Please help me.... urgent.. Thanx in advance...
3
3125
by: MMiGG | last post by:
Hi Our project need parse JAVA serialized object string in C, has any library? Thanx
4
3170
by: gg9h0st | last post by:
i'm a newbie studying php. i was into array part on tutorial and it says i'll get an array having keys that from member variable's name by converting an object to array. i guessed "i can...
1
1903
by: Kevin S Gallagher | last post by:
I found this code (pretty sure it was from a MVP) for converting a string variable to a form object which works fine within a form. Take the code and place it into a code module and it fails on the...
0
1356
by: rrp83 | last post by:
Hi All Can anyone fwd me the code for converting a string to bytes similar to the GetBytes function in C# and viceversa?? Regards, RRP83
2
3988
by: CoreyWhite | last post by:
Problem: You have numbers in string format, but you need to convert them to a numeric type, such as an int or float. Solution: You can do this with the standard library functions. The...
2
3353
by: bylabylamo | last post by:
i have a problem converting a json string that i get from a servlet into a json object using eval function of java script. any one please help me..........
0
7131
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6894
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7388
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4600
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3099
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.