• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 372
  • Last Modified:

How do I code this DOS command in VB6

This command on the command line in a DOS box works fine.
    copy /b song 1.mp3+song 2.mp3+song 3.mp3 allsongs.mp3
It combines all 3 songs into 1 song and the result is a file that plays all 3 songs one after another.
How do I envoke that command from a VB6 application?
(NOTICE: the space between the word "song" and the number after it)
(Please show me how to do it if there is a space or if there isn't one)
I've tried differend SHELL string combinations but I'm not having any luck.

copy /b song 1.mp3+song 2.mp3+song 3.mp3 allsongs.mp3
 copy /b song1.mp3+song2.mp3+song3.mp3 allsongs.mp3

Open in new window

  • 3
  • 2
1 Solution
I don't have vb6 to test this but the actual command string worked for me (without the escape slashes)

Shell("copy /b \"song 1.mp3\"+\"song 2.mp3\"+\"song 3.mp3\" allsongs.mp3") 

Open in new window

rbendAuthor Commented:
I have to ammend my previous description of the issue.
I am taking the contents of text boxes and using that as the data for the string.
So, textbox one will have " C:\songs\song1.mp3" in it.
Text box two will have "C:\songs/song2.mp3" in it etc
WIth that, I need to be able to execute from VB, what would be the equivalent in DOS.
The DOS command would be  "copy /b song1.mp3+song2.mp3 allsongs.mp3

My impression of the VB command is:
 shell("copy b/ " + text1.text + text2.text + "allsongs.mp3")
but that doesn't work for a lot of reasons.
What will work please?
Ah I see. I'm making the assumption that \ is the escape character so \" will put a double quote inside the string. In VBScript it's ""... Also assuming that + is VB6's concatenation operator, in VBScript it's &.
I don't know if it'll work but you may certainly try it:

shell("copy /b \"" + text1.text + "\"+\"" + text2.text + "\" allsongs.mp3")

Open in new window

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

astroviper sounds like he is getting you in the right direction.

While '+' will combine strings, it's better to use the '&' symbol (both add string together)... and by this I mean to use the '&' sybmol to concatinate strings (you still need the '+' sign in your DOS command that you are trying to run inside of shell).

'\' isn't a VB escape character.  To get a quotation mark embedded inside a VB string, you use two double quotes.

And lastly, I would suggest that you build the shell command in a string variable first, that way you can test the value to see if it really is what you want before sending it to the shell command.
Dim Command as String
Command = "copy /b """ & text1.text & """+""" & text2.text & """+""" & text3.text & """ ""allsongs.mp3"""
Debug.print "[" & Command & "]" 
Shell( Command )
'Command should be something like...
'copy /b "song1.mp3"+"song2.mp3"+"song3.mp3" "allsongs.mp3"

Open in new window

BTW, a trick I like to use to keep quoation marks strait (so you don't have to remember when to use double, tripple, or even quad quotation marks) is to define the constant...

Global Const QUOTATION_MARK as String = """"

Then to include a quoation mark in a string, use the constant...


It makes the code a bit longer (because connatentating the constant is more code than doubling the quotes) but it makes the code SO MUCH MORE READABLE!!!!
Thanks HooKooDooKu,
I've never done VB before, only VBScrict and I was extrapolating using what I'd found during a quick visual basic google. That syntax is exactly the same as VBScript and the one I'd used to test that I'd put the quotes in the right place. Didn't expect that.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now