带参数的VB.NET函数

时间:2015-04-23 13:46:02

标签: vb.net

我在VB.NET中有这个功能:

Function RunVoIPCDR(Optional ByVal function_selected_customer As String = "")
    If function_selected_customer > 0 And CallsMonth.SelectedValue <> "" And CallsYear.Text <> "" Then

    End If
End Function

但我在If行上收到错误说:

  

其他信息:从字符串转换&#34;&#34;输入&#39; Double&#39;无效。

3 个答案:

答案 0 :(得分:2)

function_selected_customer是一个字符串,但您尝试使用它,就像它是一个数字一样。如果在逻辑中将空字符串视为等于0,则可以执行以下操作:

andalso

{{1}}表示如果第一部分为假,则其他部分甚至不会被测试。

答案 1 :(得分:0)

我不知道定义,但看起来像这部分: CallsMonth.SelectedValue <> ""应该检查数值而不是空字符串,例如CallsMonth.SelectedValue <> 0

答案 2 :(得分:0)

你这样做

function_selected_customer > 0

一个字符串不能大于一个数字。您必须将字符串转换为数字或让参数接受数字。

Dim valueAsNumber As Integer

If Not Int32.TryParse(function_selected_customer, valueAsNumber) Then
    valueAsNumber = 0 ' Assuming that you want a 0 for bad input
End If

If valueAsNumber > 0 And ... Then