Solved

Open cdrom Door and Close with visual basic

Posted on 1998-06-02
5
544 Views
Last Modified: 2013-11-25
How i can open and close the Cdrom Door and Close it with visual basic?
0
Comment
Question by:latin_man
  • 3
5 Comments
 
LVL 4

Expert Comment

by:zsi
ID: 1462319
If you are using the MCI OCX, you can invoke the Command method with the "Eject" command

MCI1.Command = "Eject"


0
 
LVL 4

Expert Comment

by:yowkee
ID: 1462320
To open and close CD-Drive door through Visual Basic:

--
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, _
ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hWndCallback As Long) As Long

Function vbmciSendString(ByVal Command As String, ByVal hWnd As Long) As String
    Dim Buffer As String
    Dim dwRet As Long

    Buffer = Space$(100) ' Create a buffer
    dwRet = mciSendString(Command, ByVal Buffer, Len(Buffer), hWnd)
    vbmciSendString = Buffer
End Function

Private Sub cmdOpen_Click()
  ' Pass 0 or Me.hWnd to 2nd parameter
  Call vbmciSendString("set cdaudio door open", 0)
End Sub

Private Sub cmdClose_Click()
  Call vbmciSendString("set cdaudio door closed", 0)
End Sub
--

Regards.

0
 

Author Comment

by:latin_man
ID: 1462321
if you can tell me a sample and i only want one button to open and that the cddoor can open without a cd in the cdrom
0
 
LVL 4

Expert Comment

by:yowkee
ID: 1462322
latin_man,

  Did my comment suit your requirement? The code:
  Call vbmciSendString("set cdaudio door open", 0)
is to open the cd door (no matter with or without cd inside).
0
 
LVL 4

Accepted Solution

by:
yowkee earned 50 total points
ID: 1462323
latin_man,

  Now I propose my answer to open and close using one button. If you only want one button to open cd door with or without a cd in the cdrom, please look at my previous comment.

--
Dim bOpen As Boolean

Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA"
(ByVal lpstrCommand As String, _
ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal
hWndCallback As Long) As Long

Function vbmciSendString(ByVal Command As String, ByVal hWnd As Long) As
String
    Dim Buffer As String
    Dim dwRet As Long
    Buffer = Space$(100) ' Create a buffer
    dwRet = mciSendString(Command, ByVal Buffer, Len(Buffer), hWnd)
    vbmciSendString = Buffer
End Function

Private Sub Command1_Click()
  If bOpen Then  
      Call vbmciSendString("set cdaudio door closed", 0)
  Else
      Call vbmciSendString("set cdaudio door open", 0)
  End If
  bOpen = Not bOpen
End Sub
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question