Results 1 to 4 of 4

Thread: Parameter count mismatch

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Posts
    95

    Parameter count mismatch



    I get a parameter count mismatch when trying to invoke.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Parameter count mismatch

    The problem is that the UpdateDelegate takes a ParamArray of parameters and you can not pass a regular array to a ParamArray and a delegate doesn't allow ParamArrays so it's kind of a catch 22 moment. You can either change your UpdateForm to accept two parameters (a string and an object) or you can pass in a lambda into the UpdateDelegate constuctor and get rid of the delegate.
    Code:
      Public Sub UpdateForm(parameters() As Object)
        If Me.InvokeRequired Then
          Me.Invoke(Sub()
                      Select Case CStr(parameters(0))
                        Case "Title"
                          Me.Text = CStr(parameters(1))
                        Case "ButtonText"
                          Button1.Text = CStr(parameters(1))
                        Case "Size"
                          Me.Size = DirectCast(parameters(1), Size)
                      End Select
                    End Sub)
        End If
      End Sub
    Edit: It should probably look this way just in case an invoke isn't reguired:
    Code:
      Public Sub UpdateForm(parameters() As Object)
        Dim invokeSub = Sub()
                          Select Case CStr(parameters(0))
                            Case "Title"
                              Me.Text = CStr(parameters(1))
                            Case "ButtonText"
                              Button1.Text = CStr(parameters(1))
                            Case "Size"
                              Me.Size = DirectCast(parameters(1), Size)
                          End Select
                        End Sub
        If Me.InvokeRequired Then
          Me.Invoke(invokeSub)
        Else
          invokeSub()
        End If
      End Sub
    Last edited by Joacim Andersson; Jan 14th, 2012 at 03:24 PM.

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Parameter count mismatch

    @kalo93 - sorry to jump in here - not really on topic - I'm just curious...

    Why are you doing an update on a different thread?? What is the requirement that you are serving by doing that??

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Posts
    95

    Re: Parameter count mismatch

    Quote Originally Posted by szlamany View Post
    @kalo93 - sorry to jump in here - not really on topic - I'm just curious...

    Why are you doing an update on a different thread?? What is the requirement that you are serving by doing that??
    I was writing a tutorial, I've fixed it now though.

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