Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA equivalent to += 1

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Is there a VBA equivalent to += to concatentate a variable with itself and another variable or string literal.

I tried googling, but I didn't seem to find anything and I am assuming that += in a search box might be seen as operators or something.

I tried "+=" but that yielded nothing either?

Is the only way by typing VariableName = VariableName + "xyz"

Cheers,
1DMF



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 


Hi,

I would recommend NEVER using the PLUS sign for string concatenation. The PLUS sign ought to be used for arithmetic operations.
Code:
VariableName = VariableName & "xyz"


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
oh , I was taught by Duanne that you use it to ensure NULL + ' ' = NULL wheres as NULL & ' ' = ' '.

Eitherway is there not a &= , i tried it but get an error?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 


I suppose that there are some instances, as you mentioned.

What's the deal with += or &= ??? Are you referring to c# 'shortcut' syntax? Appears there is none in VB, AFAIK.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Dunno about it being C# 'shortcut' syntax but it is normal syntax in Java and perl.

Oh well, was worth asking, thanks for the reply.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
The plus sign can be very handy for database concatenations in queries, where the possibility of a null value exists. A common one is middle initial that gets omitted.

first & " " & mid + ". " & last as FullName

if a mid exists then you would get something like
John P. Smith
and if no mid
John Smith

If you use & you would get
John . Smith
When a mid is omitted

string + null = null
string & null = string
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top