|
-
Apr 11th, 2000, 05:36 PM
#1
Thread Starter
Addicted Member
Hi guys, a thought:
In concatenating strings one can use & or +, what is best?
What's your opinion?
André
-
Apr 11th, 2000, 05:49 PM
#2
Member
I use & only
I only ever use & to concatenate strings, for one simple reason...it's fail safe.
Because + is used to add values (when they're numbers), VB may under certain circumstances try to add strings together.
Take the following example
1+1=2
"Hello" & "my name is"...would give "Hello my name is"
"Hello" + "my name is" may actually give an integer value based on the value of the characters added together.
Hope this helps
Matt
-
Apr 11th, 2000, 05:50 PM
#3
Thread Starter
Addicted Member
It's not a problem, I also only use &, but I have seen other peoples sources where + is used for this purpose.
I agree with you completely!
-
Apr 11th, 2000, 06:00 PM
#4
Hyperactive Member
Hello André
The & sign can also be handy when you are working with an Access database.
If a field off a record is never filled in and you want to send this information to a TextBox it will give an error.
When you are using:
Text1.text = CustomerDYN!YourField 'gives an error
Text1.text = "" & CustomerDYN!YourField ' don't gives an error.
I do think the & sign is the only good choice (personal)
Michelle
-
Apr 11th, 2000, 06:12 PM
#5
Member
msgbox (1 + 2) results in 3
msgbox (1 & 2) results in 12
therefore, if you want to concatenate 2 strings (or numbers), always use & !
-
Apr 11th, 2000, 06:48 PM
#6
Frenzied Member
Hey michelle that's really good!
I usually check for IsNull() but your method is obviously quicker!
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
|