By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,096 Members | 1,264 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,096 IT Pros & Developers. It's quick & easy.

"method or data member not found" using Toolbar button

P: 23
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.

Expand|Select|Wrap|Line Numbers
  1. select case button.key
  2. case "btn1"
  3.        msgbox ""
  4. case "btn2"
  5.       msgbox ""
  6. end
  7. end select
Can anybody help me in figuring out this problem

Thanks
Mar 27 '07 #1
Share this Question
Share on Google+
22 Replies


SammyB
Expert 100+
P: 807
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?
Mar 27 '07 #2

P: 23
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.
Mar 27 '07 #3

SammyB
Expert 100+
P: 807
>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
Expand|Select|Wrap|Line Numbers
  1.         Select Case button
  2.             Case 1
  3.                 MsgBox("First")
  4.             Case 2
  5.                 MsgBox("Second")
  6.             Case Else
  7.                 MsgBox("Something else")
  8.         End Select
Mar 27 '07 #4

P: 23
I am using vb6.0 version. I tried by removing ".key" as you told. This is not showing anything.
Mar 27 '07 #5

SammyB
Expert 100+
P: 807
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:
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
  3.     Select Case Button.Key
  4.         Case "btn1"
  5.             MsgBox "First"
  6.         Case "btn2"
  7.             MsgBox "Second"
  8.     End Select
  9. End Sub
Mar 27 '07 #6

P: 23
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.
Mar 27 '07 #7

SammyB
Expert 100+
P: 807
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.Button. Does your code look exactly like mine?
Mar 27 '07 #8

P: 23
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)
Mar 27 '07 #9

SammyB
Expert 100+
P: 807
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
Expand|Select|Wrap|Line Numbers
  1. Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
  2.     Select Case Button.Key
  3.         Case "btn1"
  4.             MsgBox "First"
  5.         Case "btn2"
  6.             MsgBox "Second"
  7.     End Select
  8. End Sub
Now, press the Start button and see if the buttons work.
Mar 27 '07 #10

P: 3
I could be wrong, but I think that the Member .key has to belong to the class Button... Hope this helps, Roger
Mar 27 '07 #11

P: 23
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 !!!!
Mar 27 '07 #12

P: 23
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.
Mar 27 '07 #13

SammyB
Expert 100+
P: 807
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
Mar 27 '07 #14

P: 23
How do I check whether all the required members of button are present in my project ??
Mar 27 '07 #15

SammyB
Expert 100+
P: 807
How do I check whether all the required members of button are present in my project ??
:confused: Since you are using a non-standard toolbar, we have no way of knowing. Please do what my last post said.
Mar 27 '07 #16

P: 23
Thank you for your help.That is the reason. But how can I include the members to the button ?
Mar 27 '07 #17

P: 23
I looked for the methods of button object in Object Browser, then compared with other system's Button Object. So I found that my system has no methods for button object. Is it possible to add the methods to my system too ? Can you please check it
Thank you very much for your help
Mar 27 '07 #18

P: 3
I think in object oriented programming such as Visual Basic .Net you can add your own custom methods to the Button Class. That is all I remember... Roger
Mar 27 '07 #19

Expert 5K+
P: 8,434
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.

Expand|Select|Wrap|Line Numbers
  1. select case button.key
  2. case "btn1"
  3.        msgbox ""
  4. case "btn2"
  5.       msgbox ""
  6. end
  7. end select
Can anybody help me in figuring out this problem
Sorry, I haven't followed the rest of the thread yet (short of time) but if you have defined button as anything, that is probably your problem. If this is the type of toolbar I'm familiar with, Button should represent the parameter (ByVal Button As MSComctlLib.Button) which is received when this event procedure is called.
Mar 28 '07 #20

Expert 5K+
P: 8,434
Oops! Looks as though I spoke too soon.

Are you sure you don't have some custom object you're created (or a form or whatever) called "Button"?

Here's an exercise which might (or might not) help. Change the name of the parameter to something which you know won't match anything else. For example...
Expand|Select|Wrap|Line Numbers
  1. Private Sub Toolbar1_ButtonClick(ByVal KillerSaidToDoThis As MSComctlLib.Button)
  2.    Debug.Print KillerSaidToDoThis.Index, KillerSaidToDoThis.Caption, _
  3.                KillerSaidToDoThis.Key
  4. End Sub
Mar 28 '07 #21

kenobewan
Expert 2.5K+
P: 4,871
I believe that we are reaching the end of how much help we can provide here. Clear step by step instructions have been given.

We all started somewhere and there is no shame in being a newbie. My suggestion is find a book or course and learn the basics. This is a site for programmers and not geared to learning the basics - it is assumed by the experts that you have this.

So please learn the fundamentals, it will save you time in the log run. I am sure we could suggest some resources if you like. Thanks.
Mar 28 '07 #22

Expert 5K+
P: 8,434
I looked for the methods of button object in Object Browser, then compared with other system's Button Object. So I found that my system has no methods for button object.
When you select Button in the object browser, what does it show in the grey window down the bottom?

(Note, I've updated the title of the thread - "Hi All" won't help anyone in the future who needs to search for help on this topic).
Mar 28 '07 #23

Post your reply

Sign in to post your reply or Sign up for a free account.