Simple Constructor Question

skiman62

Newcomer
Joined
Oct 8, 2003
Messages
2
Hello all, this is my first post to these boards though I have been using them as a resource for a couple of months now. I am taking my first programming class and I have a question. I have created a class called EmployeeList I need to create a method via the constructor that accepts one argument:The name of a sequential file to read. As it reads the file it will populate an array of Employee structures that is hidden from the developer. Here is what I have so far..not much, but damn IO confuses me almost as much as dynamic arrays do..Thanks in advance for the help
Option Explicit On
Option Strict On

Imports System.Convert
Imports System.IO




Namespace Employees



Public Class EmployeeList
Public Structure Employee
Public ID As Integer
Public LastName As String
Public FirstName As String
Public SSN As String
Public HourlyWage As Double
Public HoursWorked As Double

Public Function FullName() As String
Return FirstName & " " & LastName
End Function

Public Function Pay() As Double
Return HourlyWage * HoursWorked
End Function
End Structure
Private SampleRecord() As Employee
End Class
 
You can make a constructor for your class like this:
Visual Basic:
'constructor is always callled New
Public Sub New(ByVal filepath As String) 'Accept a string that will contain the path
'do something with the file
End Sub
Also if you need an array that needs to change size dynamically you could consider using an ArrayList, in which you can put any object and expand it as you need to.
 
I was actually going in the right direction!

Thanks a bunch for the advice. I read ahead a bit and found out a little bit bout Array Lists. They seem so much more robust/useful for my purpose. Still dont have all the syntax down pat but at least I wont look like a total bufoon when I go to get help from my professor. Can anyone recommend a vb.net syntax book?
 
I wouldnt recommend a book on syntax as much as a book that covers the Framework itself. If you want to lean about the syntax then simply reading several pages from MSDN collection will get you up and running with the syntax,
 
Back
Top