Results 1 to 6 of 6

Thread: & or +

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 1999
    Location
    Los Angeles
    Posts
    186

    Question

    Hi guys, a thought:

    In concatenating strings one can use & or +, what is best?

    What's your opinion?


    André

  2. #2

    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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 1999
    Location
    Los Angeles
    Posts
    186
    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!

  4. #4
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    455
    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

  5. #5
    Member
    Join Date
    Apr 1999
    Posts
    38
    msgbox (1 + 2) results in 3
    msgbox (1 & 2) results in 12

    therefore, if you want to concatenate 2 strings (or numbers), always use & !

  6. #6
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Thumbs up

    Hey michelle that's really good!

    I usually check for IsNull() but your method is obviously quicker!
    Mark
    -------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width