By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,193 Members | 1,648 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,193 IT Pros & Developers. It's quick & easy.

Prevent 'Chr(13) + Chr(10)' from Being Executed in String

P: n/a
I have the following code in my web page.

Dim tmpReplace As String
'Giving tmpReplace the value from the textbox on the
webform.
tmpReplace = txtComments.Text.Trim
'Prevents report from crashing when a single quote is in
string
tmpReplace = tmpReplace.Replace("'", "''")
'Replace carriage return with the appropriate CharCodes.
tmpReplace = tmpReplace.Replace("\n", "chr(13) + chr(10)")

I want to display the following text on my report: chr(13) + chr(10)
Instead what is happening is that .Net is executing the chr function
and creating a carriage return. What do I need to do to prevent the
chr function from being launched?
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
| tmpReplace = tmpReplace.Replace("'", "''")
| 'Replace carriage return with the appropriate CharCodes.
| tmpReplace = tmpReplace.Replace("\n", "chr(13) + chr(10)")
|
| I want to display the following text on my report: chr(13) + chr(10)
| Instead what is happening is that .Net is executing the chr function
| and creating a carriage return. What do I need to do to prevent the
| chr function from being launched?

It's not executing the Chr function. "\n" is not special character i VB.NET.
If you want to replace CRLF, use:

tmpReplace = tmpReplace.Replace(vbCrLf, "chr(13) + chr(10)")

But if you're doing this only for storing in database, use parameters
instead and everything - quotes, line ends etc. - would be escaped
automatically.

--
Michal A. Valasek, Altair Communications, http://www.altaircom.net
Please do not reply to this e-mail, for contact see http://www.rider.cz
Nov 17 '05 #2

P: n/a
I removed the "\n" from the code. The example I was using to go by
said this would remove the return, but obviously it wont. Here is what
I changed it to.

Here is code from my report options page:

'Setup user's comments in correct format so that it can be
'passed to the comment formula on the report.

Dim tmpReplace As String

tmpReplace = txtComments.Text.Trim

'Replace double quotes in the string with 2 double quotes.
tmpReplace=tmpReplace.Replace(Chr(34), Chr(34) + Chr(34))

'Replace carriage returns & line feed with double quotes &
'text that represents a return and line feed.
tmpReplace = tmpReplace.Replace(Chr(13) + Chr(10), """ +
chr(13) + chr(10) + """)

'Add double quotes to tmpReplace.
tmpReplace = """" + tmpReplace + """"

Session("UComments") = tmpReplace

This allows me to pass the text to my web form that contains my
CrystalReport Viewer. On this page, I have the following text:

oRpt.DataDefinition.FormulaFields.Item("UserCommen ts").Text
= Trim(Session("UComments"))
CrystalReportViewer1.ReportSource = oRpt

By doing this I can pass the value to a blank formula field named
UserComments on my report. Took forever, but I finally got everything
to work.
Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.