Solved

How do I code this DOS command in VB6

Posted on 2009-07-01
7
354 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

705 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