I am currently working on a small doctors office project. The extent of my knowledge is using collections. So to premise, each doctor is allowed a maximum of 3 patients. On day 1: I need to create up to 3 patients per doctor, be able to save their information to a collection, and then save the info to patients.txt. On day 2: I need to be able to read the file, read/change the data, then save. So, know you have the gist of it. I have some class constructors set up. So here is my current code. Keep in mind, the collections are saving to patients.txt.
Main Form
Patient Class
Medical Class
Questions: I "can" save the collections to the file, however, how do I re-access the collection to view the contents? Is that possible?
Main Form
Code:
Option Explicit On
Option Strict On
Imports System.IO
Public Class MainForm
Dim patient As New Collection
Dim medical As New Collection
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim _patient As New patient
Dim _medical As New medical
txtFirst.Text = _patient.strFirst
txtLast.Text = _patient.strLast
txtAddress.Text = _patient.strAddress
txtPhone.Text = _patient.strPhone
cboInsurance.Text = _patient.strInsurance
txtPolicy.Text = _patient.strPolicy
txtCharges.Text = CStr(_patient.dblCharges)
txtInsPaid.Text = CStr(_patient.dblInsurance)
txtDue.Text = CStr(_patient.dblDue)
cboDoctors.Text = _medical.strDoctors
txtHeight.Text = _medical.StrHeight
txtWeight.Text = CStr(_medical.sngWeight)
txtAge.Text = CStr(_medical.strAge)
txtBloodPressure.Text = _medical.strBloodPressure
chkImmunizations.Text = CStr(_medical.booImmunizations)
txtPhysical.Text = _medical.strPhysical
txtGlucose.Text = CStr(_medical.sngGlucose)
End Sub
Private Sub btnNPatient_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNPatient.Click
Dim patientinfo As StreamWriter
patientinfo = File.AppendText("patients.txt")
patient.Add(txtFirst)
patient.Add(txtLast)
patient.Add(txtAddress)
patient.Add(txtPhone)
patient.Add(cboInsurance)
patient.Add(txtPolicy)
patient.Add(txtCharges)
patient.Add(txtInsPaid)
patient.Add(txtDue)
medical.Add(cboDoctors)
medical.Add(txtHeight)
medical.Add(txtWeight)
medical.Add(txtAge)
medical.Add(txtBloodPressure)
medical.Add(chkImmunizations)
medical.Add(txtPhysical)
medical.Add(txtGlucose)
patientinfo.WriteLine(patient)
patientinfo.WriteLine(medical)
patientinfo.Close()
End Sub
End Class
Code:
Option Strict On
Option Explicit On
Public Class patient
Public strFirst As String
Public strLast As String
Public strAddress As String
Public strPhone As String
Public strInsurance As String
Public strPolicy As String
Public dblCharges As Double
Public dblInsurance As Double
Public dblDue As Double
Public Sub New()
strFirst = "Unknown"
strLast = "Unknown"
strAddress = "Unknown"
strPhone = "Unknown"
strInsurance = "None"
strPolicy = "None"
dblCharges = 0.0
dblInsurance = 0.0
dblDue = 0.0
End Sub
End Class
Code:
Option Strict On
Option Explicit On
Public Class medical
Public strDoctors As String
Public StrHeight As String
Public sngWeight As Single
Public strAge As String
Public strBloodPressure As String
Public booImmunizations As Boolean
Public strPhysical As String
Public sngGlucose As Single
Public Sub New()
strDoctors = "Unassigned"
StrHeight = CStr(0)
sngWeight = 0
strAge = "Unknown"
strBloodPressure = "Not yet taken"
booImmunizations = False
strPhysical = "Unkown"
sngGlucose = 0
End Sub
End Class