Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Difficulty with an '&'

Status
Not open for further replies.

CestusGW

Programmer
Jul 2, 2002
55
CA
I have a VB 6.0 application which is doing a lot of work with directory structures. Many of these dirs contain the '&' character in them. This character always places spaces to either side of itself when it is read by VB. Is there any escape function for VB (I haven't found one yet!)? Greg W
wolgemga@aecl.ca
 
The '&' char is the string concatenation operator, and if the editor is placing spaces automatically around it, then the editor is assuming it to be the string operator.

You should be able, without any problem, to embed this character into a string

DirName = "Dogs&Cats" - note that the & is inside the string. If for some reason that doesn't work, you can also use the Chr() function, using 38 to represent the &

DirName = "Dogs" & chr(38) & "Cats" Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
This problem is actually coming from a batch file that is written, not the VB application itself (whoops, should've traced the error further first) Greg W
wolgemga@aecl.ca
 
How about a sample,

I made and EXE
Sub Main()
MsgBox Command$
End
End Sub

and did DOS...

test DOGS&CATS

and the messagebox was correct, DOGS&CATS with no spaces inserted.

The command line came through fine. Win98 VB5.

Have you gotten that far in your testing?





 
I'm using WinNT 4 SP6 with VB6 SP5, and here was what my .bat file that was generated had:
myEx.exe Z:\R&D_Branch\myDirWhen it ran in the console window however it displayed:
myEx.exe Z:\R & D_Branch\myDirAnd then it threw an error
I solved the problem though by simply enclosing my command argument in ' " ' quotations, and parsing them out through the program. Greg W
wolgemga@aecl.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top