Results 1 to 9 of 9

Thread: [2005] Hi ppl - Open dir [RESOLVED]

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2006
    Posts
    23

    Unhappy [2005] Hi ppl - Open dir [RESOLVED]

    hi all...

    i have a form With:
    Button1
    listbox1
    listbox2

    wath i need is wen i click my button open the thir:

    ("C:\Programs\ "+ listbox1.Selecteditem) ---- this work fine

    but if i need

    ("C:\Programs\" + listbox1.selecteditem + listbox2.selecteditem )


    supose i have a selected item in listbox1 -- EXP and i have other in listbox2 -- TEXT.txt, wen i click button1 i need this result:

    open ("c:\Programs\EXP\TEXT.txt)
    Last edited by Bruno Frade; Jun 22nd, 2006 at 04:01 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Hi ppl - Open dir

    You simply need to concatenate with an additional "\" between the two list box items. Alternatively you could use the String.Format method, or even IO.Path.Combine twice.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    Re: [2005] Hi ppl - Open dir

    Something like this....

    ("C:\Programs\" & listbox1.selecteditem & "\" & listbox2.selecteditem)

    Bob
    "I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jun 2006
    Posts
    23

    Re: [2005] Hi ppl - Open dir

    tks for all, but can you explain in a few words the diference between

    ("C:\Programs\" + listbox1.selecteditem)

    and

    ("C:\Programs\" & listbox1.selecteditem)

    just to learn...

    txk bie
    Bruno Frade

  5. #5
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    Re: [2005] Hi ppl - Open dir

    + is a math operator, used for addition.
    & is a text operator.

    I think, but I'm sure JMC will be more concise.... very shortly....
    "I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Hi ppl - Open dir

    "+" is the addition operator while "&" is the concatenation operator.

    "str1" + "str2" = "str1str2"
    "str1" & "str2" = "str1str2"
    1 + 2 = 3 -> The number 3
    1 & 2 = "12" -> A string
    "str1" + 2 -> Unhandled Exception: Cannot convert String to Integer
    "str1" & 2 = "str12"
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jun 2006
    Posts
    23

    Re: [2005] Hi ppl - Open dir [RESOLVED]

    ok, tkx very much

    congratz to VBForums, and for all members..

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Hi ppl - Open dir

    And...

    "10" + 2 = 12 -> The number 12

    Basically, "+" will concatenate if both operands are strings but otherwise will try to convert to Double if the operands are different types. If the string can be converted to a Double then it is, otherwise an excpetion is thrown. "&" will convert both operands to type String by calling their ToString method no matter what the type of either operand.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    Re: [2005] Hi ppl - Open dir

    ^^^ Told ya !

    Quote Originally Posted by staticbob

    I think, but I'm sure JMC will be more concise.... very shortly....
    "I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings

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