Solved

Open cdrom Door and Close with visual basic

Posted on 1998-06-02
5
550 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 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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 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
Course of the Month8 days, 10 hours left to enroll

615 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