How do I declare a variable that allows data to be added to it without losing its existing value?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Colleyville Alan

    How do I declare a variable that allows data to be added to it without losing its existing value?

    I seem to recall reading somewhere that there was a keyword that allowed a
    variable to have data added to it without losing its contents.

    a = "Hi " and
    b = "There"

    myvar = a
    myvar = b

    the value of myvar after this would be "Hi There".

    How do you do accomplish this?


  • Randy Harris

    #2
    Re: How do I declare a variable that allows data to be added to it without losing its existing value?

    "Colleyvill e Alan" <aecharbonneau@ nospam.comcast. net> wrote in message
    news:hQ5Xb.3019 71$xy6.1484743@ attbi_s02...[color=blue]
    > I seem to recall reading somewhere that there was a keyword that allowed a
    > variable to have data added to it without losing its contents.
    >
    > a = "Hi " and
    > b = "There"
    >
    > myvar = a
    > myvar = b
    >
    > the value of myvar after this would be "Hi There".
    >
    > How do you do accomplish this?[/color]

    There's no keyword to do that, however, you can use:

    myvar = myvar & a
    myvar =myvar & b



    Comment

    • Mike Storr

      #3
      Re: How do I declare a variable that allows data to be added to it without losing its existing value?

      myvar = a & b

      Mike Storr



      "Colleyvill e Alan" <aecharbonneau@ nospam.comcast. net> wrote in message
      news:hQ5Xb.3019 71$xy6.1484743@ attbi_s02...[color=blue]
      > I seem to recall reading somewhere that there was a keyword that allowed a
      > variable to have data added to it without losing its contents.
      >
      > a = "Hi " and
      > b = "There"
      >
      > myvar = a
      > myvar = b
      >
      > the value of myvar after this would be "Hi There".
      >
      > How do you do accomplish this?
      >
      >[/color]


      Comment

      • Colleyville Alan

        #4
        Re: How do I declare a variable that allows data to be added to it without losing its existing value?

        "Randy Harris" <randy@SpamFree .com> wrote in message
        news:Y06Xb.2208 $t16.1782724@ne wssvr28.news.pr odigy.com...[color=blue]
        > "Colleyvill e Alan" <aecharbonneau@ nospam.comcast. net> wrote in message
        > news:hQ5Xb.3019 71$xy6.1484743@ attbi_s02...[color=green]
        > > I seem to recall reading somewhere that there was a keyword that allowed[/color][/color]
        a[color=blue][color=green]
        > > variable to have data added to it without losing its contents.
        > >
        > > a = "Hi " and
        > > b = "There"
        > >
        > > myvar = a
        > > myvar = b
        > >
        > > the value of myvar after this would be "Hi There".
        > >
        > > How do you do accomplish this?[/color]
        >
        > There's no keyword to do that, however, you can use:
        >
        > myvar = myvar & a
        > myvar =myvar & b[/color]

        Well, to be more specific, I am trying to load the contents of an array into
        a variable string.

        For x = 1 To iNumRecs3 Step 1
        myStr = rstMyRecs![Group] & " " & rstMyRecs![Name] & " "
        rstMyRecs.MoveN ext
        Next x

        Msgbox("The missing information is" & myStr)




        I cannot figure out how to do this. Right now, the myStr gets overwritten
        each time through. How can I add to this variable from a loop?


        Comment

        • Randy Harris

          #5
          Re: How do I declare a variable that allows data to be added to it without losing its existing value?

          "Colleyvill e Alan" <aecharbonneau@ nospam.comcast. net> wrote in message
          news:Uf6Xb.1706 81$U%5.797137@a ttbi_s03...[color=blue]
          > "Randy Harris" <randy@SpamFree .com> wrote in message
          > news:Y06Xb.2208 $t16.1782724@ne wssvr28.news.pr odigy.com...[color=green]
          > > "Colleyvill e Alan" <aecharbonneau@ nospam.comcast. net> wrote in message
          > > news:hQ5Xb.3019 71$xy6.1484743@ attbi_s02...[color=darkred]
          > > > I seem to recall reading somewhere that there was a keyword that[/color][/color][/color]
          allowed[color=blue]
          > a[color=green][color=darkred]
          > > > variable to have data added to it without losing its contents.
          > > >
          > > > a = "Hi " and
          > > > b = "There"
          > > >
          > > > myvar = a
          > > > myvar = b
          > > >
          > > > the value of myvar after this would be "Hi There".
          > > >
          > > > How do you do accomplish this?[/color]
          > >
          > > There's no keyword to do that, however, you can use:
          > >
          > > myvar = myvar & a
          > > myvar =myvar & b[/color]
          >
          > Well, to be more specific, I am trying to load the contents of an array[/color]
          into[color=blue]
          > a variable string.
          >
          > For x = 1 To iNumRecs3 Step 1
          > myStr = rstMyRecs![Group] & " " & rstMyRecs![Name] & " "
          > rstMyRecs.MoveN ext
          > Next x
          >
          > Msgbox("The missing information is" & myStr)
          >
          >
          >
          >
          > I cannot figure out how to do this. Right now, the myStr gets overwritten
          > each time through. How can I add to this variable from a loop?[/color]

          For x = 1 To iNumRecs3 Step 1
          myStr = myStr & rstMyRecs![Group] & " " & rstMyRecs![Name] & "
          "
          rstMyRecs.MoveN ext
          Next x



          Comment

          • Colleyville Alan

            #6
            Re: How do I declare a variable that allows data to be added to it without losing its existing value?

            > >[color=blue][color=green]
            > > I cannot figure out how to do this. Right now, the myStr gets[/color][/color]
            overwritten[color=blue][color=green]
            > > each time through. How can I add to this variable from a loop?[/color]
            >
            > For x = 1 To iNumRecs3 Step 1
            > myStr = myStr & rstMyRecs![Group] & " " & rstMyRecs![Name] &[/color]
            "[color=blue]
            > "
            > rstMyRecs.MoveN ext
            > Next x[/color]


            I must be getting punchy since I used that exact same way of doing things in
            many SQL statements but could not see it as a solution here!
            Thanks


            Comment

            • Tom C

              #7
              Re: How do I declare a variable that allows data to be added to it without losing its existing value?

              Alan,
              I create a module to put all my global public variables in.
              Each variable is prefaced with the word "Public" (g for global)

              i.e. Public gstrMyGlobalCon stant As String
              Public gstrAnotherGlob alConstant as string

              These variables can then be set from anywhere in the program and the
              value will remain even after the procedure which set them is complete.

              In response to your code as listed in your original note, I think you may
              want to try something a bit different such as:

              gstrMyGlobalCon stant = "Hello"
              gstrAnotherGlob alConstant = "Alan"

              In order to now place BOTH values into one variable you could use:

              myvar = gstrMyGlobalCon stant & " " & gstrAnotherglob alConstant
              the result would be: "Hello Alan"

              OR
              myvar = gstrMyGlobalCon stant
              myvar= myvar & " " & gstrAnotherGlob alConstant
              the result would again be: "Hello Alan"

              Hope this helps.

              Tom


              "Colleyvill e Alan" <aecharbonneau@ nospam.comcast. net> wrote in message
              news:hQ5Xb.3019 71$xy6.1484743@ attbi_s02...[color=blue]
              > I seem to recall reading somewhere that there was a keyword that allowed a
              > variable to have data added to it without losing its contents.
              >
              > a = "Hi " and
              > b = "There"
              >
              > myvar = a
              > myvar = b
              >
              > the value of myvar after this would be "Hi There".
              >
              > How do you do accomplish this?
              >
              >[/color]


              Comment

              Working...