Closed Thread
Results 1 to 6 of 6

Thread: Nested If Then Else

  1. #1
    kenex is offline Learning Programmer
    Join Date
    Dec 2008
    Posts
    31
    Rep Power
    0

    Nested If Then Else

    Code:
    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
    Last edited by Vswe; 03-13-2010 at 02:54 AM. Reason: Use Code tags when posting code

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Posts
    9,547
    Blog Entries
    5
    Rep Power
    98

    Re: Nested If Then Else

    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".

  4. #3
    kenex is offline Learning Programmer
    Join Date
    Dec 2008
    Posts
    31
    Rep Power
    0

    Re: Nested If Then Else

    Quote Originally Posted by Vswe View Post
    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.

  5. #4
    anglina's Avatar
    anglina is offline Learning Programmer
    Join Date
    Jan 2009
    Location
    Vientiane, Laos
    Posts
    76
    Rep Power
    0

    Re: Nested If Then Else

    Quote Originally Posted by kenex View Post
    Thx for the reply;it realy helped me.
    Serious or Sarcastic?

  6. #5
    kenex is offline Learning Programmer
    Join Date
    Dec 2008
    Posts
    31
    Rep Power
    0

    Re: Nested If Then Else

    serious!

  7. #6
    progcomputeach is offline Learning Programmer
    Join Date
    Mar 2010
    Posts
    45
    Rep Power
    0

    Re: Nested If Then Else

    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

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Nested classes
    By skypower in forum Java Help
    Replies: 3
    Last Post: 04-06-2011, 02:13 PM
  2. Nested Loop Help
    By Kragen831 in forum Java Help
    Replies: 1
    Last Post: 02-23-2011, 07:43 PM
  3. Nested for loops?
    By fluteplayer in forum Java Help
    Replies: 6
    Last Post: 02-03-2011, 11:21 PM
  4. Need with with for nested loops
    By bkim33 in forum Java Help
    Replies: 6
    Last Post: 01-19-2011, 03:06 AM
  5. nested loop
    By za7ef in forum C and C++
    Replies: 10
    Last Post: 04-08-2010, 02:24 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts