Monday 2 January 2012

How to open and close the CD tray

hi again, now im going to teach you how to open and close a CD tray, there are some problems in it though but if you create an .exe (build it) and run it works fine.
so first you have to declare the function
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
after that you would want the script to open or close the CD tray, i think the best sub to put it in would be when a button is pressed.
'to open the CD drive
 mciSendString("Set CDAudio Door Open Wait", 0&, 0&, 0&)

'to close the CD drive
  mciSendString("Set CDAudio Door Closed Wait", 0&, 0&, 0&)

this is simply saying open/close the CD drive

hope it helps (with what ever you would use this for)

Download this project
Add program to startup

The following code can add you executable to startup so that when ever the user turn there computer on the program will load up.

Try


Dim appname As String = IO.Path.GetFileName(Application.ExecutablePath)

Dim vDirectory As String

vDirectory = "C:\Documents and Settings\All Users\Start Menu\Programs\Startup\"

Dim zDir As New DirectoryInfo(vDirectory)

If Not zDir.Exists Then

My.Computer.FileSystem.CopyFile(Application.ExecutablePath, "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\" & appname, True)

Else

My.Computer.FileSystem.CopyFile(Application.ExecutablePath, "C:\Documents and Settings\All Users\Start Menu\Programs\Startup\" & appname, True)

End If



Catch ex As Exception



End Try
Beginner game tutorial

i have been programming for a while now and people ask me, how do i make things move with the arrow keys? well here you go!
Private Sub fm_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyData = Keys.Up Then
'if the up arrow key is pressed
'what you want to happen
end if
End Sub

as you can see, the code for the arrow key is in the form-keydown. this will not work any other way. e.keydata works with most keys on the keyboard. it is saying simply, if this key is pressed then...

Another thing that people ask me is, how do i write an if touching code?
and here it is!
If object1.Bounds.IntersectsWith(object2.Bounds) Then
'what you want to happen
end if
 this one does not have to be in a certain sub but i find that the best one to be in is a timer on a very small interval because it will check every to the timer goes round. this is also simply saying, if the bounds of object1 is touching object2s bounds then...

i have sent an attachment so you could see it examples of how these could be used.

hope this has been helpful