我要检查单元格 J34(excel)的值。如果该值为 null 则显示消息,如果不是则运行其余代码。
但是,当我编译时,我在网上得到了上面的错误:
decAnnualMid = Convert.ToDecimal(Globals.dsbPositionBoard.Range("J34").Value)
这是我的其余代码
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