Vb.net 错误:选项Strict On不允许从';对象';至';十进制';
我想检查单元格J34(excel)的值。如果该值为null,则显示消息,如果不是,则运行代码的其余部分 但是,当我编译时,我会在第行看到上面的错误: decAnnualMid=Convert.ToDecimal(Globals.dsbPositionBoard.Range(“J34”).Value) 这是我剩下的代码Vb.net 错误:选项Strict On不允许从';对象';至';十进制';,vb.net,Vb.net,我想检查单元格J34(excel)的值。如果该值为null,则显示消息,如果不是,则运行代码的其余部分 但是,当我编译时,我会在第行看到上面的错误: decAnnualMid=Convert.ToDecimal(Globals.dsbPositionBoard.Range(“J34”).Value) 这是我剩下的代码 Option Strict On Option Explicit On Private Sub chk10thPercentile_CheckedChanged(sender A
Option Strict On
Option Explicit On
Private Sub chk10thPercentile_CheckedChanged(sender As Object, e As EventArgs) Handles chk10thPercentile.CheckedChanged
'This event runs when the 10th checkbox is checked
'The event clears the cells where the value will be pasted
'enters the value from cell J34 into calculationShet H45 and clears
'the checkboxes for 25th, 50th, 75th, 90th and Other Amount
'checkboxes.
Dim decAnnualMid As Decimal
If chk25thPercentile.Checked = True And Globals.dsbPositionBoard.Range("J34").Value Is DBNull.Value Then
'Display is user has not selected a position in the dashboard.
MsgBox("The Market Data section of the Position Dashboard does not have a value for the 10th Percentile.", MsgBoxStyle.Critical, "Input Error")
Me.Close()
Else
'convert the value of K34 to decimal and
decAnnualMid = Convert.ToDecimal(Globals.dsbPositionBoard.Range("J34").Value)
'convert annual salary to hourly
decHourlyMid = decAnnualMid / 52 / 40
'display in the Mid label box
lblAnnualMid.Text = decAnnualMid.ToString("C")
lblHourlyMid.Text = decHourlyMid.ToString("C")
'Uncheck all other boxes
chk25thPercentile.Checked = False
chk50thPercentile.Checked = False
chk75thPercentile.Checked = False
chk90thPercentile.Checked = False
chkOtherAmount.Checked = False
End If
End Sub
Range(“J34”)生成object类型的对象引用,而不是Range类型的对象引用。你必须在happy上选择严格的选项:
Dim sel As Range = CType(Globals.dsbPositionBoard.Range("J34"), Range)
decAnnualMid = Convert.ToDecimal(sel.Value)
Range(“J34”)生成object类型的对象引用,而不是Range类型的对象引用。你必须在happy上选择严格的选项:
Dim sel As Range = CType(Globals.dsbPositionBoard.Range("J34"), Range)
decAnnualMid = Convert.ToDecimal(sel.Value)