CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: little confused

  1. #1
    Join Date
    Dec 2008
    Posts
    27

    little confused

    OK i have wrote code that is supposed to open and close CD tray the code works but when i tried to make the code all i one button that's where i got confused. here's the code
    Code:
    Public Class Form1
        Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
       (ByVal lpCommandString As String, ByVal lpReturnString As String, _
       ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim retval As Long
            If retval = mciSendString("set CDAudio door open", "", 0, 0) Then
    
            Else : retval = mciSendString("set CDAudio door closed", "", 0, 0)
    
            End If
        End Sub
    
    End Class
    basically what i wanted to do was make one button open it then when clicked to would close but i also wanted the text on the button to change along with it. so when clicked the first time the button would say open then when clicked again it would say close. any idea how i could do this? thanks in advance for any help.

  2. #2
    Join Date
    Oct 2006
    Posts
    327

    Re: little confused

    Hello,

    Make a "switch" :

    set the caption of your button to "open" at the beginning;
    Then ;

    Code:
    Private Sub Command1_Click()
      If Command1.Caption = "open" Then Command1.Caption = "closed" Else Command1.Caption = "open"
    End Sub
    and then refer to the caption, that way :

    mciSendString("set CDAudio door" & command1.caption ......

    Now : this is the principle and it would work like that with VB6

    You will have to transpose it to VB.Net (you are on the wrong section)

    EDIT : something else about your post there :
    http://www.codeguru.com/forum/showthread.php?t=491519
    If your tool is VB.Net, you will have to transform it too (as every Long is an Integer under VB.nat)
    Last edited by moa; January 26th, 2010 at 10:48 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured