多播委托未定义错误

时间:2013-12-20 21:37:19

标签: vb.net

这段代码有什么问题MyEqaution没有定义,我也不知道为什么有人可以提供帮助。应该定义因为我定义了吗?我很困惑。或者我没有以正确的方式定义MyEqaution。就像我说的,任何人都可以帮忙。

Imports System.Delegate

Module Module1

    Dim a As Integer
    Dim b As Integer
    Dim Answer As Integer
    Dim MyEqaution As Math

    Private Delegate Sub Math()

    Sub Main()
        Dim MyEqaution As Math
        Dim ask As MyEqaution
        Dim Multiply1 As MyEqaution
        Dim Subtract1 As MyEqaution
        Dim Addition1 As MyEqaution
        Dim Divide1 As MyEqaution
        Dim MyEqationAll As Math

        ask = New MyEqaution(AddressOf Ask1)
        Multiply1 = New MyEqaution(AddressOf Multiply)
        Subtract1 = New MyEqaution(AddressOf Subtract)
        Addition1 = New MyEqaution(AddressOf Addition)
        Divide1 = New MyEqaution(AddressOf Divide)
        MyEqaution = Math.Combine(ask, Multiply1, Subtract1, Addition1, Divide1)
        MyEqationAll.DynamicInvoke("Math")
        Console.ReadLine()
    End Sub

    Sub Ask1()
        Console.WriteLine("Enter First Integer")
        a = Console.ReadLine()
        Console.WriteLine("Enter Second Integer")
        b = Console.ReadLine()
    End Sub

    Sub Multiply()
        Answer = a * b
        Console.WriteLine(Answer)
    End Sub

    Sub Subtract()
        Answer = a - b
        Console.WriteLine(Answer)
    End Sub

    Sub Addition()
        Answer = a + b
        Console.WriteLine(Answer)
    End Sub

    Sub Divide()
        Answer = a / b
        Console.WriteLine(Answer)
    End Sub

End Module

1 个答案:

答案 0 :(得分:0)

MyEqaution在您的代码中可变

昏暗的声明用法:

Dim variable as Type

下面:

  Private Delegate Sub Math()
    Sub Main()

        'Dim ask As Math
        'Dim Multiply1 As Math
        'Dim Subtract1 As Math
        'Dim Addition1 As Math
        'Dim Divide1 As Math 
        'ask = New Math(AddressOf Ask1)
        'Multiply1 = New Math(AddressOf Multiply)
        'Subtract1 = New Math(AddressOf Subtract)
        'Addition1 = New Math(AddressOf Addition)
        'Divide1 = New Math(AddressOf Divide)
        'MyEqaution = CType(Math.Combine(ask, Multiply1, Subtract1, Addition1, Divide1), Math)
        'or shorter
         MyEqaution = CType(Math.Combine(New Math(AddressOf Ask1), New Math(AddressOf Multiply), _
                                    New Math(AddressOf Subtract), New Math(AddressOf Addition), New Math(AddressOf Divide)), Math)
        MyEqaution.Invoke()
        Console.ReadLine()
    End Sub