如何将子过程中的值传递给函数过程....我是否将整个子过程传递给函数过程参数?

时间:2012-03-30 03:58:20

标签: vb.net

我是学生做作业,我如何将值从子程序传递给函数程序....我想将值从decSubtotal传递给名为CalculateDiscount的函数过程;看看我的代码 -

 Private Sub CalculateSubtotal(ByVal _decTENTCOST As Decimal, ByVal _decRVCOST As Decimal, _
                              ByVal _decCABINCOST As Decimal)

    Dim decSubtotal As Decimal
    Dim intSiteType, intNumberOfNights As Integer

    intSiteType = cboSiteType.SelectedIndex()
    intNumberOfNights = Convert.ToInt32(txtNumberOfNights.Text)

    Select Case intSiteType
        Case 0
            decSubtotal = _decTENTCOST * intNumberOfNights
        Case 1
            decSubtotal = _decRVCOST * intNumberOfNights
        Case 2
            decSubtotal = _decCABINCOST * intNumberOfNights

    End Select

    lblSubtotal.Text = decSubtotal.ToString()

End Sub

1 个答案:

答案 0 :(得分:1)

你会像这样调用这个函数,(可能在你的结束选择语句之后)

Dim MyValue = CalculateDiscount(decSubTotal)

您的CalculateDiscount可能如下所示:

Function CalculateDiscount(byval pSubTotal as Decimal) as Decimal

   ....

   return MyDiscountedAmount

End Function

在VB.NET中,我们只提到“subs”和“functions”。两者都是子例程,也称为子程序(对某些程序而言)。函数总是返回一个值,而subs永远不会返回一个值。