Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,444 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,284 people online right now. Registration is fast and FREE... Join Now!




What is wrong with this code?

 
Reply to this topicStart new topic

What is wrong with this code?

doomlord52
6 Dec, 2007 - 06:33 PM
Post #1

New D.I.C Head
*

Joined: 5 Dec, 2007
Posts: 1


My Contributions
CODE
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
Private Sub CommandButton1_Click()
Dim Iret As Long
Iret = mciSendString("Set CDAudio door open", ReturnString, 127, 0)
End Sub
Private Sub CommandButton2_Click()
Dim Iret As Long
Iret = mciSendString("Set CDAudio door closed", ReturnString, 127, 0)
End Sub


What is wrong with the code!!!
(It is the code to open CD drive, and close it.
User is offlineProfile CardPM
+Quote Post

Nayana
RE: What Is Wrong With This Code?
6 Dec, 2007 - 10:19 PM
Post #2

DIC Hawk - 나야나 नयन:
Group Icon

Joined: 14 Nov, 2007
Posts: 824



Thanked: 5 times
Dream Kudos: 175
My Contributions
There's nothing functionally wrong with the code. I copied it straight into a
VB6 project, made two buttons called CommandButton1 and CommandButton2 and clicking on the 1st one made my CD drive open.

It can't close it because I have a laptop.

Is there anything special about your computer? Are there any programs on it which can open/close the CD drive?
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: What Is Wrong With This Code?
9 Dec, 2007 - 05:11 AM
Post #3

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 3,906



Thanked: 34 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
The code worked on my laptop too.
Sometimes, a buffer has to be allocated for certain functions to work.
Try using this function and see if it works for you.

CODE

Function CDcommand(ByVal Command As String, ByVal hWnd As Long) As String
    Dim Buff As String
    Dim dwR As Long
    Buff = Space$(100) ' Create a buffer
    dwR = mciSendString(Command, ByVal Buff, Len(Buff), hWnd)
    CDcommand = Buff
End Function

Call the function like this:
CODE
Dim ret as String
ret = CDcommand("set cdaudio door open", 0)
ret = CDcommand("set cdaudio door closed", 0)

User is offlineProfile CardPM
+Quote Post

lzaero
RE: What Is Wrong With This Code?
19 Dec, 2007 - 04:09 AM
Post #4

New D.I.C Head
*

Joined: 13 Sep, 2007
Posts: 28


My Contributions
i also been try that your code here As what i observed there's nothing wrong with your code...but when i pressing the buttonopen again and again i might observe an error like this Attached Image
User is offlineProfile CardPM
+Quote Post

LookNAO
RE: What Is Wrong With This Code?
28 Dec, 2007 - 11:50 AM
Post #5

D.I.C Head
**

Joined: 28 Dec, 2007
Posts: 66



Thanked: 1 times
My Contributions
QUOTE(doomlord52 @ 6 Dec, 2007 - 07:33 PM) *

CODE
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
Private Sub CommandButton1_Click()
Dim Iret As Long
Iret = mciSendString("Set CDAudio door open", ReturnString, 127, 0)
End Sub
Private Sub CommandButton2_Click()
Dim Iret As Long
Iret = mciSendString("Set CDAudio door closed", ReturnString, 127, 0)
End Sub


What is wrong with the code!!!
(It is the code to open CD drive, and close it.


Const ReturnString = 13


QUOTE(doomlord52 @ 6 Dec, 2007 - 07:33 PM) *

CODE
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
Private Sub CommandButton1_Click()
Dim Iret As Long
Iret = mciSendString("Set CDAudio door open", ReturnString, 127, 0)
End Sub
Private Sub CommandButton2_Click()
Dim Iret As Long
Iret = mciSendString("Set CDAudio door closed", ReturnString, 127, 0)
End Sub


What is wrong with the code!!!
(It is the code to open CD drive, and close it.



Or try:
Dim ReturnString as String
ReturnString = chr$(13)


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 02:18PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month