-2

It will not run the msgbox for the errors when incorrect data is entered

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim weight As Decimal
        Dim height As Decimal
        Dim bmi As Decimal
        weight = InputBox("enter weight")
        height = InputBox("enter height")
        If weight > 10 And weight <= 600 And height >= 0.5 And height <= 2.7 Then
            bmi = weight / (height) ^ 2
        ElseIf weight <= 10 And weight > 600 Then
            MsgBox("you have enterd in valid data it must be above 10 and below or equal 600")
        ElseIf height < 0.5 And height > 2.7 Then
            MsgBox("you have enterd in valid data it must between 0.5 and 2.7 inclusive")
        End If
        TextBox1.Text = bmi
End Sub
Dman
  • 553
  • 1
  • 11
  • 33

2 Answers2

2

Your error is here

ElseIf weight <= 10 And weight > 600 Then
        MsgBox("you have enterd in valid data it must be above 10 and below or equal 600")
    ElseIf height < 0.5 And height > 2.7 Then
        MsgBox("you have enterd in valid data it must between 0.5 and 2.7 inclusive")
    End If

Your weight is never going to be less than or equal to 10 AND greater than 600 at the same time. Same applies for the height

You need to use OR instead of AND

Andrew
  • 2,315
  • 3
  • 27
  • 42
0

Please check your conditions. No value can be lessthan 10 and also greater than 600. eg. lets take weigth = 3. it is less than 10 but it is not greater than 600.

Please correct your conditions.

Pavan
  • 337
  • 1
  • 4
  • 10