【发布时间】:2022-01-04 12:45:01
【问题描述】:
如何避免收到此警告?如果警告和代码保持如下,软件会抛出运行时错误吗?编写此代码的更好方法是什么?由于我不能对网格值使用最小值和最大值,因此我只能使用 .Value ,因此我编写了以下代码。
Select Case CSng(dgv_config.Item(dgv_config.Columns("p").Index, rowindex).Value)
Case 1 To 150
#Disable Warning BC42019 ' Operands of type Object used for operator
If dgv_config.Item(dgv_config.Columns("tsamp").Index, rowindex).Value > 400 Then
#Enable Warning BC42019 ' Operands of type Object used for operator
dgv_config.Item(dgv_config.Columns("tsamp").Index, rowindex).Value = 400
End If
#Disable Warning BC42019 ' Operands of type Object used for operator
If dgv_config.Item(dgv_config.Columns("tsamp").Index, rowindex).Value < 50 Then
#Enable Warning BC42019 ' Operands of type Object used for operator
dgv_config.Item(dgv_config.Columns("tsamp").Index, rowindex).Value = 50
End If
End Select
【问题讨论】:
-
好吧,我猜 Option strict 现在已关闭,我建议在继续之前将其打开(它应该几乎总是打开,很多指南已经解释了该过程)。实际问题虽然,它确实为您解释了它。 dgv 中的值是 object 类型,您将其与数字类型进行比较。简单的答案是将 dvg 值的结果类型转换为适当的类型