Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Open cdrom Door and Close with visual basic

Posted on 1998-06-02
5
Medium Priority
?
554 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 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

963 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