-
February 15th, 2011, 03:08 AM
#1
Employee Class single error identification
I'm currently taking a newbie VB course (online) and in this program that I am writing, I am getting one error (red) that when double clicked in the Error List, takes me to the Application.Designer window and states that "Employee is a type in 'WindowsApplication1' and cannot be used as an expression." The only solution it gives me is to generate the Employee Class (in the designer). When I select that, it gives me 3 more errors (all yellow). The Employee class has been made, so I don't really know where else to go from here. Could anyone point me in the right direction? Below is the code, in case it helps. I appreciate the help.
Code:
Option Strict On
Public Class Employee
Private firstName As String ' employee first name
Private lastName As String ' employee last name
Private employee1MonthlySalary As Integer = 5000 ' employee 1 monthly salary
Private employee2MonthlySalary As Integer = 4000 ' employee 2 monthly salary
Public Sub New(ByVal first As String, ByVal last As String)
firstName = first
lastName = last
End Sub
Public ReadOnly Property First() As String
Get
Return firstName
End Get
End Property
Public ReadOnly Property Last() As String
Get
Return lastName
End Get
End Property
Private Sub Employee_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim salary1 As Integer ' Employee 1 Yearly Salary calculation
Dim salary2 As Integer ' Employee 2 Yearly Salary calculation
Dim raise1Salary As Integer ' Employee 1 Yearly Salary with 10% raise
Dim raise2Salary As Integer ' Employee 2 Yearly Salary with 10% raise
salary1 = employee1MonthlySalary * 12
salary2 = employee2MonthlySalary * 12
raise1Salary = CInt(employee1MonthlySalary * 1.1)
raise2Salary = CInt(employee2MonthlySalary * 1.1)
If employee1MonthlySalary < 0 Then
Throw New ArgumentOutOfRangeException
MessageBox.Show("Employee 1's salary amount must be greater than zero.", "Out of Range", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
If employee2MonthlySalary < 0 Then
Throw New ArgumentOutOfRangeException
MessageBox.Show("Employee 2's salary amount must be greater than zero.", "Out of Range", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Dim employee1 As New Employee("John", "Doe")
outputTextBox.AppendText("Employee 1: " & employee1.First & " " & employee1.Last & " - " & "Yearly salary: " & salary1 & vbCrLf)
Dim employee2 As New Employee("Jane", "Doe")
outputTextBox.AppendText("Employee 2: " & employee2.First & " " & employee2.Last & " - " & "Yearly salary: " & salary2 & vbCrLf)
outputTextBox.AppendText(vbCrLf & "Yearly salary adjusted for 10% increase" & vbCrLf)
outputTextBox.AppendText("Employee 1: " & employee1.First & " " & employee1.Last & " - " & "Yearly salary: " & raise1Salary & vbCrLf)
outputTextBox.AppendText("Employee 2: " & employee2.First & " " & employee2.Last & " - " & "Yearly salary: " & raise2Salary & vbCrLf)
End Sub
End Class
-
February 15th, 2011, 07:55 AM
#2
Re: Employee Class single error identification
You are trying to create instances of your class within the class.
Code:
Dim employee1 As New Employee("John", "Doe")
outputTextBox.AppendText("Employee 1: " & employee1.First & " " & employee1.Last & " - " & "Yearly salary: " & salary1 & vbCrLf)
Dim employee2 As New Employee("Jane", "Doe")
outputTextBox.AppendText("Employee 2: " & employee2.First & " " & employee2.Last & " - " & "Yearly salary: " & salary2 & vbCrLf)
outputTextBox.AppendText(vbCrLf & "Yearly salary adjusted for 10% increase" & vbCrLf)
outputTextBox.AppendText("Employee 1: " & employee1.First & " " & employee1.Last & " - " & "Yearly salary: " & raise1Salary & vbCrLf)
outputTextBox.AppendText("Employee 2: " & employee2.First & " " & employee2.Last & " - " & "Yearly salary: " & raise2Salary & vbCrLf)
This code needs to be somewhere else.
Always use [code][/code] tags when posting code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|