Miranda Lynn Miranda Lynn - 2 years ago 68
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

For intNumber = 1 To 9
' Body of Loop
iNextyear = iNextyear + iNextyear * CDec((txtExpectedRaise.Text)) / 100
decAnnualPay = iNextyear

' 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 = ""

MsgBox("Please Enter A Number ", , "question")
txtExpectedRaise.Text = ""
btnCompute.Visible = False

Answer Source

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")
 End If

The same pattern applies to the other values.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download