MCI (function)

Syntax Mci (command$,result$ [,error$])
Description Executes an Mci command, returning an Integer indicating whether the command was successful.
Comments The Mci function takes the following parameters:
Parameter Description
command$ String containing the command to be executed.
result$ String variable into which the result is placed. If the command doesn't return anything, then a zero-length string is returned. To ignore the returned string, pass a zero-length string, such as. r% = Mci("open chimes.wav type waveaudio","")
error$ Optional String variable into which an error string will be placed. A zero-length string will be returned if the function is successful.
Example 1 This first example plays a wave file. The wave file is played to completion before execution can continue.
Sub Main()
  Dim result As String
  Dim ErrorMessage As String
  Dim Filename As String
  Dim rc As Integer
  'Establish name of file in the Windows directory.
  Filename = FileParse$(System.WindowsDirectory$ + "\" + "chimes.wav")
  'Open the file and driver.
  rc = Mci("open " & Filename & " type waveaudio alias CoolSound","",ErrorMessage)
  If (rc) Then
    'Error occurred--display error message to user.
    MsgBox ErrorMessage
    Exit Sub
  End If
  rc = Mci("play CoolSound wait","","")  'Wait for sound to finish.
  rc = Mci("close CoolSound","","")   'Close driver and file.
End Sub
Example 2 This next example shows how to query an Mci device and play an MIDI file in the background.
Sub Main()
  Dim result As String
  Dim ErrMsg As String
  Dim Filename As String
  Dim rc As Integer
  'Check to see whether MIDI device can play for us.
  rc = Mci("capability sequencer can play",result,ErrorMessage)
  'Check for error.
  If rc Then
    MsgBox ErrorMessage
    Exit Sub
  End If
  'Can it play?
  If result <> "true" Then
    MsgBox "MIDI device is not capable of playing."
    Exit Sub
  End If
  'Assemble a filename from the Windows directory.
  Filename = FileParse$(System.WindowsDirectory$ & "\" & "canyon.mid")
 
  'Open the driver and file.
  rc = Mci("open " & Filename & " type sequencer alias song",result$,ErrMsg)
  If rc Then
    MsgBox ErrMsg
    xit Sub
  End If
  rc = Mci("play song","","")  'Play in the background.
  MsgBox "Press OK to stop the music.",ebOKOnly
  rc = Mci("close song","","")
End Sub
See Also Beep (statement)