Solved

How do I code this DOS command in VB6

Posted on 2009-07-01
7
344 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 16

Expert Comment

by:HooKooDooKu
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Easy CSR creation in Exchange 2007,2010 and 2013
Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

763 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

10 Experts available now in Live!

Get 1:1 Help Now