|
-
Jul 17th, 2000, 05:43 AM
#1
Thread Starter
Addicted Member
What do you prefer for a string concatenation and why ?
I prefer & because
- it shows explicitly what the code is supposed to do.
- it forces a concatenation even if the variables aren't
declared as string.
A collegue of mine insist on using +. He claims it's faster, (which was true in vb4 but not anymore in vb5 and up) and better in general because & is a variant operator which you should avoid. This wouldn't be so annoying if he hadn't developed the habit of scanning all code on & and changing them to + which becomes very annoying after a while.
So what do you think ?
Regards,
Laurens
Using VB5 Enterprise edition SP3
VB6 Enterprise edition SP5
-
Jul 17th, 2000, 05:51 AM
#2
Fanatic Member
& all the way.
& is unambiguous. It clearly defines that you will be concatenating two strings.
+ can be misinterpreted, and many beginners in VB ask why the get the answer "1234" when doing the operation "12" + "34".
Iain, thats with an i by the way!
-
Jul 17th, 2000, 06:04 AM
#3
Hyperactive Member
& is the character
Altough the ampersand is a variant operator it's still better to use in code because you see exactly what the code is supposed to do.
There's a disadvantage, however, but as you get more experienced, it disappears.
If I write this (unformatted by vb):
seekval = "the value being seek
msgbox SeekVal&" times " & OtherVar
then vb says it's syntax error, and I ask myself why da hell? It's just the simple reason that I'm telling it that the variable 'SeekVal' is a Long when it actually is a String, so vb get's all smarty and starts arguing.
The plus sign is actually only ment for addition calculations from VB5. The reason why it can work as a concatenation symbol is for compatibility with old version programmers.
Signed, Rodik ([email protected])
Programmer,usesVB6ED
===========================
Copyright©RodikCo,2002.
Dont mind this signature ;] Its old
-
Jul 18th, 2000, 01:34 AM
#4
Thread Starter
Addicted Member
Thanks guys, I couldn't agree more.
Regards,
Laurens
Using VB5 Enterprise edition SP3
VB6 Enterprise edition SP5
-
Jul 18th, 2000, 01:41 AM
#5
Addicted Member
'+' is a mathematical term to add 2 numbers together.
'&' is a VB term to add 2 strings together.
Reality is an illusion caused by by lack of drugs
Is this real or am i just having a dream?
-
Jul 18th, 2000, 01:44 AM
#6
Hyperactive Member
Actually '&' is a VB term to implicitly convert the contents of both sides into strings and concatenate them.
-
Jul 18th, 2000, 02:15 AM
#7
Hyperactive Member
Hello LAURENS,
As a VB database user I prever to use "&".
If you made a new record in a recordset all fields are Null.
If you want to add (with "+") a Null text field to a string variable, the operation will gives an "invalid use of null" error.
When you are using the "&" sign, the error will not occur.
Maybe this is a reason to use "&" !
Nice regards,
Michelle.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|