"method or data member not found" using Toolbar button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kkk1979
    New Member
    • Mar 2007
    • 23

    "method or data member not found" using Toolbar button

    I am not an experienced programmer. I am getting an error as "method or data member not found" when i entered the following code in buttonclick procedure of the toolbar.

    Code:
    select case button.key
    case "btn1"
           msgbox ""
    case "btn2"
          msgbox ""
    end
    end select
    Can anybody help me in figuring out this problem

    Thanks
    Last edited by Killer42; Mar 28 '07, 01:39 AM. Reason: Please use [CODE]...[/CODE] tags around your code
  • SammyB
    Recognized Expert Contributor
    • Mar 2007
    • 807

    #2
    Originally posted by kkk1979
    I am not an experienced programmer. I am getting an error as "method or data member not found" when i entered the following code in buttonclick procedure of the toolbar.

    select case button.key
    case "btn1"
    msgbox ""
    case "btn2"
    msgbox ""
    end
    end select

    Can anybody help me in figuring out this problem

    Thanks
    Kay, your Case statement is not setup correctly: remove the line "end". Also, I think that it does not like button.key. What did you Dim button as? What version of VB are you using: VBA, VB6, or VB.NET?

    Comment

    • kkk1979
      New Member
      • Mar 2007
      • 23

      #3
      Originally posted by SammyB
      Kay, your Case statement is not setup correctly: remove the line "end". Also, I think that it does not like button.key. What did you Dim button as? What version of VB are you using: VBA, VB6, or VB.NET?
      I declared button as Integer, also I removed the end statement. Still I am getting the same error. I am using vb98.

      Comment

      • SammyB
        Recognized Expert Contributor
        • Mar 2007
        • 807

        #4
        >I removed the end statement
        Great!

        >I am using vb98
        Why? We can give you general ideas, but I and most others have never seen vb98

        >I declared button as Integer
        then you cannot have button.key
        so what does button equal at the top of your code. Can't you just do
        Code:
        		Select Case button
        			Case 1
        				MsgBox("First")
        			Case 2
        				MsgBox("Second")
        			Case Else
        				MsgBox("Something else")
        		End Select

        Comment

        • kkk1979
          New Member
          • Mar 2007
          • 23

          #5
          I am using vb6.0 version. I tried by removing ".key" as you told. This is not showing anything.

          Comment

          • SammyB
            Recognized Expert Contributor
            • Mar 2007
            • 807

            #6
            Originally posted by kkk1979
            I am using vb6.0 version. I tried by removing ".key" as you told. This is not showing anything.
            Ah, VB6, where is the wipes off the sweat smilie.
            You are correct, it should be Button.Key. So,
            1. Make sure that you added buttons to the ToolBar
            2. Make sure that you entered the keys for the buttons: btn1, btn2
            Now, you event routine should look like:
            Code:
            Option Explicit
            Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
            	Select Case Button.Key
            		Case "btn1"
            			MsgBox "First"
            		Case "btn2"
            			MsgBox "Second"
            	End Select
            End Sub

            Comment

            • kkk1979
              New Member
              • Mar 2007
              • 23

              #7
              I have been trying this from yesterday. I kept the .key as btn1 and btn2 correctly.
              getting the same compilation error by highlighting ".key" method in blue color.
              I am sorry to tell like this.

              Comment

              • SammyB
                Recognized Expert Contributor
                • Mar 2007
                • 807

                #8
                Originally posted by kkk1979
                I have been trying this from yesterday. I kept the .key as btn1 and btn2 correctly.
                getting the same compilation error by highlighting ".key" method in blue color.
                I am sorry to tell like this.
                Don't be sorry, this is why we get the big bucks! ;) In #3, you said "I declared button as Integer". VB defines it as MSComctlLib.But ton. Does your code look exactly like mine?

                Comment

                • kkk1979
                  New Member
                  • Mar 2007
                  • 23

                  #9
                  Yes, have been trying the code which is exactly like yours. But as you asked me about the declaration, then I thought "ok, I need to declare" like that.
                  So I tried both ways. I think my code doesn't like .key method.(but why I don't know)

                  Comment

                  • SammyB
                    Recognized Expert Contributor
                    • Mar 2007
                    • 807

                    #10
                    Originally posted by kkk1979
                    Yes, have been trying the code which is exactly like yours. But as you asked me about the declaration, then I thought "ok, I need to declare" like that.
                    So I tried both ways. I think my code doesn't like .key method.(but why I don't know)
                    I would suggest that you start all over again, slowly. Follow these steps:
                    1. Get out of all windows but this one and start VB6 from the Start button
                    2. In the New Project dialog, select Standard EXE and press Open
                    3. If you don't have a Toolbar control in the toolbox, press Ctrl T and place a checkmark before Microsoft Windows Common Controls 6.0
                    4. Double-click the toolbar icon in the toolbox to add it to your form
                    5. Click on Custom in the Properties window and press the elipses button.
                    6. Click on the Buttons tab and click Insert Button.
                    7. Make the caption 1 and the key btn1
                    8. Click Insert Button again
                    9. Make the caption 2 and the key btn2 and press OK
                    10. Double-click on the toolbar to bring up the code window
                    11. Add code to the Click event
                    Code:
                    Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
                    	Select Case Button.Key
                    		Case "btn1"
                    			MsgBox "First"
                    		Case "btn2"
                    			MsgBox "Second"
                    	End Select
                    End Sub
                    Now, press the Start button and see if the buttons work.

                    Comment

                    • rowen33
                      New Member
                      • Mar 2007
                      • 3

                      #11
                      I could be wrong, but I think that the Member .key has to belong to the class Button... Hope this helps, Roger

                      Comment

                      • kkk1979
                        New Member
                        • Mar 2007
                        • 23

                        #12
                        I followed the steps,got the same error.But when i double clicked the toolbar from the toolbox(as in step 4), I got toolbar wizard along with toolbar.Does this makes any difference ?? Waiting for your reply !!!!

                        Comment

                        • kkk1979
                          New Member
                          • Mar 2007
                          • 23

                          #13
                          That might be the reason, How do I check that ?
                          I opened Object Browser, selected "button" option in left pane, nothing is shown in the right pane.
                          If that is your guess, can you please show how to include the ".key" method to my project.

                          Comment

                          • SammyB
                            Recognized Expert Contributor
                            • Mar 2007
                            • 807

                            #14
                            Originally posted by kkk1979
                            I followed the steps,got the same error.But when i double clicked the toolbar from the toolbox(as in step 4), I got toolbar wizard along with toolbar.Does this makes any difference ?? Waiting for your reply !!!!
                            What is a toolbar wizard? We are not using the same VB6. Remove your toolbar and press Ctrl T to open the Components dialog. Uncheck everything on the Controls tab and press OK. Now, press Ctrl T again and place a checkmark before Microsoft Windows Common Controls 6.0.

                            Now, try adding the Toolbar again. If you get a wizard, some other VB6 guru will have to help you because I don't do wizards, daemons, or databases. :D Hope this solves it! --Sam

                            Comment

                            • kkk1979
                              New Member
                              • Mar 2007
                              • 23

                              #15
                              How do I check whether all the required members of button are present in my project ??

                              Comment

                              Working...