By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,395 Members | 1,427 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,395 IT Pros & Developers. It's quick & easy.

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

P: n/a
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?
Nov 12 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"Colleyville Alan" <ae***********@nospam.comcast.net> wrote in message
news:hQ5Xb.301971$xy6.1484743@attbi_s02...
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?


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

myvar = myvar & a
myvar =myvar & b

Nov 12 '05 #2

P: n/a
myvar = a & b

Mike Storr
www.veraccess.com
"Colleyville Alan" <ae***********@nospam.comcast.net> wrote in message
news:hQ5Xb.301971$xy6.1484743@attbi_s02...
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?

Nov 12 '05 #3

P: n/a
"Randy Harris" <ra***@SpamFree.com> wrote in message
news:Y0********************@newssvr28.news.prodigy .com...
"Colleyville Alan" <ae***********@nospam.comcast.net> wrote in message
news:hQ5Xb.301971$xy6.1484743@attbi_s02...
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?


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

myvar = myvar & a
myvar =myvar & b


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.MoveNext
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?
Nov 12 '05 #4

P: n/a
"Colleyville Alan" <ae***********@nospam.comcast.net> wrote in message
news:Uf6Xb.170681$U%5.797137@attbi_s03...
"Randy Harris" <ra***@SpamFree.com> wrote in message
news:Y0********************@newssvr28.news.prodigy .com...
"Colleyville Alan" <ae***********@nospam.comcast.net> wrote in message
news:hQ5Xb.301971$xy6.1484743@attbi_s02...
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?
There's no keyword to do that, however, you can use:

myvar = myvar & a
myvar =myvar & b


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.MoveNext
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?


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

Nov 12 '05 #5

P: n/a
> >
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?
For x = 1 To iNumRecs3 Step 1
myStr = myStr & rstMyRecs![Group] & " " & rstMyRecs![Name] &

" "
rstMyRecs.MoveNext
Next x

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
Nov 12 '05 #6

P: n/a
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 gstrMyGlobalConstant As String
Public gstrAnotherGlobalConstant 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:

gstrMyGlobalConstant = "Hello"
gstrAnotherGlobalConstant = "Alan"

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

myvar = gstrMyGlobalConstant & " " & gstrAnotherglobalConstant
the result would be: "Hello Alan"

OR
myvar = gstrMyGlobalConstant
myvar= myvar & " " & gstrAnotherGlobalConstant
the result would again be: "Hello Alan"

Hope this helps.

Tom
"Colleyville Alan" <ae***********@nospam.comcast.net> wrote in message
news:hQ5Xb.301971$xy6.1484743@attbi_s02...
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?

Nov 12 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.