Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 387
0 Users 5 Guests Online

Open And Close CD Tray

Note: I use Visual Basic Enterprise 6 for this tutorial.

Hey there! this is just a simple visual basic tutorial for those of you who have problems with opening and closing your CD tray.

Common Uses:
1. too lazy to bend over and open it yourself.
2. its stuck for an unknown reason.

First off open up your Visual Basic program

and create a new Standard EXE

TutorialNinja Image

After doing so you will want to grab the Command Button tool and on the form draw a random button.

Off to the side in the Properties menu select the box to the right of (name) and rename it cmdOpen. Then in the box to the right of Caption replace it with Open Tray!

Or you can use this image to help you!

TutorialNinja Image

You will want to do that again but instead of Open Tray and cmdOpen you will want to use Close Tray and cmdClose.

You an also add another command button and name it cmdPClose with the caption of Close Program.

Now what you want to do is double click on the cmdOpen command button use the following code

Code

mciSendString "set cdaudio door open", 0, 0, 0 'Open the CD Tray
MsgBox "Tray Opened!" 'say the cd tray was opened


So far the code that the code window should show is:
Code

Private Sub cmdOpen_Click()
mciSendString "set cdaudio door open", 0, 0, 0 'Open the CD Tray
MsgBox "Tray Opened!" 'say the cd tray was opened
End Sub


Next, double click the Close Tray button and add:
Code

mciSendString "set cdaudio door closed", 0, 0, 0 'Close Tray
msgbox "Tray Closed!"


With that done theres really only 1 thing to do which is the cmdPClose command button.

With that, double click Close Program button and add:

Code

Me.Hide 'Close the program
MsgBox "Goo Bye!" 'Good bye ^^


That should be it But before you go to compile you will want to add one last code to the top of the document that will make this program work for real which is:

Code

Option Explicit
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


That should go above ALL OTHER CODING or you may get an error.

When thats done feel free to add graphics or other random things then click F5 to test.

There is a download in the downloads section of the website with a preview of this :)

Hope you learned something!
ShadowMage
Author:
Views:
2928
Rating:
Posted on Wednesday 20th August 2008 at 01:57 PM
cyruswu
cyruswu
Ahh man! I wish I learn't Visual Basic.
Posted on Tuesday 19th August 2008 at 06:36 PM
ritchielee666
ritchielee666
This was a brilliant tuturial!
VB 9.0 (2008) Wouldn't have it, but i fixed that!
Posted on Tuesday 19th August 2008 at 03:55 PM
ritchielee666
ritchielee666
pretty handy, mine never opens when i press the button!
Posted on Thursday 27th December 2007 at 01:36 PM
Dalez
Dalez
Thanks, this has worked fine!
Posted on Sunday 6th May 2007 at 10:12 PM
ShadowMage
ShadowMage
Lol MSN has a script with that name :P
Posted on Sunday 6th May 2007 at 09:36 PM
DanielXP
DanielXP
CUP HOLDER!
Posted on Sunday 6th May 2007 at 09:27 PM
ShadowMage
ShadowMage
lol no prob :) theres a download in the Other category
Posted on Sunday 6th May 2007 at 09:10 PM
Diablosblizz
Diablosblizz
Haha this is a VERY lazy way of opening the CD Drive! I like it! Ty!