Solved

Parameters sending problem

Posted on 2000-03-27
13
187 Views
Last Modified: 2010-05-02
I've made a VB 5 program that launches WinAmp to play MP3 music.
All works fine when I launch MP3 "normal" names (i.e. crises.mp3).
The problem is I get an error when I try something like tubular bells.mp3. WinAmp understands spaces in name as separate files, so it tries to load tubular.mp3 and bells.mp3.
So the question is simple: how can I nest quotation marks? I need the double ones inside, so it can't be "  '  " (it's a pity 'cause VB takes this as correct). VB says it's wrong the form '  "  '. At least I think this is the correct form, as looking inside the Windows Explorer and the registered files, it says the order to play a winamp file is "winamp.exe" "<name>.mp3".

Actually I use the code:

    Dim xVar As Double
    Dim cParam As String
    Dim cVarExe As String
    cParam = App.Path + "Oldfield\tubular bells II.mp3" ' It's an example
    cVarExe = (cProgram + " " + cParam)
    xVar = Shell(cVarExe, vbMinimizedFocus)

The question about the nesting is easy, so I put 50 points. But if you want to answer the exact code syntax for launching the WinAmp 2.60, you can ask me to increase points to 100.
0
Comment
Question by:BETTY
  • 5
  • 4
  • 2
  • +1
13 Comments
 
LVL 14

Expert Comment

by:wsh2
ID: 2661626
To use quotations inside a string.. all you have to do is put 2 quotes together. Using your code, we would then use..

cVarExe = ("""" & cProgram & """ """ & cParam & """")

As quotes are hard to read here it is again schematically..
cVarExe = ("xx" & cProgram & "xx xx" & cParam & "xx")
where x is equal to the double quote character.


   


0
 
LVL 14

Accepted Solution

by:
mcrider earned 50 total points
ID: 2661628
Do this:


    Dim xVar As Double
    Dim cParam As String
    Dim cVarExe As String
    cParam = App.Path + "Oldfield\tubular bells II.mp3" ' It's an example
    cVarExe = (cProgram + " " + + Chr$(34)+ cParam + Chr$(34))
    xVar = Shell(cVarExe, vbMinimizedFocus)



Cheers!®©

0
 
LVL 14

Expert Comment

by:mcrider
ID: 2661632
OOPS!

Should have been this:

    Dim xVar As Double
    Dim cParam As String
    Dim cVarExe As String
    cParam = App.Path + "Oldfield\tubular bells II.mp3" ' It's an example
    cVarExe = (cProgram + " " + Chr$(34) + cParam + Chr$(34))
    xVar = Shell(cVarExe, vbMinimizedFocus)


Cheers!®©

0
 
LVL 14

Expert Comment

by:wsh2
ID: 2661652
To elaborate on your cProgram variable.. it should read like:

cProgram = "c:\Progam Files\Winamp\Winamp.exe"

(or whatever the pathname to your Winamp program is).

To elaborate on your cParam variable.. it should read like:

cParam = "c:\MyPathName\MyMP3.MP3"

(or something to that effect)

0
 
LVL 14

Expert Comment

by:wsh2
ID: 2661833
Now that I have had time.. here is a routing that all you have to do is pass the MP3 path and Filename.. Eg.

IF xShellByExtension (App.Path & "Oldfield\tubular bells II.mp3") _
Then
  MsgBox ("Successful")
Else
  MsgBox ("UNSUCCESSFUL")
End If

<----- Code Begin ----->

Option Explicit
' Declarative Section
Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
  (ByVal lpFile As String, _
  ByVal lpDirectory As String, _
  ByVal lpResult As String) _
  As Long

' xShellByExtension Function
Private Function xShellByExtension _
(ByVal strFilePathName As String) _
As Boolean

  Dim StrCommand As String
  Dim strProgram As String
  Dim lngReturn As Long
 
  strProgram = Space(255)
  lngReturn = FindExecutable(strFilePathName, "", strProgram)
  If lngReturn <= 32 _
  Then ' Error
    MsgBox (strFilePathName & " No File Association Exists!")
    Exit Function
  End If
 
  strProgram = Left$(strProgram, InStr(1, strProgram, Chr(0)) - 1)
  StrCommand = """" & strProgram & """" _
    & " " _
    & """" & strFilePathName & """"
  lngReturn = Shell(StrCommand, vbNormalFocus)
  If lngReturn <= 0 _
  Then
    MsgBox (strFilePathName & " Program Could Not Be Launched!")
    Exit Function
  End If
 
  xShellByExtension = True 'Successful

End Function

<----- Code End ----->

Enjoy.. <smile>


 

0
 
LVL 14

Expert Comment

by:wsh2
ID: 2661874
mcrider:
Look at our time stamps both "Date: Monday, March 27 2000 - 02:01PM"..  
nananananananannana.. <tongue out>.. beat ya.. LOL

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 14

Expert Comment

by:mcrider
ID: 2661979
<Yanking on your stuck out tongue and using a very large whitewash brush to paint it>  Take that! <VBG>

I just got the feeling I was in a Bugs Bunny cartoon <ROTFLMAO>!
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2662022
Or you could use ShellExecute as in this example modified from MS article
http://support.microsoft.com/support/kb/articles/Q170/9/18.asp

Option Explicit

Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As _
String, ByVal lpszFile As String, ByVal lpszParams As String, _
ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long

Private Declare Function GetDesktopWindow Lib "user32" () As Long

Const SW_SHOWNORMAL = 1

Const SE_ERR_FNF = 2&
Const SE_ERR_PNF = 3&
Const SE_ERR_ACCESSDENIED = 5&
Const SE_ERR_OOM = 8&
Const SE_ERR_DLLNOTFOUND = 32&
Const SE_ERR_SHARE = 26&
Const SE_ERR_ASSOCINCOMPLETE = 27&
Const SE_ERR_DDETIMEOUT = 28&
Const SE_ERR_DDEFAIL = 29&
Const SE_ERR_DDEBUSY = 30&
Const SE_ERR_NOASSOC = 31&
Const ERROR_BAD_FORMAT = 11&

Function StartDoc(DocName As String) As Long
    Dim Scr_hDC As Long
    Scr_hDC = GetDesktopWindow()
    StartDoc = ShellExecute(Scr_hDC, "Open", DocName, _
    "", "C:\", SW_SHOWNORMAL)
End Function

Private Sub RunDoc(ByVal sFilename As String)
    Dim r As Long, msg As String
    r = StartDoc(sFilename)
    If r <= 32 Then
        'There was an error
        Select Case r
            Case SE_ERR_FNF
                msg = "File not found"
            Case SE_ERR_PNF
                msg = "Path not found"
            Case SE_ERR_ACCESSDENIED
                msg = "Access denied"
            Case SE_ERR_OOM
                msg = "Out of memory"
            Case SE_ERR_DLLNOTFOUND
                msg = "DLL not found"
            Case SE_ERR_SHARE
                msg = "A sharing violation occurred"
            Case SE_ERR_ASSOCINCOMPLETE
                msg = "Incomplete or invalid file association"
            Case SE_ERR_DDETIMEOUT
                msg = "DDE Time out"
            Case SE_ERR_DDEFAIL
                msg = "DDE transaction failed"
            Case SE_ERR_DDEBUSY
                msg = "DDE busy"
            Case SE_ERR_NOASSOC
                msg = "No association for file extension"
            Case ERROR_BAD_FORMAT
                msg = "Invalid EXE file or error in EXE image"
            Case Else
                msg = "Unknown error"
        End Select
        MsgBox msg
    End If
End Sub

Private Sub Command1_Click()
    'Run the associated file
    RunDoc "c:\windows\desktop\back street boys.mp3"
End Sub
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2662038
And to open Winamp minimized use:
Const SW_SHOWMINIMIZED = 2

instead of SW_SHOWNORMAL
0
 
LVL 1

Author Comment

by:BETTY
ID: 2675498
Boys, boys, don't fight!...

First correct answer is mcrider's one, so it's only fair he should get the 50 points.

However, wsh2's one applies to a more general problem and allows to run a registered file no matter where the associated program is, so I've learned from his response.

And Erick37's one is another way of doing this.

So I've decided to give an aditional prize for your effort, wsh2 and erick37. Please answer my question "Parameters (for wsh2)" or "Parameters (for Erick37)" and you will have 50 extra points each...

Please leave here your comments to my suggestion before I post these restricted questions.
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2677472
Betty,

Thanks for the points! Glad I could help!

By the way, there was no *real* fighting here... wsh2 is a friend!  In case you missed it, the comments above included: LOL, <VBG>, <tongue out> and <ROTFLMAO>.

Any time you see someone making a comment in <> marks, it's a *virual* action, and you should imagine that person performing the action. As for the contents:

   <LOL> = Laughing Out Loud
   <VBG> = Very Big Grin
   <ROTFLMAO> = Rolling On The Floor Laughing My A** Off

If you want to post a question for wsh2 and Erick37, that would be cool...  I suggest the title of the questions be "FOR WSH2 ONLY" and "FOR ERIC37 ONLY".  Don't forget to mention this question in the new questions...


Cheers!®©


0
 
LVL 1

Author Comment

by:BETTY
ID: 2679492
Aha!
I am so grateful for this explanation as for the answer itself.

Let me explain: I'm from Spain, ECC, and as you see I can write and undestand a basic Englih, but most of us (Spanish) don't know these abbreviations and set phrases.

And worst of all, most English-speaking people don't think about other language-speaking people. Lately, I've even seen English people that look at Spanish as a shadow for the preeminence of English. That's why I thank you for the explanation... by the way very curious meanings ;-)

Finally, I will not post a restricted question for wsh2 and Erick37 until they confirm me they agree because I don't want to have 100 points blocked a long time. But thanks for the suggestions.

Greetings from Barcelona, in the sunny Spain!!
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2679720
From the English you have written so far, who would have ever guessed that you are from Spain?.. You write VERY well Betty.. <smile>.

As to agreeing, I certainly do, and I think you will find that Erick37 does also. Thank YOU.. <smile>.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

744 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

15 Experts available now in Live!

Get 1:1 Help Now