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
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
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 =
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
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?
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
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.
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
K.... let me know how it turns out.
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
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?
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
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.
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215