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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

First step:

"Creating a Visual Basic File Association"

Once this is done, your program is passed the filename of the associated file as a command line argument.  You can read this info using the Command() function when your program starts.

Hope it helps.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
adam8Author Commented:
Could you please tell me how to read the info using the Command() function
adam8Author Commented:
Could you please tell me how to read the info using the Command() function
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

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
            '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()
    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()
    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
If UBound(vCmdLine) > 0 Then
adam8Author Commented:
Thanks a lot for the help,
i appreciate it very much.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.