Too many arguments to 'Public Sub New()'

jpdbay

Active member
Joined
Feb 22, 2006
Messages
31
Programming Experience
Beginner
Hi all,

I'm getting the mentioned error when I copy paste a piece of code where I add a new button in a form. It works fine with all other buttons in the form. The code is:
VB.NET:
Private Sub cmdManualBucketAddition_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdManualBucketAddition.Click
        'Cursor = Cursors.WaitCursor

        WriteTrace(Me.Name & ":cmdManualBucketAddition_Click", 3, True)

        If AfficherForm(New frmModiBucketCharging([COLOR=Red]m_HeadId[/COLOR])) = DialogResult.OK Then Refresh()
        

        WriteTrace(Me.Name & ":cmdManualBucketAddition_Click", 3, False)
    End Sub
The error is shown in the red marked variable which I pass in the argument. m_HeadId declared as Integer. The same variables pass to other buttons and no prob. I'm figuring out why and even try to understand suggestion given by senior members in this forum but cannot resolve...pls guide:confused::confused:

jpdbay
 
This is due to the frmModiBucketCharging don't have a method that allowed you to pass an argument to it. In the frmModiBucketCharging, you can find this method:

VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2]()
[/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].New()
[/SIZE][SIZE=2][COLOR=#008000]'This call is required by the Windows Form Designer.
[/COLOR][/SIZE][SIZE=2]InitializeComponent()
[/SIZE][SIZE=2][COLOR=#008000]'Add any initialization after the InitializeComponent() call
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]

Now you have to overload it so that it can take an additional argument, for example, creating a new method:

VB.NET:
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2]([/SIZE]pHeadId As Integer[SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].New()
[/SIZE][SIZE=2][COLOR=#008000]'This call is required by the Windows Form Designer.
[/COLOR][/SIZE][SIZE=2]InitializeComponent()
[/SIZE][SIZE=2][COLOR=#008000]'Add any initialization after the InitializeComponent() call[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' Doing something with pHeaderId
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]
 
lingsn,

Sorry for late reply. I just settled the overload argument issue. After initializing new constructor as per your advise, it works fine. :). It took almost 1 month to understand it. I feel like so silly:eek:..now, I can continue with the form.:) thanks again.
 
Back
Top