I'm following the book Visual Basic 2012 How to Program
I've created a very simple class :
If I delete the line with the comment <-- this one I get "0 year income", as expected.
But with the line I should get "positive" But I get this error message seen below :
Image may be NSFW.
Clik here to view.![Name: IMG_1916.jpg
Views: 77
Size: 34.8 KB]()
Here is the exercise question :
9.7 (Employee Class) Create a class called Employee that includes three pieces of information as
instance variablesa first name (type String), a last name (type String) and a monthly salary (type
Integer). Your class should have a constructor that initializes the three instance variables. Provide
a property for each instance variable. The property for the monthly salary should ensure that its value remains positiveif an attempt is made to assign a negative value, throw an exception. Write an
app that demonstrates class Employees capabilities. Create two Employee objects and display each
objects yearly salary. Then give each Employee a 10% raise and display each Employees yearly salary
again.
Is it a bug in Visual Studio don't think so. But my book explains it so it should work!
Shed some light on this one you guys !
I've created a very simple class :
Code:
Public Class Form1
Dim First As Employee = New Employee
Dim Second As Employee = New Employee
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
First.FirstName = "John"
First.LastName = "Henderson"
First.MonthlySalary = 0
MessageBox.Show(First.MonthlySalary * 12 & " Year income")
MessageBox.Show((First.MonthlySalary * 12) * 1.1 & " Year income with 10 % raise")
Second.firstname = "Billy"
Second.lastname = "The Kid"
Second.MonthlySalary = 1500
MessageBox.Show(Second.MonthlySalary * 12 & " Year income")
MessageBox.Show((Second.MonthlySalary * 12) * 1.1 & " Year income with 10 % raise")
End Sub
End Class
Code:
Public Class Employee
Private _FirstName As String
Private _LastName As String
Private _MonthlySalary As Integer
Public Sub New()
_FirstName = "test"
_LastName = "test"
_MonthlySalary = 1
End Sub
Public Property FirstName As String
Get
Return _FirstName
End Get
Set(value As String)
_FirstName = value
End Set
End Property
Public Property LastName As String
Get
Return _LastName
End Get
Set(value As String)
_LastName = value
End Set
End Property
Public Property MonthlySalary As Integer
Get
Return _MonthlySalary
End Get
Set(value As Integer)
If value <= 0 Then
Throw New ArgumentOutOfRangeException("positive") '<_-------this one
End If
_MonthlySalary = value
End Set
End Property
End Class
But with the line I should get "positive" But I get this error message seen below :
Image may be NSFW.
Clik here to view.
Here is the exercise question :
9.7 (Employee Class) Create a class called Employee that includes three pieces of information as
instance variablesa first name (type String), a last name (type String) and a monthly salary (type
Integer). Your class should have a constructor that initializes the three instance variables. Provide
a property for each instance variable. The property for the monthly salary should ensure that its value remains positiveif an attempt is made to assign a negative value, throw an exception. Write an
app that demonstrates class Employees capabilities. Create two Employee objects and display each
objects yearly salary. Then give each Employee a 10% raise and display each Employees yearly salary
again.
Is it a bug in Visual Studio don't think so. But my book explains it so it should work!
Shed some light on this one you guys !