计算带有标签值的公式 [英] calculation of a formula with value in label
问题描述
你好,我的代码没有取值标签
默认情况下它取0而不是取label1.text值
DataGridView9.Rows(i).Cells(16).Value = CDbl(DataGridView9.Rows(i).Cells(13).Value)* Val(Label1.Text)
请帮我这个
试试以下
Dim Value1 = CDbl(DataGridView9.Rows(i).Cells(13).Value)
Dim Value2 = Val(Label1 .Text)
然后
DataGridView9.Rows(i).Cells (16).Value = Value1 * Value2在上面的行上放置一个断点。当断点命中鼠标悬停在Value1和Value2上时,值是否符合预期?
此外,您应该使用Convert.ToInt32而不是Val。如果不确定DataGridView9.Rows(i).Cells(13).Value是否为Double,请先使用Integer.TryParse验证它是否为整数。
Dim Value1 As Double = 0
Dim Value2 As Double = CDbl(Label1.Text)
如果Double.TryParse(CStr(DataGridView9.Rows(i).Cells(13).Value),Value1)然后
DataGridView9.Rows(i).Cells(16).Value = Value1 * Value2
结束如果
最后,您可能想检查是否有DataGridView9。行(i)。细胞(13)。值不是什么。
hello, my codes is not taking the value of label
it is taking 0 by default instead of taking label1.text value
DataGridView9.Rows(i).Cells(16).Value = CDbl(DataGridView9.Rows(i).Cells(13).Value) * Val(Label1.Text)
please help me in this
Try the following
Dim Value1 = CDbl(DataGridView9.Rows(i).Cells(13).Value) Dim Value2 = Val(Label1.Text)Then
DataGridView9.Rows(i).Cells(16).Value = Value1 * Value2Put a breakpoint on the line above. When the breakpoint hits hover over both Value1 and Value2, are the values as expected?
Also you should use Convert.ToInt32 rather than Val. If not sure if DataGridView9.Rows(i).Cells(13).Value is a Double use Integer.TryParse first to validate it's an integer.
Dim Value1 As Double = 0 Dim Value2 As Double = CDbl(Label1.Text) If Double.TryParse(CStr(DataGridView9.Rows(i).Cells(13).Value), Value1) Then DataGridView9.Rows(i).Cells(16).Value = Value1 * Value2 End IfLastly, you might want to check if DataGridView9.Rows(i).Cells(13).Value is not Nothing.
这篇关于计算带有标签值的公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!