我有两个接受输入的文本框。数据计算并显示在ListBox
。
我根本没有显示消息框。因此,无论我输入什么数据,我都会发布所有内容,现在它们都在显示。有趣的是计算是正确的并且显示正确。
如果两个文本框中的数据不是数字,为空或小于零,我需要显示消息框。
如果有人能给我一个想法,我将不胜感激。
' Did user enter a numeric value?
If IsNumeric(txtHourlyWage.Text) Then
decHourlyWage = Convert.ToDecimal(txtHourlyWage.Text)
End If
' Is Hourly Wage greather than zero?
If decHourlyWage > 0 Then
End If
' Did user enter a numeric value?
If IsNumeric(txtExpectedRaise.Text) Then
decExpectedRaise = Convert.ToDecimal(txtExpectedRaise.Text)
End If
' Did user enter a numeric value?
If decExpectedRaise > 0 Then
End If
' If txtHourlyWage.Text = "" Or txtExpectedRaise.Text = "" Then
'MsgBox("Input Cannot Be Empty")
iNextyear = (decHourlyWage * decHoursInWeek) * (decWeeksInYear)
iNextyear = iNextyear
decAnnualPay = iNextyear
lstAnnualPay.Items.Add(decAnnualPay.ToString("c"))
For intNumber = 1 To 9
' Body of Loop
iNextyear = iNextyear + iNextyear * CDec((txtExpectedRaise.Text)) / 100
decAnnualPay = iNextyear
lstAnnualPay.Items.Add(decAnnualPay.ToString("c"))
Next
' Display error message if user entered a negative number
MsgBox("You Entered " & txtHourlyWage.ToString() & ". Please Enter a Positive Number ", , "question")
MsgBox("You Entered " & txtExpectedRaise.ToString() & ". Please Enter a Positive Number ", , "question")
'Display error message if user entered a nonnumeric value
MsgBox("Please Enter A Number ", , "question")
txtHourlyWage.Text = ""
txtHourlyWage.Focus()
MsgBox("Please Enter A Number ", , "question")
txtExpectedRaise.Text = ""
txtExpectedRaise.Focus()
btnCompute.Visible = False
答案 0 :(得分:0)
以这种方式使用更强大的decimal.TryParse
' Did user enter a numeric value?
If Not decimal.TryParse(txtHourlyWage.Text, decHourlyWage) OrElse _
decHourlyWage < 0 Then
MsgBox("You Entered an invalid value for the Hourly Wage (negative, zero or empty", "Number")
return
End If
相同的模式适用于其他值。