Results 1 to 6 of 6

Thread: How to include a function call as a parameter in another function?

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    3

    How to include a function call as a parameter in another function?

    For example:
    VB Code:
    1. Public Function RefreshPages(ctl1 as control, ctl2 as control, ctl3 as control, sub_name as ??????)
    2.  
    3.      ctl1.do something
    4.      ctl2.do something
    5.      ctl3.do something
    6.  
    7.      'now call the sub or function that was passed as a paramater
    8.  
    9.      sub_name()
    10.  
    11. End Function

    So whenever i finish doing whatever with the controls that the function was passed, i can then call the sub or function that was also passed.
    Last edited by C_Huegel; Apr 4th, 2004 at 03:33 PM.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Do a search on Delegates. This will limit you to a method with no parameters since you wont know what to pass in but it is very easy.

    Something like this:
    VB Code:
    1. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    2.         RefreshPages(Button1, Button2, lblName, AddressOf callback)
    3.     End Sub
    4.  
    5.     Public Delegate Sub RefreshPageCallBack()
    6.  
    7.     Public Function RefreshPages(ByVal ctl1 As Control, ByVal ctl2 As Control, ByVal ctl3 As Control, ByVal callback As RefreshPageCallBack)
    8.  
    9.         ctl1.Text = String.Empty
    10.         ctl2.Text = String.Empty
    11.         ctl3.Text = String.Empty
    12.  
    13.         'now call the sub or function that was passed as a paramater
    14.         callback.Invoke()
    15.  
    16.     End Function
    17.  
    18.     Public Sub callback()
    19.         MsgBox("called")
    20.     End Sub
    Last edited by Edneeis; Apr 4th, 2004 at 03:58 PM.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    3
    Sweet, Thanks.

  4. #4
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    I've never personally seen or heard of that. but, I'm no expert either. What I might do is use a SELECT statement and when certain paramerters are met, have certain functions launch.

    That's just ONE way though. my .02



    I'm anxious to see what the verterans have to suggest!!
    Last edited by Andy; Apr 4th, 2004 at 04:14 PM.

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    3
    Delegates is just what I was looking for... perfect.

  6. #6
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    lol EdNeesis beat me to it. My post looks out of place

    While in the middle of posting, my 11 month-old daughter wanted to play and I didn't finish it in time. funny

    BUT, I didn't know anything about delegates. I'm looking into that too

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