我有一个组合框,可以选择以下值: " ----&#34 ;, " C&#34 ;, " d&#34 ;, " E" 默认为" ----"
如果组合框选择是" C"或" E"我需要结果是" 1" 如果组合框选择是" ----"或" D"我需要结果是" 0"
然后添加所有组合框的总和,并在tbComDataTot文本框中给出结果
我使用以下代码:
Private Sub cbTermPurch_SelectedIndexChange(sender As Object, e As EventArgs) Handles cbComData1.SelectedIndexChanged, cbComData2.SelectedIndexChanged, cbComData3.SelectedIndexChanged, cbComData4.SelectedIndexChanged, cbComData5.SelectedIndexChanged, cbComData6.SelectedIndexChanged
Dim a As Integer = 0
Dim cd1 As Integer = CInt(IIf(cbComData1.Text = "C" Or cbComData2.Text = "E", 1, 0))
Dim cd2 As Integer = CInt(IIf(cbComData2.Text = "C" Or cbComData1.Text = "E", 1, 0))
Dim cd3 As Integer = CInt(IIf(cbComData3.Text = "C" Or cbComData3.Text = "E", 1, 0))
Dim cd4 As Integer = CInt(IIf(cbComData4.Text = "C" Or cbComData4.Text = "E", 1, 0))
Dim cd5 As Integer = CInt(IIf(cbComData5.Text = "C" Or cbComData5.Text = "E", 1, 0))
Dim cd6 As Integer = CInt(IIf(cbComData6.Text = "C" Or cbComData6.Text = "E", 1, 0))
Try
a = (cd1 + cd2 + cd3 + cd4 + cd5 + cd6)
If a > 0 Then
tbComDataTot.Text = a.ToString
Else
If a = CInt("0") Then
tbComDataTot.Text = "0"
End If
End If
Catch ex As Exception
'If a calculation error occurs, show Error message box
Dim frm As New MeMsgCalcError(ex, "'Total Fuel Card Purchases' Calculation Error." & vbCrLf & "Lines 1517-1540")
frm.Show()
End Try
End Sub
回复回复:
更正了忽略dim语句var define的语句中的错误。
尝试更改为IF而非IIF。
在调试中(显然在来到这里寻求帮助之前检查调试)将变量保持在" 0"无论在组合框中输入什么。
所有修改仍会导致" 0"被退回而不是预期的总数。
附加信息:
通过导入CSV文件来填充CB。如果我手动选择使用组合框,代码工作正常。我希望代码在导入后读取cb,并通过手动干预读取总数。这个类似的代码在我的程序的其他地方使用,它工作正常,但在组合框中设置为严格的YES / NO答案。