Jump to content

Nested If Then Else

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
kenex

kenex

    Learning Programmer

  • Members
  • PipPipPip
  • 32 posts
Public Class Form1
 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim age As Integer
Dim height As Double
Dim weight As Double
Dim name As String
Dim status As String
 
name = Txtname.Text
age = txtage.Text
height = txtheight.Text
weight = txtweight.Text
 
 
If age >= 18 And age <= 60 Then
If height >= 170 And height <= 2000 Then
If weight >= 60 And weight <= 80 Then
status = " prceed "
Else
status = " Reject "
End If
End If
End If
txtoutput.Text = " name: " & name & vbCrLf & " Age: " & age & vbCrLf & _
" height: " & height & vbCrLf & _
" weight: " & weight & vbCrLf & " Status: " & status
End Sub
End Class

Please can someone help correct this code.Wanted the programme to display reject when number below 18
is entered on the 'Age' textbox

Edited by Vswe, 13 March 2010 - 02:54 AM.
Use Code tags when posting code


#2
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
The most simple way us just to add two more Else blocks, your current Else block is corresponding with the "weight If statement". Another solution would be to add all three conditions from the If statements in the same if statement by using "And".

#3
kenex

kenex

    Learning Programmer

  • Members
  • PipPipPip
  • 32 posts

Vswe said:

The most simple way us just to add two more Else blocks, your current Else block is corresponding with the "weight If statement". Another solution would be to add all three conditions from the If statements in the same if statement by using "And".

Thx for the reply;it realy helped me.

#4
anglina

anglina

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts

kenex said:

Thx for the reply;it realy helped me.

Serious or Sarcastic?

#5
kenex

kenex

    Learning Programmer

  • Members
  • PipPipPip
  • 32 posts
serious!

#6
progcomputeach

progcomputeach

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
Just add an else clause for this: If age >= 18 And age <= 60 Then

That is:

If age >= 18 And age <= 60 Then
'existing code


Else
'display reject
End If