locked
Trouble combining a string and string variable into one variable RRS feed

  • Question

  • User-1995349159 posted
    Dear Forum, Thanks for taking a look at my question. I am trying to insert a string variable inside of two strings, and make a combined string. Public Sub Page_Load() Dim Id As String Id = Trim(Request.QueryString("Id")) End Sub Dim mp3text as string = "http://www.mydomain.com/media/" & Id & ".mp3" My goal is to make the mp3text variable have a string that is: http://www.mydomain.com/media/7.mp3 (If Id is 7) It is for some reason not connecting up correctly. I checked what string it is outputting and this is what it is giving: http://www.silvertaglive.com/media/.mp3 It is missing the Id content. Thanks again for your advice. Jeff Boise, ID
    Saturday, April 4, 2009 5:34 PM

Answers

  • User-1760427068 posted

    Hi Jeff:

    When you posted the above post, by chance were you using a browser other than Internet Explorer?  The reason I ask, I noticed the entire post was pushed into one compact paragraph.

    If you use Internet Explorer, when you are typing up your post, above the box is a series of icons starting with B and I for bold and italics and it works its way to the right, ending with an icon that has two green braces and when you mouse over this last one the tooltip reads "Source Code".  When you select this you get a box and you can type VB code (I see Dim and Sub in your code) into the box and select VB on the choices below and then your post  will specially format the code, recognizing that it is VB code, and it will look in the same way that it looks when you type it on a code behind page.  The box that comes up has the title "Source Code" over it.

    If you use other browsers these icons don't appear (and thus this option is not available).

    I'm interested in trying to solve your question so I'm going to copy your code to a blank VB code behind page and try to reconstruct it.  I hope you have a good experience here at the forum.

    ---

    Dear Forum,

    Thanks for taking a look at my question. I am trying to insert a string variable inside of two strings, and make a combined string.

     

        Public Sub Page_Load()
    
            Dim Id As String Id = Trim(Request.QueryString("Id")) 
    
        End Sub
    
        Dim mp3text As String = "http://www.mydomain.com/media/" & ID & ".mp3"
     

    My goal is to make the mp3text variable have a string that is:

    http://www.mydomain.com/media/7.mp3 (If Id is 7)

     It is for some reason not connecting up correctly.  I checked what string it is outputting and this is what it is giving:

    http://www.silvertaglive.com/media/.mp3

     It is missing the Id content. Thanks again for your advice.

    Jeff Boise, ID

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 4, 2009 6:44 PM
  • User-1760427068 posted

     

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="GoToJeffPage.aspx.vb" Inherits="GoToJeffPage" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
          Type in an integer:  <asp:TextBox ID="IntegerTextBox" runat="server"></asp:TextBox>  
          <br /><br />  
          
          <asp:Button ID="Button1" runat="server" Text="Take the Integer to the next page" />   
          <br /><br /> 
          
          <div id="feedback" runat="server" /> 
     
        </div>
        </form>
    </body>
    </html>
     

     

     

     

    Partial Class GoToJeffPage
        Inherits System.Web.UI.Page
    
        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Try
                Dim i As Integer = Convert.ToInt32(IntegerTextBox.Text)
                'feedback.InnerHtml = "The number is " + i.ToString() + "."
                Response.Redirect("Jeff.aspx?JeffID=" + i.ToString())
            Catch ex As Exception
                feedback.InnerHtml = "Your content was not accepted.  Try Again."
            End Try
    
        End Sub
    End Class
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 4, 2009 7:17 PM
  • User-1760427068 posted

     

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Jeff.aspx.vb" Inherits="Jeff" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
        <div id="feedback" runat="server" />
        
        </div>
        </form>
    </body>
    </html>

     

     

    Partial Class Jeff
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal Source As Object, ByVal E As EventArgs) Handles MyBase.Load
    
            Dim Id As String = Trim(Request.QueryString("JeffID"))
            Dim mp3text As String = "http://www.mydomain.com/media/" & Id & ".mp3"
    
            feedback.InnerHtml = "x" + mp3text + "x"
            feedback.InnerHtml += "<br /><br />"
            feedback.InnerHtml += "The x's were added to confirm that no upexpected white space characters were added."
    
        End Sub
    
    End Class
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 4, 2009 7:18 PM
  • User-1760427068 posted

    I did my first project with a query string a week ago so your question was a chance to try it again (thank you).

    There was something in the Dim statement that needed changing. 

            Dim Id As String Id = Trim(Request.QueryString("Id"))

    This was changed to

    Dim Id As String = Trim(Request.QueryString("JeffID"))

    see comment below--I think you ran into fatigue plowing through post after post on VB forums that said "Sorry this is in C# but you can easily translate it".  I'm a C# person (in a VB world, comic relief here) and I think you saw a lot of "String nameforit = ..." in the C# code.  When you have a chance can you look at your code behind page again and see if it flagged that line as "bad" with underlines or something?

    Now that we have an example to use, we can compare the code and see if there are any other differences.

    My first goal is that you look at the example, change your code, and report it works completely (thread closed, answer marked, we're both happy).  After this, with your permission, I would want to add a post or two to take things a step further.  I think your question is a good stopping point for a person starting out (save them some time because they have a complete example and don't have to go hopping around for hours or days to try and put everything together).  Also, I noticed that with asking Google to cough up VB.NET QueryString examples, it pulled up a lot of pages that were frustratingly all C#. You may have run into this too.

    I wrapped the resulting string between two x characters so we could readily see if there any unexpected white space added.  I do this because in a previous nightmare, two things that were supposed to be equal failed the equality test (one was content taken from a table in a database).  I finally discovered that on one side there was an unexpected whitespace character, and thus "cat"=" cat" is not true, no equality, the program wouldn't do what it was supposedd to do next, etc.  Possibly you are already aware of this since you added a Trim, but I wanted to make sure.  If you tell me it is OK to write another post that tries some other things for learning purposes I'll pursue this further.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 4, 2009 7:24 PM

All replies

  • User-1760427068 posted

    Hi Jeff:

    When you posted the above post, by chance were you using a browser other than Internet Explorer?  The reason I ask, I noticed the entire post was pushed into one compact paragraph.

    If you use Internet Explorer, when you are typing up your post, above the box is a series of icons starting with B and I for bold and italics and it works its way to the right, ending with an icon that has two green braces and when you mouse over this last one the tooltip reads "Source Code".  When you select this you get a box and you can type VB code (I see Dim and Sub in your code) into the box and select VB on the choices below and then your post  will specially format the code, recognizing that it is VB code, and it will look in the same way that it looks when you type it on a code behind page.  The box that comes up has the title "Source Code" over it.

    If you use other browsers these icons don't appear (and thus this option is not available).

    I'm interested in trying to solve your question so I'm going to copy your code to a blank VB code behind page and try to reconstruct it.  I hope you have a good experience here at the forum.

    ---

    Dear Forum,

    Thanks for taking a look at my question. I am trying to insert a string variable inside of two strings, and make a combined string.

     

        Public Sub Page_Load()
    
            Dim Id As String Id = Trim(Request.QueryString("Id")) 
    
        End Sub
    
        Dim mp3text As String = "http://www.mydomain.com/media/" & ID & ".mp3"
     

    My goal is to make the mp3text variable have a string that is:

    http://www.mydomain.com/media/7.mp3 (If Id is 7)

     It is for some reason not connecting up correctly.  I checked what string it is outputting and this is what it is giving:

    http://www.silvertaglive.com/media/.mp3

     It is missing the Id content. Thanks again for your advice.

    Jeff Boise, ID

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 4, 2009 6:44 PM
  • User-1760427068 posted

     

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="GoToJeffPage.aspx.vb" Inherits="GoToJeffPage" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
          Type in an integer:  <asp:TextBox ID="IntegerTextBox" runat="server"></asp:TextBox>  
          <br /><br />  
          
          <asp:Button ID="Button1" runat="server" Text="Take the Integer to the next page" />   
          <br /><br /> 
          
          <div id="feedback" runat="server" /> 
     
        </div>
        </form>
    </body>
    </html>
     

     

     

     

    Partial Class GoToJeffPage
        Inherits System.Web.UI.Page
    
        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Try
                Dim i As Integer = Convert.ToInt32(IntegerTextBox.Text)
                'feedback.InnerHtml = "The number is " + i.ToString() + "."
                Response.Redirect("Jeff.aspx?JeffID=" + i.ToString())
            Catch ex As Exception
                feedback.InnerHtml = "Your content was not accepted.  Try Again."
            End Try
    
        End Sub
    End Class
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 4, 2009 7:17 PM
  • User-1760427068 posted

     

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Jeff.aspx.vb" Inherits="Jeff" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
        <div id="feedback" runat="server" />
        
        </div>
        </form>
    </body>
    </html>

     

     

    Partial Class Jeff
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal Source As Object, ByVal E As EventArgs) Handles MyBase.Load
    
            Dim Id As String = Trim(Request.QueryString("JeffID"))
            Dim mp3text As String = "http://www.mydomain.com/media/" & Id & ".mp3"
    
            feedback.InnerHtml = "x" + mp3text + "x"
            feedback.InnerHtml += "<br /><br />"
            feedback.InnerHtml += "The x's were added to confirm that no upexpected white space characters were added."
    
        End Sub
    
    End Class
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 4, 2009 7:18 PM
  • User-1760427068 posted

    I did my first project with a query string a week ago so your question was a chance to try it again (thank you).

    There was something in the Dim statement that needed changing. 

            Dim Id As String Id = Trim(Request.QueryString("Id"))

    This was changed to

    Dim Id As String = Trim(Request.QueryString("JeffID"))

    see comment below--I think you ran into fatigue plowing through post after post on VB forums that said "Sorry this is in C# but you can easily translate it".  I'm a C# person (in a VB world, comic relief here) and I think you saw a lot of "String nameforit = ..." in the C# code.  When you have a chance can you look at your code behind page again and see if it flagged that line as "bad" with underlines or something?

    Now that we have an example to use, we can compare the code and see if there are any other differences.

    My first goal is that you look at the example, change your code, and report it works completely (thread closed, answer marked, we're both happy).  After this, with your permission, I would want to add a post or two to take things a step further.  I think your question is a good stopping point for a person starting out (save them some time because they have a complete example and don't have to go hopping around for hours or days to try and put everything together).  Also, I noticed that with asking Google to cough up VB.NET QueryString examples, it pulled up a lot of pages that were frustratingly all C#. You may have run into this too.

    I wrapped the resulting string between two x characters so we could readily see if there any unexpected white space added.  I do this because in a previous nightmare, two things that were supposed to be equal failed the equality test (one was content taken from a table in a database).  I finally discovered that on one side there was an unexpected whitespace character, and thus "cat"=" cat" is not true, no equality, the program wouldn't do what it was supposedd to do next, etc.  Possibly you are already aware of this since you added a Trim, but I wanted to make sure.  If you tell me it is OK to write another post that tries some other things for learning purposes I'll pursue this further.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 4, 2009 7:24 PM
  • User-1995349159 posted
    Dear LDechent,

    That worked great.

    I set up all the files and they worked perfectly. Really smooth. And once I had that working, I distilled it down to the code that I really needed below.

    That is interesting how you are able to load the content into the html into a similarly named Division. The code feedback.InnerHtml = mp3text looks like it directs the content.

    Thanks for fixing my text. Not sure what is wrong with my browser.

    <%@ Page Explicit = "True" Language="VB" Debug="True" %> <script language="VB" runat="server">
    Protected Sub Page_Load(ByVal Source As Object, ByVal E As EventArgs) Handles MyBase.Load
    Dim Id As String = Trim(Request.QueryString("JeffID"))
    Dim mp3text As String = "http://www.mydomain.com/media/" & Id & ".mp3"
    feedback.InnerHtml = mp3text
    End Sub
    </script>
    <head runat="server">

    <form id="form1" runat="server">


    </form>

    By the way, I do really appreciate your help. At least I have the content combined. I am just trying to slide it into the middle of some content in html, and it is acting kind of tricky.
    Saturday, April 4, 2009 8:54 PM
  • User-1760427068 posted

    Which browser are you using?  Chrome?

    I like Chrome but I always use Internet Explorer when writing a post.  I want you to try this since I believe you will want to write other posts and so you will want to:

    1) see the source code icon with the green braces

    2) try typing code into the box that appears when you click the source code icon

    (I'm happy the original problem is solved.  That is always a good feeling)

     

    Saturday, April 4, 2009 9:05 PM
  • User-1995349159 posted

    Right now it is saying that mp3text is not declared. It is as if the Subroutine is shielding the variables from the rest of the code.

    Thanks, Jeff
    Saturday, April 4, 2009 9:13 PM
  • User-1995349159 posted
    Internet explorer 6.0 on xp 64bit Maybe I need to reboot or something. But all other web sites are ok. Maybe this site was upgraded so that I have to have 7 now?
    Saturday, April 4, 2009 9:19 PM
  • User-1760427068 posted

    When you go to type a post, there is a gray bar above where you type and under the bold word Message.

    If that gray bar doesn't have any icons, try another browser until the icons appear.  When you have it you'll see other things like a yellow smiley face, scissors, etc. and at that point you know you are on an acceptable browser.

    I'll look into your other question.  If you are interested, send me a private message with your email and I'll give you an email address so you can email me a zipped copy of the folder with your web site (this is if you are interested in this--if you are working with proprietary data or have other concerns, I understand, no worries.)

    Saturday, April 4, 2009 9:45 PM
  • User-1760427068 posted

    In what type of structure are you using the <%=mp3text%>

    ?  I made a web site with your name for the project so I can try something else and see if we can knock that question off too!  : - )

    Saturday, April 4, 2009 9:47 PM
  • User-1995349159 posted
    Dear Larry, I appreciate it a lot. Here is the code sample. The other method of InnerHtml is not working for imbedding the url in a way that works with the script used by the Flash file. What do you think? Thanks Jeff <%@ Page Explicit = "True" Language="VB" Debug="True" %>
    <script language="VB" runat="server"> Protected Sub Page_Load(ByVal Source As Object, ByVal E As EventArgs) Handles MyBase.Load
    Dim Id As String = Trim(Request.QueryString("SongID"))
    Dim mp3text As String = "http://www.mydomain.com/media/" & Id & ".mp3"
    feedback.InnerHtml = mp3text
    End Sub
    </script>
    <head runat="server">


    <form id="form1" runat="server">
    The delimiter would go below:
    <object type="application/x-shockwave-flash" data="player_mp3.swf" width="200" height="20">
    <param name="movie" value="player_mp3_maxi.swf" />
    <param name="FlashVars" value="<%=mp3text%>
    runat="server" />
    &showstop=1&showinfo=1" />
    </object>
    </form>
    Sunday, April 5, 2009 12:52 AM
  • User-1995349159 posted
    Wow, my browser is still smashing everything up. Did something change on here in the last week or so? I sent you a private message. Hopefully that came through ok.
    Sunday, April 5, 2009 12:54 AM