?
Solved

Open cdrom Door and Close with visual basic

Posted on 1998-06-02
5
Medium Priority
?
553 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 100 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Suggested Courses

719 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