Format line so that I end up with ="08075" - asp-classic

How many " (double quotes) do I put around this line so that I end up with ="08075" being pasted into my excel worksheet? The line is:
Response.Write vbTab & ResultSet(8,r)
I need and '=' sign with a single quote before the ResultSet(8,r) with a closing double quote after... I tried:
Response.Write vbTab & "="" & ResultSet(8,r) & """
but that didn't work, plus a couple others but that didn't work, the number of quotes thing always gets me so if someone wants to give me a general rule of thumb on this one I would really appreciate it.

To get a literal double quote (") inside of a string in VBScript, you need to use two double quotes (""). So for your example:
Response.Write vbTab & "=""" & ResultSet(8,r) & """"
' ^ ^ ^ ^ These delimit the string
' ^^ ^^ These create literal quotes

Wouldn't you know, I just cracked it:
Response.Write vbTab & "=""" & ResultSet(8,r) & """"
Thanks, R.

Double each quote you want to end up in the string. So what you want would be:
Response.Write vbTab & "=""" & ResultSet(8,r) & """"

Related

Exporting Json data in asp.net vb from MS SQL

I am trying to export data from MS SQL out in a json format in my asp.net web forms application. Problem is it exports with two double quotes around the values instead of just one double quote.
I want it to export like this:
{"bizunitid":"11111","prodlineid":"1","reasonforsurvey":"1"}
but it is coming out like this:
"{""bizunitid"":""11111"",""prodlineid"":""1"",""reasonforsurvey"":""2""}"
I have tried replacing the two double quotes but it always returns two double quotes.
Dim json As String = cmd.ExecuteScalar
streamWriter.Write(json.Replace("""""", Chr(34)))
Not sure if this is what you're looking for, but it's how I've done it when posting JSon to an API for a messaging app with VB.Net:
MessageTitle = MessageTitle.Replace("""", """""")
MessageBody = MessageBody.Replace("""", """""")
Dim strPostData As String = "{" &
"""notification"": {" &
"""sound"": ""default""," &
"""title"": """ & MessageTitle & """," &
"""body"": """ & MessageBody & """" &
"}, " &
"""data"": {" &
"""title"": """ & MessageTitle & """," &
"""body"": """ & MessageBody & """" &
"}," &
"""to"": """ & strRegIDs & """," &
"""priority"": 10 " &
"}"
hopefully that helps a bit

how to add my value into asp format

Dim adoRecordset
Remark is the value saved in SQL
my html value is
value="<%=adoRecordset("Remark")%>">
so how could i add it into the " ??? "
response.Write VALUE='???'
Thanks Guys ~
I think this should do the trick for you:
Response.Write "<value='" & adoRecordset("Remark") & "' name='test'>"
Edit: My quick and lazy version, as done properly by Mr. Shadow Wizard
Response.Write("<input name=""test"" value=""" & Replace(adoRecordset("Remark"), """", """) & """ />")

how to add Linebreak to a string in asp.net vb

I tried everything, but nothing seems to work!
How the do I put a breakline?!
Dim textMsg as String
textMsg = Body.text & Environment.Newline & _ q1.text & Environment.Newline & _ q2.text & Environment.Newline & _ q3.text & Environment.Newline & _ q4.text '
please help
(with corrent code I get an error cuz of the & Environment.Newline & _ ")
Since you tagged this asp.net, I'll guess that this newline should appear in a web page. In that case, you need to remember that you are creating html rather than plain text, and html ignores all whitespace... including newlines. If you view the source for your page, you'll likely see that the new lines do make it to your html output, but they are ignored, and that's what is supposed to happen. If you want to show a new line in html, use a <br> element:
textMsg = Body.text & "<br>" & _ q1.text & "<br>" & _ q2.text & "<br>" & _ q3.text & "<br>" & _ q4.text
The code above will place the text on several lines. It's interesting that if you view the source now, you'll see that everything is all on the same line, even though it uses several lines for display.
You should add a br:
textMsg = Body.text & "<BR/>" & _ q1.text & "<BR/>" & _ q2.text & "<BR/>" & _ q3.text & "<BR/>" & _ q4.text
Or you can try:
Str & VBNewLine OR Str & VBCrLf
Or set the email message to html. The the will work.
thats the right one:
& (vbCrLf) &
Try this:
dim textMsg as String
textMsg = Body.text & vbNewLine
I preffer .Net Style:
& Environment.NewLine &
It's Is exactly the same that
& (vbCrLf) &

concatenating string in classic asp

I am trying to concatenate image url (string) with img tag but i am not sure how to put " after src=. Please help to concatenate this.
response.write("<img src=" & '"' & rs("ProductImage") & '"' &" /><br/>")
You have to double up the quotes:
Response.Write("<img src=""" & rs("ProductImage") & """ /><br/>")
Since HTML can use double quotes or single quotes, why not just use single quotes for the HTML. So your code would look like this:
response.write("<img src='" & rs("ProductImage") & "' /><br/>")
The resulting output would look like this:
<img src='ProductImageUrl' /><br/>
Another option is to use the chr function:
Response.Write("<img src=" & chr(34) & rs("ProductImage") & chr(34) & " /><br/>")
ascii code 34 is the double quote. We use this all the time when writing out HTML.

ASP - Printing the entire request contents

I'm debugging some ASP code and I need to get a quick printout of the current Request datastructure, which I believe is an array of key/value pairs.
I see that Request.Form("key") is the method for extracting individual elements.
Any tips on printing out the entire thing?
Try this
For Each item In Request.Form
Response.Write "Key: " & item & " - Value: " & Request.Form(item) & "<BR />"
Next
Working:
For x = 1 to Request.Form.Count
Response.Write x & ": " _
& Request.Form.Key(x) & "=" & Request.Form.Item(x) & "<BR>"
Next
I have other Classic ASP code snippets here:
https://github.com/RaviRamDhali/programming-procedure/tree/master/Snippets/ASP
Try a FOR/EACH loop:
for each x in Request.Form
Response.Write(x)
Next

Resources