[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)
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.
Re: [2005] Hi ppl - Open dir
Something like this....
("C:\Programs\" & listbox1.selecteditem & "\" & listbox2.selecteditem)
Bob
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
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....
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"
Re: [2005] Hi ppl - Open dir [RESOLVED]
ok, tkx very much
congratz to VBForums, and for all members..
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.
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....