Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Creating dynamic handlers

Posted on 2010-08-29
4
Medium Priority
?
422 Views
Last Modified: 2012-05-10
Hey there. I'm attempting to call a user defined function (callbyname) on a dynamically created button using add handler.

AddHandler button.Click, AddressOf CallByName(form, "function_name", CallType.Method)

Open in new window


unfortunatly i keep getting this error:
'AddressOf' operand must be the name of a method (without parentheses)

Any help would be great :)

Many Thanks
Ben
0
Comment
Question by:lazypeople
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 48

Assisted Solution

by:Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs) earned 200 total points
ID: 33552946
The routine you use in AddHandler *must* have the same signature as the event. So for a button's Click event, the routine will need to have an Object (sender) and EventArgs (e), like this....

    AddHandler button.Click, AddressOf Button_Click

...where the Button_Click routine looks like this....

    Public Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)
        'your code
    End Sub

Wayne
0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 800 total points
ID: 33552975
Hi Ben;

Try it like this.

' Create the Button
Dim dButton As New Button()
dButton.Name = "DynamicButton"
dButton.Text = "DynamicButton"
dButton.Location = New Point(10, 10)
'...
'Assign the Click event to an event handler
AddHandler dButton.Click, AddressOf DynamicButton_Click
' Add Button to the forms collection
Me.Controls.Add(dButton)




Private Sub DynamicButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    ' Call the function to CallByName here in the event handler
    ' CallByName(form, "function_name", CallType.Method)

End Sub

Fernando
0
 
LVL 3

Author Closing Comment

by:lazypeople
ID: 33553230
Thanks :)
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 33553245
Not a problem, glad I was able to help.  ;=)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

593 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question