Solved

How do I code this DOS command in VB6

Posted on 2009-07-01
7
345 Views
Last Modified: 2013-11-25
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

0
Comment
Question by:rbend
  • 3
  • 2
7 Comments
 
LVL 3

Expert Comment

by:astroviper
ID: 24759520
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

0
 

Author Comment

by:rbend
ID: 24759664
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?
 
0
 
LVL 3

Expert Comment

by:astroviper
ID: 24759772
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

0
Free book by J.Peter Bruzzese, Microsoft MVP

Are you using Office 365? Trying to set up email signatures but you’re struggling with transport rules and connectors? Let renowned Microsoft MVP J.Peter Bruzzese show you how in this exclusive e-book on Office 365 email signatures. Better yet, it’s free!

 
LVL 16

Expert Comment

by:HooKooDooKu
ID: 24760335
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

0
 
LVL 16

Accepted Solution

by:
HooKooDooKu earned 50 total points
ID: 24760359
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...

str = QUOTATION_MARK & "Text in Quotes" & QUOTATIONMARK

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!!!!
0
 
LVL 3

Expert Comment

by:astroviper
ID: 24760465
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.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
In this video we show how to create a User Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Mailb…
how to add IIS SMTP to handle application/Scanner relays into office 365.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now