Miranda Lynn Miranda Lynn - 7 months ago 9
Vb.net Question

Message boxs are not working as expected

I am new to programing. I am using Visual studio 2015. I am in week 4.
The problem I am having is I can not get the messageboxs to display as expected. I have been at this for 3 days now, and I have tried everything, and I am fairly sure it is really simple'

I have 2 text boxes that accept input from, the data is calucalted and displayed in a listbox.

I was not getting the messageboxs to show at all. so I unnested everything and now I they are displaying no mater data I put in. the funny thing is the calcualtions are correct and display correct.
I need the message boxes to appear if the data in the two text boxes are not a number, are empty and are less than zero.
Please if anyone can give me an idea I would be grateful

' 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

Answer

Use the more powerfull decimal.TryParse in this way

'  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

The same pattern applies to the other values.