-
Jan 14th, 2021, 04:02 PM
#1
Thread Starter
New Member
Bizarre string concatenation issue
(I can't believe what I'm seeing, maybe it's just high fatigue level)
I have this code in a form:
Code:
Function BaseString() As String
Dim myHTML As String = ""
myHTML = myHTML & "<iframe" & vbCr
myHTML = myHTML & " width=" & WBrowser.Width.ToString & vbCr
myHTML = myHTML & " height=" & WBrowser.Height.ToString & vbCr
myHTML = myHTML & " frameborder=""0"" style=""border:0"""
Return myHTML
End Function
When I break the code to see the return value, it is, literally, this:
Code:
" <iframe" & vbCr & " width=300" & vbCr & " height=494" & vbCr & " frameborder=""0"" style=""border:0"""
I wouldn't know how to do that if I tried; it's as if the code itself is showing up in the string. If I break this function out, test it separately, it works as one might expect, just concatenating the strings.
Does anyone have any idea why this might be happening? It's VS 2017, fairly straightforward form code; the larger context is that I'm trying to feed HTML into a Webbrowser control to show a location on Google Maps. Doing it naively gives me an error saying that the map piece has to be in a frame, which pushed me in this direction. None of this should be relevant to the problem, though.
I would think the problem would be *something* in the interpretation environment that has gone strange, but restarting VS didn't help. I could just be blind to the cause through fatigue, but I just don't understand this.
Last edited by dday9; Jan 14th, 2021 at 04:33 PM.
-
Jan 14th, 2021, 04:09 PM
#2
Re: Bizarre string concatenation issue
What happens if you change
Code:
Dim myHTML As String = ""
to just
Code:
Dim myHTML As String
-
Jan 14th, 2021, 04:27 PM
#3
Re: Bizarre string concatenation issue
I tested your code : I put the result in a label and I get the expected result :
<iframe
width=227
height=162
frameborder="0" style="border:0"
but if I put a break to debug and see the result I get this : "<iframe width=227 height=162 frameborder="0" style="border:0""which is correct, it is the value of MyHTML.
try to use the text visualization, when you check for the value, there is a small magnifying glass icon , click on it and click on the first line "text visualization" (or something like that. it will interpret the value and display it in a new windows
PS: I had to change WBrowser by something else to get a value
Last edited by Delaney; Jan 14th, 2021 at 04:39 PM.
The best friend of any programmer is a search engine
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
-
Jan 14th, 2021, 04:36 PM
#4
Re: Bizarre string concatenation issue
I would ignore using the concatenation and go with interpolation since you're using VS2017:
Code:
Function BaseString() As String
Return $"<iframe
width={WBrowser.Width.ToString()}
height={WBrowser.Height.ToSTring()}
frameborder="")"" style=""border: 0"""
End Function
-
Jan 14th, 2021, 05:40 PM
#5
Re: Bizarre string concatenation issue
You're not closing your iframe element... " ></iframe>"
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 14th, 2021, 08:50 PM
#6
Thread Starter
New Member
Re: Bizarre string concatenation issue
Originally Posted by OptionBase1
What happens if you change
Code:
Dim myHTML As String = ""
to just
Code:
Dim myHTML As String
Tried it, same result.
-
Jan 14th, 2021, 08:51 PM
#7
Thread Starter
New Member
Re: Bizarre string concatenation issue
In a different context, a sub I set up to test, it also works correctly. So the question is, why would it not? I can't imagine any environment issue that would cause this. I've never seen it before, and it makes absolutely no sense.
-
Jan 14th, 2021, 08:54 PM
#8
Thread Starter
New Member
Re: Bizarre string concatenation issue
True, because later I add a URL with a google.maps thing with a lat/lon included, and only then do I close the frame.
The main issue is - why does string concatenation behave this way in this context? Has anyone seen anything like this? It makes zero sense to me. I'm trying to work through what I think might be going on at the interpreter level, or translation to MSIL process, and I can't imagine this sort of oddity.
-
Jan 14th, 2021, 08:58 PM
#9
Thread Starter
New Member
Re: Bizarre string concatenation issue
I don't disagree that in a different context it acts as expected. This program will eventually be a screensaver, so it starts with a Sub Main(), then brings up the main form. If I try the code in the Sub Main, it works just fine. There's something about being in the form class that seems to cause it to run off the rails, but I'm not sure what, nor what to test for or look for; it seems to be a kind of 'meta' problem, not related to the soundness (or lack thereof) of the specific code fragment, but rather something that causes the entire language environment to misbehave.
Tomorrow I'll try to refactor things to break everything into little digestable pieces that may be tested, but I wish I had some idea of what type of problem I was looking for. I *could* try it in VS 2019 and see if I see the same behavior - maybe the first thing to do.
-
Jan 14th, 2021, 09:03 PM
#10
Re: Bizarre string concatenation issue
It works as expected for me...
Code:
Function BaseString() As String
Dim myHTML As String = ""
myHTML = myHTML & "<iframe" & vbCr
myHTML = myHTML & " width=" & WBrowser.Width.ToString & vbCr
myHTML = myHTML & " height=" & WBrowser.Height.ToString & vbCr
myHTML = myHTML & " frameborder=""0"" style=""border:0"""
Return myHTML
End Function
Attachment 179875
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 14th, 2021, 09:18 PM
#11
Re: Bizarre string concatenation issue
Yeah, works fine.
Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MessageBox.Show(BaseString)
End Sub
Function BaseString() As String
Dim myHTML As String
myHTML = "<iframe" & vbCr
myHTML = myHTML & " width=" & WBrowser.Width.ToString & vbCr
myHTML = myHTML & " height=" & WBrowser.Height.ToString & vbCr
myHTML = myHTML & " frameborder=""0"" style=""border:0"
Return myHTML
End Function
I removed the leading and trailing ""
If you put a break point at "Return myHTML" the value display is the same as you posted but what's strange about that.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|