Solved

Open cdrom Door and Close with visual basic

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now