D
duncsCsharpNewbie
Guest
I'm getting the error message I set up. It locates the file but does not perform the tasks. I am very new to this and have no idea what I am doing wrong.
Assignment Details:
Write a program that READs a file of charges for a patient’s hospital stay. The file contains two sets of records:
Record Layout - Each record is on a separate line in the Hospital Billing Data file:
I/O - Trans Code
55 - Number Of Days
2000.00 - Rate
253.91 – Charges
Sample Record:
Trans Code, Number Of Days, Rate, Charges
Note: The fields in the patient record are on individual lines in the file.
If the patient was an in-patient (I), the following data should be used:
If the patient was an out-patient (O) the following data should be used:
Note: The data file is not to be altered in any way. The points will be 0 for the assignment if altered.
For reference:
Your program should meet the following objectives:
Text File:
I
55
2000.00
253.91
I
25
1000.00
350.50
I
15
3000.00
459.30
I
100
2500.00
550.25
I
32
4000.00
850.85
I
5
9000.00
1450.95
O
0
285.00
450.99
O
0
390.00
450.99
I
14
6000.00
485.55
I
8
1500.00
650.32
I
12
6000.00
150.43
I
60
5000.00
950.65
O
0
2000.00
450.56
I
45
10000.00
450.12
O
0
1500.00
450.77
O
0
200.00
450.56
O
0
400.00
450.05
O
0
100.00
450.22
I
120
19000.00
290.99
I
2
2500.00
180.34
I
7
3000.00
360.13
I
60
12000.00
975.90
O
0
350.00
450.30
I
65
2000.00
485.55
My Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace MedicalRecordProject_Mod6
{
public partial class formMedicalBilling : Form
{
private const int y = 0;
private const int z = 0;
public formMedicalBilling()
{
InitializeComponent();
}
private void buttonRun_Click(object sender, EventArgs e)
{
//Check to see if file exists
if (File.Exists(@"C:\Users\Amanda\Desktop\CIS223\Mod6\hospbillingdata.txt"))
{
try
{
//Variables
string eachLine;
string transCode;
decimal days;
decimal rate;
decimal OPcharges;
decimal IPcharges;
decimal totalOutCharges;
decimal totalInCharges;
decimal OPCount = y; //Accumulator, set to 0
decimal IPCount = z; //Accumulator, set to 0
//Declare a StreamReader variable
StreamReader inputFile;
//Open the file and get a StreamReader object
inputFile = File.OpenText(@"C:\Users\Amanda\Desktop\CIS223\Mod6\hospbillingdata.txt");
//Read the file's contents
eachLine = inputFile.ReadLine();
//Get info for InPatient
if (eachLine == "O")
{
//Get OutPatient Info
transCode = inputFile.ReadLine();
days = decimal.Parse(inputFile.ReadLine());
rate = decimal.Parse(inputFile.ReadLine());
OPcharges = decimal.Parse(inputFile.ReadLine());
//Display OutPatient Total Records
OPCount++;
textBoxTotalOPRecords.Text = OPCount.ToString();
//Display OutPatient Total Charges
totalOutCharges = rate + OPcharges;
textBoxTotalOPCharges.Text = totalOutCharges.ToString();
//Display OutPatient to ListBox
OPlistbox.Items.Add(OPcharges);
}
else
{
//Get InPatient Info
transCode = inputFile.ReadLine();
days = decimal.Parse(inputFile.ReadLine());
rate = decimal.Parse(inputFile.ReadLine());
IPcharges = decimal.Parse(inputFile.ReadLine());
//Display InPatient Total Records
IPCount++;
textBoxTotalIPRecords.Text = IPCount.ToString();
//Display InPatient Total Charges
totalInCharges = days * rate + IPcharges;
textBoxTotalIPCharges.Text = totalInCharges.ToString();
//Display InPatient to ListBox
IPlistbox.Items.Add(IPcharges);
}
//Close the file
inputFile.Close();
}
catch
{
//Display Error Message
MessageBox.Show("An error has occured");
}
}
else
MessageBox.Show("File does not exist.");
}
private void buttonExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
Continue reading...
Assignment Details:
Write a program that READs a file of charges for a patient’s hospital stay. The file contains two sets of records:
- Patients that were admitted as an in-patient (I).
- Patients that were admitted as an outpatient (O).
Record Layout - Each record is on a separate line in the Hospital Billing Data file:
I/O - Trans Code
55 - Number Of Days
2000.00 - Rate
253.91 – Charges
Sample Record:
Trans Code, Number Of Days, Rate, Charges
Note: The fields in the patient record are on individual lines in the file.
If the patient was an in-patient (I), the following data should be used:
- The number of days spent in the hospital.
- The daily rate for hospital services.
- Hospital medication charges.
- Formula: (Days * Rate) + Charges
If the patient was an out-patient (O) the following data should be used:
- The daily rate has been included (but not used) to keep things simple in the record.
- Rate for hospital services.
- Hospital medication charges.
- Formula: Rate + Charges
Note: The data file is not to be altered in any way. The points will be 0 for the assignment if altered.
For reference:
- Use page 308 (Reading Data from a File) in your book as a guide.
- A picture of what the might look like can be downloaded.
Your program should meet the following objectives:
- The program should check to make sure the file exists before trying to read it. If it does not exist, it should display a message in a messagebox and not continue. (See video in Learning Activities.)
- Use a While loop that reads the file till EOF.
- Use StreamReader Object.
- The program should calculate and display the following:
- Total charges for each individual type of patient (I and O), then add that total to an in-patient or outpatient listbox.
- Grand Total (accumulated total charges) for number of in-patient and out-patient total charges below the listbox.
- Record a count for each number of in-patient and outpatient records and display the count below the listbox.
- Grand Total number of records read overall in a label.
Text File:
I
55
2000.00
253.91
I
25
1000.00
350.50
I
15
3000.00
459.30
I
100
2500.00
550.25
I
32
4000.00
850.85
I
5
9000.00
1450.95
O
0
285.00
450.99
O
0
390.00
450.99
I
14
6000.00
485.55
I
8
1500.00
650.32
I
12
6000.00
150.43
I
60
5000.00
950.65
O
0
2000.00
450.56
I
45
10000.00
450.12
O
0
1500.00
450.77
O
0
200.00
450.56
O
0
400.00
450.05
O
0
100.00
450.22
I
120
19000.00
290.99
I
2
2500.00
180.34
I
7
3000.00
360.13
I
60
12000.00
975.90
O
0
350.00
450.30
I
65
2000.00
485.55
My Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace MedicalRecordProject_Mod6
{
public partial class formMedicalBilling : Form
{
private const int y = 0;
private const int z = 0;
public formMedicalBilling()
{
InitializeComponent();
}
private void buttonRun_Click(object sender, EventArgs e)
{
//Check to see if file exists
if (File.Exists(@"C:\Users\Amanda\Desktop\CIS223\Mod6\hospbillingdata.txt"))
{
try
{
//Variables
string eachLine;
string transCode;
decimal days;
decimal rate;
decimal OPcharges;
decimal IPcharges;
decimal totalOutCharges;
decimal totalInCharges;
decimal OPCount = y; //Accumulator, set to 0
decimal IPCount = z; //Accumulator, set to 0
//Declare a StreamReader variable
StreamReader inputFile;
//Open the file and get a StreamReader object
inputFile = File.OpenText(@"C:\Users\Amanda\Desktop\CIS223\Mod6\hospbillingdata.txt");
//Read the file's contents
eachLine = inputFile.ReadLine();
//Get info for InPatient
if (eachLine == "O")
{
//Get OutPatient Info
transCode = inputFile.ReadLine();
days = decimal.Parse(inputFile.ReadLine());
rate = decimal.Parse(inputFile.ReadLine());
OPcharges = decimal.Parse(inputFile.ReadLine());
//Display OutPatient Total Records
OPCount++;
textBoxTotalOPRecords.Text = OPCount.ToString();
//Display OutPatient Total Charges
totalOutCharges = rate + OPcharges;
textBoxTotalOPCharges.Text = totalOutCharges.ToString();
//Display OutPatient to ListBox
OPlistbox.Items.Add(OPcharges);
}
else
{
//Get InPatient Info
transCode = inputFile.ReadLine();
days = decimal.Parse(inputFile.ReadLine());
rate = decimal.Parse(inputFile.ReadLine());
IPcharges = decimal.Parse(inputFile.ReadLine());
//Display InPatient Total Records
IPCount++;
textBoxTotalIPRecords.Text = IPCount.ToString();
//Display InPatient Total Charges
totalInCharges = days * rate + IPcharges;
textBoxTotalIPCharges.Text = totalInCharges.ToString();
//Display InPatient to ListBox
IPlistbox.Items.Add(IPcharges);
}
//Close the file
inputFile.Close();
}
catch
{
//Display Error Message
MessageBox.Show("An error has occured");
}
}
else
MessageBox.Show("File does not exist.");
}
private void buttonExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
Continue reading...