Problem with consistent file creations.

KillerTomato

Member
Joined
Mar 20, 2007
Messages
6
Programming Experience
1-3
Hey yall, I am working on a POS System for a client of mine, and right now I need a little help with Employee File Creations. Below is my code, but first the problem. I AM able to creat a employee file. But after I create oen I must restarts the program to make another one. This would work great if the client only had one employee, but they dont. I've been looking at this code for the past hour and a half trying to see what I am doing wrong. Either it's because I'm tired, or I cant program, I'll let yall decide but just look at my code and tell me what I am overlooking, or what I dont have or something. Thanks

Employee Class: SaveEmployee, and EmployeeExists Sub's
VB.NET:
Imports System.IO
Module Employee

    ' Employee name Info
    Dim first = managercp.txtfirst.Text
    Dim middle = managercp.txtmiddle.Text
    Dim last = managercp.txtlast.Text
    ' Address Info
    Dim address = managercp.txtaddress.Text
    Dim city = managercp.txtcity.Text
    Dim state = managercp.txtstate.Text
    Dim zip = managercp.txtzip.Text.ToString
    ' Birthday
    Dim bday = managercp.txtbday.Text.ToString
    ' Home Phone
    Dim hphone = managercp.txthome.Text.ToString
    ' Cell Phone
    Dim cphone = managercp.txtcell.Text.ToString
    ' Social Security Number
    Dim ssn = managercp.txtssn.Text.ToString
    ' Employee Number + Employee File
    Dim number = managercp.txtnumber.Text.ToString
    ' Empty the Text Boxes



    Sub Save()
        File.WriteAllText(My.Application.Info.DirectoryPath & "\" & number & ".emp", _
        "-Employee Name Info-:" + vbCrLf _
        & first + " " & middle + " " & last + vbCrLf _
        & "-Employee Address Info-:" + vbCrLf _
        & address + vbCrLf & city + vbCrLf & state + vbCrLf & zip + vbCrLf _
        & "-Employee Info-:" + vbCrLf _
        & bday + vbCrLf & hphone + vbCrLf & cphone + vbCrLf _
        & "-Employee Social Security Number-:" + vbCrLf _
        & ssn)
        ' Clear TextBoxes
        first = ""
        middle = ""
        last = ""
        address = ""
        city = ""
        state = ""
        zip = ""
        bday = ""
        hphone = ""
        cphone = ""
        ssn = ""
        number = ""
    End Sub

    Sub EmpExists()
        MsgBox("Employee File with that number already exists. Please specify a new number, or delete the existing Employee File.", _
        MsgBoxStyle.Critical, "Employee File Error")
    End Sub

End Module

Manager Control Panel: Save/Make Employee File
VB.NET:
Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
        If My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\" & txtnumber.Text & ".emp") Then
            Employee.EmpExists()
        End If
        Employee.Save()
    End Sub

So can yall see anything? I cant but maybe it's just me. Thanks again.
 
omg, I would make an Employee class for this

and when you Dim first = managercp.txtfirst.Text, you forgot the AS String right after the Dim first

Dim first = managercp.txtfirst.Text should be:
Dim first As String= managercp.txtfirst.Text

Here's a start to the Employee class for you:
VB.NET:
Option Explicit On
Option Strict On

Friend Class Employee
  Private m_FirstName As String
  Private m_LastName As String
  private m_EmpNumber As Integer

  Public Sub New
    Call Clear()
  End Sub

  Friend Sub Clear()
    m_FirstName = ""
    m_LastName = ""
    m_EmpNumber = 0I
  End Sub

  Friend Sub Save()
    'Save data here
  End Sub

  Friend Sub Load()
    'Load emp data here
  End Sub

  Friend Property FirstName As String
    Get
      Return m_FirstName
    End get
    Set (Value As String)
      m_FirstName = Value
    End Set
  End Property

  Friend Property LastName As String
    Get
      Return m_LastName
    End get
    Set (Value As String)
      m_LastName = Value
    End Set

  Friend Property EmpNumber As Integer
    Get
      Return EmpNumber
    End get
    Set (Value As String)
      EmpNumber
    End Set
End Class

of course you'll need to expand this (and complete it) before you can use it
 
Thanks man, you was a big help.
 
Back
Top