hello,i need to make an if statement for a mortgage application in vb.net, basically i have a list box for the DOB called cmbDOB, and a label to show the maximum mortgage. But i dont know how to make the if statement-it has to show the maximum mortage in the label depending on the following:

*Over 50yrs- maximum mortage = 15yrs
*between 40 - 50 = 20yrs
*Between 30 - 40 = 25
*betwen 18 - 30 = 30yrs
*Under 18yrs - NO mortgage!

but my list box has the DOB's as follows - 1940......to....1985. anyone good at writing vb.net language and wanna help me!!!!!please!!!!!!!! :o

dont go for IF Statements as you having more than three conditions.. go for Select case.. that will be good..

To do this properly, I would focus on allowing the user to select their birthdate with a datetimepicker....or, convert their choices from your listboxes to a date.

You will need to insert error handling and other specifics on your own, as well as adjust the accuracy of the age...but this is very close to what you need.

Public Class Form1
    Dim intage As Integer

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim dtdob As New Date(Me.ListBox1.SelectedItem.ToString, 1, 1)
        ' using this method of calculating the age of the client is inaccurate, but the
        ' function I used offers more granularity for calculating an exact age...you can tweak it.
        intage = Microsoft.VisualBasic.DateAndTime.DateDiff(DateInterval.Year, dtdob, Now)
        populatelistboxitems(intage)
    End Sub

    Private Sub populatelistboxitems(ByVal intage As Integer)
        Me.ListBox2.Items.Clear()
        Select Case intage
            Case Is >= 50
                Me.ListBox2.Items.Add("10 year mortgage")
            Case Is >= 40
                Me.ListBox2.Items.Add("10 year mortgage")
                Me.ListBox2.Items.Add("20 year mortgage")
            Case Is >= 30
                Me.ListBox2.Items.Add("10 year mortgage")
                Me.ListBox2.Items.Add("20 year mortgage")
                Me.ListBox2.Items.Add("25 year mortgage")
            Case Is >= 18
                Me.ListBox2.Items.Add("10 year mortgage")
                Me.ListBox2.Items.Add("20 year mortgage")
                Me.ListBox2.Items.Add("25 year mortgage")
                Me.ListBox2.Items.Add("30 year mortgage")
        End Select
    End Sub
End Class
This article has been dead for over six months. Start a new discussion instead.