procedure declaration does not match description of event or procedure having the same name

匿名 (未验证) 提交于 2019-12-03 03:06:01

问题:

I am just novice and I tried to make a simple program in Visual Basic 6. The code is almost equivalent to that in the textbook. It was meant to be a kind of a paint program. Surprisingly, it couldn't be compiled with the error given in the title of this question. This is the code:

Option Explicit  Dim Col As Long  Private Sub Form_Load()     AutoRedraw = True     BackColor = vbWhite     Col = vbBlack     DrawWidth = 3 End Sub  Private Sub Command1_Click()     CommonDialog1.ShowOpen     Form1.Picture = LoadPicture(CommonDialog1.FileName) End Sub  Private Sub Command2_Click()     CommonDialog1.ShowSave     SavePicture Image, CommonDialog1.FileName End Sub  Private Sub Command3_Click()     CommonDialog1.ShowColor     Col = CommonDialog1.Color End Sub  Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)     PSet (X, Y), Col End Sub  Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)     Select Case Button.Key     Case "Line1"         DrawWidth = 3     Case "Line2"         DrawWidth = 20     End Select End Sub 

The application crashes on the following line:

Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button) 

With the error:

procedure declaration does not match description of event or procedure having the same name

回答1:

The problem is here:

Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button) 

Ok, since you are coding in VB6, you get to learn some of the tricks in the VB6 playbook. Temporarily rename the method to something else like qqToolbar_ButtonClick, then go to the designer and click the button in the toolbar to regenerate the event in the code.

In the event that the signature has been mistyped, it will regenerate from the designer correctly and you might see the issue.

Another check is to see if the ToolBar1 was added to a control array? In that case, the method signature needs to look like this:

Private Sub Toolbar1_ButtonClick(ByVal Index as Integer, ByVal Button As MSComctlLib.Button) 

I hope one of these helps solve the issue for you.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!