please Help!!IF statement........

shelly121

Member
Joined
Feb 17, 2005
Messages
15
Programming Experience
Beginner
Hey ppz?any 1 gud at IF questions?? basically i have a Date-of-birth list box with 1940,1941,1942 etc to 1995. and a label which has to show the maximum mortgage available depending on:
*Over 50yrs- maximum mortage = 15yrs
*between 40 - 50 = 20yrs
*Between 30 - 40 = 25
*betwen 18 - 30 = 30yrs
*Under 18yrs - NO mortgage
so the if statement would have to work it out how old they are depending on the DOB???anyone know how to write it??
 
Here are the if else statements you need.
VB.NET:
		Dim thisyear As Integer = 2005

		If thisyear - ComboBox1.Text > 50 Then
			MsgBox("You maximum morgage years are 15")
		ElseIf thisyear - ComboBox1.Text <= 50 And thisyear - ComboBox1.Text >= 40 Then
			MsgBox("You maximum morgage years are 25")
		ElseIf thisyear - ComboBox1.Text <= 40 And thisyear - ComboBox1.Text >= 30 Then
			MsgBox("You maximum morgage years are 25")
		ElseIf thisyear - ComboBox1.Text <= 30 And thisyear - ComboBox1.Text >= 18 Then
			MsgBox("You maximum morgage years are 30")
		ElseIf thisyear - ComboBox1.Text < 18 Then
			MsgBox("You are to young to get a morgage")
		End If
		Label1.Text = thisyear - ComboBox1.Text

And to populate the combobox use:
VB.NET:
		Dim i As Integer
  		For i = 1940 To 1995
  			ComboBox1.Items.Add(i)
  		Next i

To keep people from typeing nonesence in the combobox set it's drop down property to dropdownlist.

Or use this:
VB.NET:
ComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
 
hey thanks! god its looks so simple but jus cudnt get my head round it at all!!where does the :
HTML:
 ComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
go??? does it go inside the combo box's code with the rest??

thanks
shelly​
 
shelly121 said:
hey thanks! god its looks so simple but jus cudnt get my head round it at all!!where does the :
HTML:
 ComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
go??? does it go inside the combo box's code with the rest??

thanks
shelly​

It would probubly be best to use the properties for the combobox to do it, but other than that it's bese to go in the form_load.
 
hello,thanks 4 the help-i changed sum of it tho-as i wantd it to display the mortgage in a label instead of a msb box, so iv got :
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbDOB.SelectedIndexChanged

cmbDOB.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Dim i As Integer
For i = 1940 To 1995
cmbDOB.Items.Add(i)
Next i
End Sub

Private Sub btnMortgage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMortgage.Click
im thisyear As Integer = 2005
If thisyear - cmbDOB.Text > 1955 Then
lblMortgage.Text = "15 years"
ElseIf thisyear - cmbDOB.Text <= 1955 And thisyear - cmbDOB.Text >= 1965 Then
lblMortgage.Text = "20 years"
ElseIf thisyear - cmbDOB.Text <= 1965 And thisyear - cmbDOB.Text >= 1975 Then
lblMortgage.Text = "25 years"
ElseIf thisyear - cmbDOB.Text <= 1975 And thisyear - cmbDOB.Text >= 1987 Then
lblMortgage.Text = "30 years"
ElseIf thisyear - cmbDOB.Text < 1987 Then
lblMortgage.Text = "NO MORTGAGE"
End If
lblMortgage.Text = thisyear - cmbDOB.Text


however it doesnt add the max mortgage up right?? when i ask to display the mortgage- if the dob is 1995, it displays "10", and 1994 displays "11", 1992 displays "12" ...and so on. but it shouldnt be doing this, it should just be displaying either 50,40,30 etc?? can any1 help??? please!!!!
 
malitice said:
Oh that last line you need to remove:
lblMortgage.Text = thisyear - cmbDOB.Text

hey thanks 4 ya help, iv altered the code since and its kindof working!!it now says 20,25 etc in the label but not quite in the right places??? any ideas y???
Private Sub btnMortgage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMortgage.Click
Dim thisyear As Integer = 2005

Dim age As Integer = cmbYear.Text

If thisyear - age < 18 Then
lblMortgage.Text = "NO MORTGAGE"
' below(18)
ElseIf thisyear - age < 30 Then
lblMortgage.Text = "30 years"
' between 20 and 30
ElseIf thisyear - age < 40 Then
lblMortgage.Text = "25 years"
' between 30 and 40
ElseIf thisyear - age < 50 Then
lblMortgage.Text = "20 years"
' between 40 and 50
ElseIf thisyear - age > 50 Then
lblMortgage.Text = "15 years"
' they are over 50
End If
End Sub

 
Last edited:
malitice said:
What do you mean not in the right places? Are you trying to center it or somthing?

hey, its sorted....I was just being an idiot finking that it wasnt displaying it right still....but it was!!!lol. thanks for ya help malitice.
 
I think, You can also achieve the same using the Case staments, that would have been much simpler than IF Else Statements.

For example:

Select Case thisyear - ComboBox1.Text

Case IS > 50
MsgBox("You maximum morgage years are 15")
case 40 TO 50
MsgBox("You maximum morgage years are 25")
case 30 to 40
MsgBox("You maximum morgage years are 25")
Case 18 to 30
MsgBox("You maximum morgage years are 30")
case is < 18
MsgBox("You are to young to get a morgage")
End Select
 
Back
Top