调用已经有功能的Subs

时间:2012-10-26 12:32:01

标签: vb.net visual-studio-2008

首先,我一直在谷歌搜索,我被困了,我需要一个人的手。我已经有一个包含函数作为参数的子,现在的问题是如何在我的按钮中调用这个子,请完全向我解释,我已经非常绝望了

Public Function AddDec(ByVal Valdec1 As Decimal, ByVal Valdec2 As Decimal) As Decimal
    AddDec = Valdec1 + Valdec2
End Function

Sub Finished(ByVal AddDec As Func(Of Decimal, Decimal, Decimal))
    If DetailCount1.Text.Length >= 10 Or DetailCount2.Text.Length >= 10 Then
        If TextBox1.Text = "" Then TextBox1.Text = 0
        If DetailCount1.Text.Contains(",") Or DetailCount2.Text.Contains(",") Then
            Valdec2 = CDec(TextBox1.Text)
            TextBox1.Text = Adddec(Valdec1, Valdec2)
            MsgBox("HELP ME xD")
        Else
            ValDbl2 = CDbl(TextBox1.Text)
            TextBox1.Text = ValDbl1 + ValDbl2
        End If
    ElseIf Not DetailCount1.Text.Length >= 10 And Not DetailCount2.Text.Length >= 10 Then
        If TextBox1.Text = "" Then TextBox1.Text = 0
        If kindbil1 = "Even" And Label2.Text = "Even" Then
            val2 = CInt(TextBox1.Text)
            TextBox1.Text = CInt(val1 + val2)
        ElseIf kindbil1 = "Deci" And Label2.Text = "Deci" Then
            Valdec2 = CDec(TextBox1.Text)
            TextBox1.Text = CDec(Valdec1 + Valdec2)
        ElseIf kindbil1 = "Deci" And Label2.Text = "Even" Then
            val2 = CInt(TextBox1.Text)
            Valdec2 = CDec(val2)
            TextBox1.Text = CDec(Valdec1 + Valdec2)
        ElseIf kindbil1 = "Even" And Label2.Text = "Deci" Then
            Valdec2 = CDec(TextBox1.Text)
            Valdec1 = CDec(val1)
            TextBox1.Text = CDec(Valdec1 + Valdec2)
        End If
    End If

End Sub

1 个答案:

答案 0 :(得分:1)

有点难以理解你想做什么,但我想你想用Finished方法作为AddDec参数的参数调用AddDec

为此,您必须使用the AddressOf operator

Finished(AddressOf AddDec)