Please help!!iv tryed and tryed with this!basically i have a combo box which displays the date-of-births from 1940-1995, and a button to press to display the maximum mortgage in a label. The max mortgage depends on the age of client:

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

and this is wot iv got for my code,but it underlines the "lblMortgage" part, but i dont know how else it can be written??any1 help me??:

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
Dim thisyear As Integer = 2005

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

End Sub
End Class

Recommended Answers

All 16 Replies

I'm guessing lblmortgage is a label (not a textbox) and therefore, would require the use of .caption instead of .text and I'm guessing it's not a variable... so you should also add .caption to the others.... such as

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
Dim thisyear As Integer = 2005

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

End Sub
End Class

hello,thanks 4 replying -

it underlines ".caption" tho?? and when i put the mouse cursor over it, it says

caption is not a member of 'system.windows.forms.label'

???

I was wrong. I'm sorry. I was still operating under the rules of VB6, not .net. The Label is supposed to be .Text, not .Caption.... but instead of using just lblMortgage = try using lblMortgage.text =

hy, thanks, yh i changed it to .text but now its adding up the mortage wrong?? when i enter 1995 it should say "no mortgage" but it says "10", and 1994 displays 11 in the lable, 1993 displays 12 ...and so on???
and iv changed the numbers such as 30 to the actual dates such as 1975, but this still has no effect:

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

????

hmn, you could try converting the string to a number first. I'm not sure if .NET does that for you right off the bat or not. You might have to cast it, or you might be able to use val, like: thisyear - val(cmdDob.txt) > 1995 then?

no...... :-| it still doesnt make a difference. thabks for ya help so far tho.

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
Dim thisyear As Integer = 2005

If thisyear - Val(cmbDOB.Text) > 1955 Then
lblMortgage.Text = "15 years"
ElseIf thisyear - Val(cmbDOB.Text) <= 1955 And thisyear - Val(cmbDOB.Text) >= 1965 Then
lblMortgage.Text = "20 years"
ElseIf thisyear - Val(cmbDOB.Text) <= 1965 And thisyear - Val(cmbDOB.Text) >= 1975 Then
lblMortgage.Text = "25 years"
ElseIf thisyear - Val(cmbDOB.Text) <= 1975 And thisyear - Val(cmbDOB.Text) >= 1987 Then
lblMortgage.Text = "30 years"
ElseIf thisyear - Val(cmbDOB.Text) < 1987 Then
lblMortgage.Text = "NO MORTGAGE"
End If
lblMortgage.Text = thisyear - Val(cmbDOB.Text)

ElseIf thisyear - Val(cmbDOB.Text) < 1987 Then
     lblMortgage.Text = "NO MORTGAGE"
End If

' /* What is this line all about!?!?!? */
lblMortgage.Text = thisyear - Val(cmbDOB.Text)

after you figure out your calculations, using the else if block..... you end your if, right? Immediately after that, you set lblMortgage.text (which, was set in the elseif block) to whatever thisyear = cmbDob.text is.....(which for 1995 is 10, because 2005 -1995 = X?)

Remove that last line:
lblMortgage.Text = thisyear - Val(cmbDOB.Text)

And it should work.

2 be honest, i dnt knw wot that line ws about!!ths is a bit confusin 4 me now! wel...it gets funnier- now its just displaying "no mortgage" for every dob entered!!

Dim thisyear As Integer = 2005

If thisyear - Val(cmbDOB.Text) > 1955 Then
lblMortgage.Text = "15 years"
ElseIf thisyear - Val(cmbDOB.Text) <= 1955 And thisyear - Val(cmbDOB.Text) >= 1965 Then
lblMortgage.Text = "20 years"
ElseIf thisyear - Val(cmbDOB.Text) <= 1965 And thisyear - Val(cmbDOB.Text) >= 1975 Then
lblMortgage.Text = "25 years"
ElseIf thisyear - Val(cmbDOB.Text) <= 1975 And thisyear - Val(cmbDOB.Text) >= 1987 Then
lblMortgage.Text = "30 years"
ElseIf thisyear - Val(cmbDOB.Text) < 1987 Then
lblMortgage.Text = "NO MORTGAGE"
End If
End Sub

nope!! i noticed at 1st i hadnt put "val" to all the right places, but its just displaying "no mortgage" to every DOB entered!!! :o

K.... let me know how it turns out.

nope!! i noticed at 1st i hadnt put "val" to all the right places, but its just displaying "no mortgage" to every DOB entered!!! ??

this line: If thisyear - cmbDOB > 1955 will NEVER be true (2005 - anything in the 1900's)
what you need to do, is NOT compare by year... compare by the subtracted number. instead of thisyear - cmbdob > 1955, use your table:

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

age = 2005 - 1995 right? Age is 10 now..... so you can say
if age < 18 then.... we know it is, because the kid is 10, but you are comparing to whole dates. So like if 2005 - 1995 (which is ten) > 1955. The comparison, in english, says "if the age is greater than 1955 then." I wouldn't ever want to live to be 1955... I'll be honest. 70 is pushing it for me :)

Test it by age, not year.

age = thisyear - val(cmbdob.text)
if age > 50 then
     ' they are over 50
elseif age < 50 and age > 40 then
     ' between 40 and 50
end if

What do you think?

err ...i fink you knw wot you mean,bt im a bit confused by everthin u jus sed!!sorry! :o does the

age = thisyear - val(cmbdob.text)

go where ive put it...as it underlines "age" everywhere:


Private Sub btnMortgage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMortgage.Click
Dim thisyear As Integer = 2005


age = thisyear - Val(cmbDOB.Text)
If age > 50 Then
lblMortgage.Text = ("You maximum morgage years are 15")
ElseIf age <= 50 And age >= 40 Then
' between 40 and 50
lblMortgage.Text = ("You maximum morgage years are 20")
ElseIf age <= 40 And age >= 30 Then
lblMortgage.Text = ("You maximum morgage years are 25")
ElseIf age <= 30 And age >= 18 Then
lblMortgage.Text = ("You maximum morgage years are 30")
ElseIf age < 18 Then
lblMortgage.Text = ("You are to young to get a morgage")
End If

thanks :confused:

I'm guessing you have an "option explicit" specified somewhere. If that's the case then age is not defined.... you'll need to DIM age as integer, first, or Remove Options Explcit. ;)

A better explaination of what is going on is this...
You need to know the person's age. That's what's in the table. The person's age. So, you figure out the person's age, by taking today's year, and subtracting that other year, right? Ok, So, We've got the person's age. Now, we need to test the conditions.... is the person older than 50... etc, etc.

:( this is wot iv done from the help uv given me, but now its not displaying anything in the label, please help!!!!?? :?: :

Private Sub cmbDOB_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
Dim thisyear As Integer = 2005
Dim age As Integer


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

;)

wel iv gt it partly workn now- its displayying the max mortgage but in the wrong places!! it says "20 years" for all the DOB entered between 1940- 1965?? and "25 years" from 1966 to 1974!!! and so on.... this is the code iv wrote from the help "comotose" gave me! anyone help to y its not quite workin:

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


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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.