muhammad islam muhammad islam - 1 year ago 47
Vb.net Question

I do not know why I am getting this 'Addressof' error?

I got a problem when using this add handler. It keeps on saying


"AddressOf operand must be the name of a method (without parentheses)".


I am not sure what I have done wrong for this to occur.
The code for the add handler:

AddHandler cboQuantity(i).TextChanged, AddressOf StarterQuantityPrice(i)


The code for the
starterquantityprice
:

`Public Sub StarterQuantityPrice(ByVal i As Integer)
For k = 1 To CInt(MenuSelection.cboNumOfStarterDishes.SelectedItem)
QuantityPriceCalculation(k, i)
Next
End Sub`


The code for the
cboQuantity
:

X = 492
cboQuantity(i) = New ComboBox
cboQuantity(i).Location = New Point(X, Y)
For j = 1 To 10
cboQuantity(i).Items.Insert(j - 1, j)
Next
cboQuantity(i).DropDownStyle = ComboBoxStyle.DropDown
cboQuantity(i).Width = 43 : cboQuantity(i).Height = 21`

Answer Source

I'm not positive of this but I think the target of teh AddressOf needs the same signature as hooked event.

e.g.

AddHandler c.TextChanged, AddressOf SetDirty

Private Sub SetDirty(ByVal sender As Object, ByVal e As System.EventArgs)
    If Not mbDirty AndAlso Not mbFormLoad Then
        mbDirty = True
      ....
End Sub

Note that SetDirty as the same parameters as does TextChanged.

In your case you would use Sender to defined the control that changed and then find the required value.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download