[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

Parameters sending problem

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
BETTY
Asked:
BETTY
  • 5
  • 4
  • 2
  • +1
1 Solution
 
wsh2Commented:
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
 
mcriderCommented:
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
 
mcriderCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
wsh2Commented:
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
 
wsh2Commented:
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
 
wsh2Commented:
mcrider:
Look at our time stamps both "Date: Monday, March 27 2000 - 02:01PM"..  
nananananananannana.. <tongue out>.. beat ya.. LOL

0
 
mcriderCommented:
<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
 
Erick37Commented:
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
 
Erick37Commented:
And to open Winamp minimized use:
Const SW_SHOWMINIMIZED = 2

instead of SW_SHOWNORMAL
0
 
BETTYAuthor Commented:
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
 
mcriderCommented:
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
 
BETTYAuthor Commented:
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
 
wsh2Commented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 5
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now