Results 1 to 11 of 11

Thread: Bizarre string concatenation issue

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Location
    Stonington, CT
    Posts
    9

    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.

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Bizarre string concatenation issue

    What happens if you change

    Code:
    Dim myHTML As String = ""
    to just

    Code:
    Dim myHTML As String

  3. #3
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    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

    Name:  Capture.jpg
Views: 153
Size:  23.2 KB


    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)

  4. #4
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,754

    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
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: Bizarre string concatenation issue

    You're not closing your iframe element... " ></iframe>"

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Location
    Stonington, CT
    Posts
    9

    Re: Bizarre string concatenation issue

    Quote Originally Posted by OptionBase1 View Post
    What happens if you change

    Code:
    Dim myHTML As String = ""
    to just

    Code:
    Dim myHTML As String
    Tried it, same result.

  7. #7

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Location
    Stonington, CT
    Posts
    9

    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.

  8. #8

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Location
    Stonington, CT
    Posts
    9

    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.

  9. #9

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Location
    Stonington, CT
    Posts
    9

    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.

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    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
    Code:
    MsgBox(BaseString)
    Attachment 179875

  11. #11
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    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
  •  



Click Here to Expand Forum to Full Width