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.
LVL 1
adam8Asked:
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.

Erick37Commented:
First step:

"Creating a Visual Basic File Association"
http://www.mvps.org/vbnet/code/reg/association.htm

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.
0

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
0
adam8Author Commented:
Could you please tell me how to read the info using the Command() function
0
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!

Erick37Commented:
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
0
Erick37Commented:
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
0
Erick37Commented:
Oops, bug fix:
In form_Load, change
If Not (vCmdLine(1) = vbNullString) Then
to
If UBound(vCmdLine) > 0 Then
0
adam8Author Commented:
Thanks a lot for the help,
i appreciate it very much.
0
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.