|
-
Aug 14th, 2003, 10:20 AM
#1
Thread Starter
Frenzied Member
& or +? *RESOLVED*
Which is the standard/better way to add strings together?
VB Code:
MsgBox "DataSave.Param" + Format(n + 1) + "=s"
or
VB Code:
MsgBox "DataSave.Param" & Format(n + 1) & "=s"
Is there any difference between using '&' or '+'?
Is either considered bad practice?
Last edited by agmorgan; Aug 15th, 2003 at 03:33 AM.
-
Aug 14th, 2003, 10:23 AM
#2
Frenzied Member
It depends on what programming language your using.
VB and ASP use & for string concatenation.
But the C based languages use the + for string concatenation.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Aug 14th, 2003, 10:30 AM
#3
Thread Starter
Frenzied Member
Im using VB6 and I always used & for string concatenation
I just inherited a project and it is full of +'s.
It still works though.
I guess the previous programmer had a C background then...
-
Aug 14th, 2003, 10:32 AM
#4
PowerPoster
depends on what it is you want to do. "+" means addition, so if you do
1 + "2", then answer is 3
but "&" is concatendation, so if you do
1 & "2", then the answer is "12"
See, they are not even remotely the same thing.
-
Aug 14th, 2003, 10:39 AM
#5
Thread Starter
Frenzied Member
This gives the same result though
VB Code:
Private Sub Form_Load()
MsgBox "hi" & " phinds"
MsgBox "hi" + " phinds"
Unload Me
End Sub
So they can be similar in some situations...
-
Aug 14th, 2003, 03:19 PM
#6
Frenzied Member
Originally posted by agmorgan
This gives the same result though
VB Code:
Private Sub Form_Load()
MsgBox "hi" & " phinds"
MsgBox "hi" + " phinds"
Unload Me
End Sub
So they can be similar in some situations...
I believe that is called getting lucky! 
That only worked because the compliere was unable to perform the math and add the 2 strings together.. The compiler has a bug in it.. Becarefull and don't put a complementing bug in your code..
Rudy
10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".
-
Aug 14th, 2003, 03:24 PM
#7
Junior Member
My VB book "Sam's teach yourself VB in 24 hours" shows that either will work, but recommends to use & when putting strings together and reserve + for math, since it looks cleaner,
-
Aug 14th, 2003, 03:25 PM
#8
Hyperactive Member
always use '&' when concatenating 2 strings and '+' when adding a value to a number......
its just bad programming practice to use '+' when dealing with strings.
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
|