visual basic escaping quotes - vb.net

I feel dumb for not being able to figure this out, but I can't seem to find a post or google search that seems to get this to make sense to me. I have the following code:
Select Case frmRMAT.TblRMATrackDataGridView.Item("courier", 1).Value.ToString
Case "FedEx"
sTrackNum = "<a href=""https://www.fedex.com/fedextrack/?tracknumbers=""" & frmRMAT.TblRMATrackDataGridView.Item("tracking_num", 1).Value
End Select
as you can see I have escaped the first part, but I need the actual value to be included. It is currently giving me this value:
sTrackNum = "<a href="https://www.fedex.com/fedextrack/?tracknumbers="689691090971 "
So I do not need the " before the actual tracking number. How do I manipulate the quotes so that I obtain a proper html string? Thanks

Just omit the quotes you don't want to have.
Use
sTrackNum = "<a href=""https://www.fedex.com/fedextrack/?tracknumbers=" & frmRMAT.TblRMATrackDataGridView.Item("tracking_num", 1).Value
instead of
sTrackNum = "<a href=""https://www.fedex.com/fedextrack/?tracknumbers=""" & frmRMAT.TblRMATrackDataGridView.Item("tracking_num", 1).Value
You could also use XML literals:
sTrackNum = <a href=<%= "https://www.fedex.com/fedextrack/?tracknumbers=" & frmRMAT.TblRMATrackDataGridView.Item("tracking_num", 1).Value %>></a>

Related

Email output adding line breaks when inserting variables into email body using Access VBA

I have an email that's being automatically generated and filling the body with results from a query. It is outputting query result items on separate lines.
The Results appear like:
LOB:
Comments
But Should Appear as:
LOB: Comments
strQryResults = strQryResults & "<li><span style='color:#000000;font-family:arial;'>" & ![LOB] & ": " & ![Comments] & "</Span>" & vbCrLf
.MoveNext
How can I remove these line breaks?
When I do Left(![Comments], 4) I see:
<div
This is what's creating the new line, but what's creating the
<div>
Updated to show answer/workaround:
In order to remove the unnecessary div tags, I replaced ![Comments] with:
Mid(![Comments], 6, Len(![Comments]) - 5)

find & vbCrLf & within a string - vb.net

In a string I have something like "First & vbCrLf & Name" - however, I want to take out the & vbCrLf & so it doesnt cause a line break.
I have done something like
If theString.Contains("& vbCrLf &") Then
' and replace, could do this above of course, but I just want it to go into the IF
End If
and
If theString.Contains("\n") Then
' and replace, could do this above of course, but I just want it to go into the IF
End If
and even "\r\n" but to no avail.
What am I missing?
If theString.Contains(vbCrLf) Then
'Do something
End If
Alternatively...
theString = theString.Replace(vbCrLf, "")
Try:
If theString.Contains(Environment.NewLine) Then
' Code goes here
End If
Remove the vbCrLf from the string literal in Contains.
testVal = testVal.Replace(vbCrLf, String.Empty).Replace("&", String.Empty)
Metacharacters not supported by VB.Net for Strings - can be used with RegEx and probably a few other .Net functions.
In your OP I think you intended:
If theString.Contains("& vbCrLf &") Then
to be
If theString.Contains(vbCrLf) Then
You can test for and replace in one command:
Dim s As String = vbCrLf
MsgBox(s.Length)
s = s.Replace(vbCrLf, "")
MsgBox(s.Length)

How can I remove the initial return when the multiple texts are added to the field?

I am asking the user to select a txt file from a specified folder on a server [This is in PowerPoint 2007], but I need to give them the option of selecting more than one, so I have a bit of conditional code to determine this.
One file selected uses this code:
oShape.TextFrame.TextRange.Text = Text
More than one file selected currently uses this:
oShape.TextFrame.TextRange.Text = oShape.TextFrame.TextRange.Text & vbCrLf & vbCrLf & Text
…but this results in an extra return space above it all in the field, which is a bit untidy.
Could anyone advise me on how I can modify this to only get the returns in between the two texts, but not at the beginning?
I am not entirely sure I got the problem, but I believe this will do:
oShape.TextFrame.TextRange.Text = iif(oShape.TextFrame.TextRange.Text <> "", oShape.TextFrame.TextRange.Text & vbCrLf & vbCrLf, "") & Text

Use the actual value of String as a Formatted Value for TextBlock.Text

So basically I have this:
A WPF window with 1 Button (btn_Convert) and 2 TextBoxes (txtBox_StringValue and txtBox_Result).
In txtBox_StringValue I then paste in a formatted string value:
"This is a Header" & vbCrLf & "======================" & _
vbCrLf & "INFO" & vbCrLf & "======================"
Then when I click btn_Convert I would like the following to happen.
Code:
Dim tempStringValue = txtBox_StringValue.Text
txtBox_Results.Text = tempStringValue
However (obviously), when I do the above the Results TextBox just displays the string again:
"This is a Header" & vbCrLf & "======================" & _
vbCrLf & "INFO" & vbCrLf & "======================"
Instead of:
This is a Header
======================
INFO
So how do I get the value of the string and then strip the containing double-quotes so that the value when assigned acts like it was a variable value set in code, not just passing a string.
From the research I have done I am guessing that I need to use Reflection, however I am not familiar with the Reflection concept and don't know how to approach it.
Any help would be greatly appreciated!
Reflection won't help you in this case. It sounds like what you're talking about is dynamically interpreting some VB.NET source code and output the result of executing that code to another text box. In that case you need to use the Code DOM classes to dynamically build an assembly in memory and execute it.

quotes in vb.net links

I want to make a link from what the user filepath that is given from an openfiledialog. But I can't get all the quotes in the right places
DOCTextBox.Text = "" & TitleTextBox.Text & ""
In order to put a " in a VB.Net string literal, you need to write "".
For example:
"<a href=""" & HttpUtility.HtmlAttributeEncode(OpenFileDialog1.FileName) _
& """target=_""blank"">" & HttpUtility.HtmlEncode(TitleTextBox.Text) & "</a>"
DOCTextBox.Text = "" & TitleTextBox.Text & ""
It sounds like you're trying to add quotes into the final string produced from the expression. In order to do that use a pair of double quotes "". For example
""
You can use triple quotes such as """