Link to home
Start Free TrialLog in
Avatar of adam8
adam8

asked on

File extensions

How could i associate mp3 files with my application, so when someone clicks on an mp3 file it runs my application and plays the sound automatcally.
ASKER CERTIFIED SOLUTION
Avatar of Erick37
Erick37
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of adam8
adam8

ASKER

Could you please tell me how to read the info using the Command() function
Avatar of adam8

ASKER

Could you please tell me how to read the info using the Command() function
Option Explicit

'This example uses the Command function to get the
'command line arguments in a function that returns
'them in a Variant containing an array.
'Taken from VB Books Online
Function GetCommandLine(Optional MaxArgs)
    'Declare variables.
    Dim C, CmdLine, CmdLnLen, InArg, I, NumArgs
    'See if MaxArgs was provided.
    If IsMissing(MaxArgs) Then MaxArgs = 10
    'Make array of the correct size.
    ReDim ArgArray(MaxArgs)
    NumArgs = 0: InArg = False
    'Get command line arguments.
    CmdLine = Command()
    CmdLnLen = Len(CmdLine)
    'Go thru command line one character
    'at a time.
    For I = 1 To CmdLnLen
        C = Mid(CmdLine, I, 1)
        'Test for space or tab.
        If (C <> " " And C <> vbTab) Then
            'Neither space nor tab.
            'Test if already in argument.
            If Not InArg Then
            'New argument begins.
            'Test for too many arguments.
                If NumArgs = MaxArgs Then Exit For
                NumArgs = NumArgs + 1
                InArg = True
            End If
            'Concatenate character to current argument.
            ArgArray(NumArgs) = ArgArray(NumArgs) & C
        Else
            'Found a space or tab.
            'Set InArg flag to False.
            InArg = False
        End If
    Next I
    'Resize array just enough to hold arguments.
    ReDim Preserve ArgArray(NumArgs)
    'Return Array in Function name.
    GetCommandLine = ArgArray()
End Function

'Usage: Retrieve the first command line arg.
'If the program was started from an associated file,
'This will be the (first) filename.
'Program must be compiled into an exe to receive command line args
Private Sub Form_Load()
    Show
    Dim vCmdLine
    vCmdLine = GetCommandLine
    'Get only the first arg
    MsgBox vCmdLine(1)
End Sub
You should do some checking on the command line arg to check for a valid mp3 file extension:

Private sFilename As String

Private Sub Form_Load()
    Show
    Dim vCmdLine
    vCmdLine = GetCommandLine
    'Get only the first arg
    'See if command line exists
    If Not (vCmdLine(1) = vbNullString) Then
        'It exists
        sFilename = vCmdLine(1)
        'Check the file extension is .mp3
        If sFilename Like "*.[Mm][Pp]3" Then
            'valid filename extension (.mp3)
            MsgBox sFilename
        End If
    End If
End Sub
Oops, bug fix:
In form_Load, change
If Not (vCmdLine(1) = vbNullString) Then
to
If UBound(vCmdLine) > 0 Then
Avatar of adam8

ASKER

Thanks a lot for the help,
i appreciate it very much.