Question: I've been stuck on this for a while and I really need help to understand this program. Programming problem: In the Chap07 folder of the
I've been stuck on this for a while and I really need help to understand this program.
Programming problem:
In the Chap07 folder of the Student Sample Programs, you will find a file named ChargeAccounts.txt. The file contains a list of a company's vaild charge account numbers. There are a total of 18 charge account numbers in the file, and each one is a 7-digit number, such as 5658845.
Code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO;
namespace Program7_3 { public partial class frmChargeAccount : Form { public frmChargeAccount() { InitializeComponent(); }
const int SIZE = 18; string[] acct= new string[SIZE];
private void Form1_Load(object sender, EventArgs e) { //Read the accounts from a disk file named ChargeAccounts.txt into an array named acct or a List. //Remember the Try statement since you are working with a disk file. StreamReader inputFile;
try { inputFile = File.OpenText("ChargeAccounts.txt");
int intIndex = 0; string strAccountNum = "";
while (!inputFile.EndOfStream==true) { strAccountNum = inputFile.ReadLine();
//put strAccountNum into an array element
intIndex++; } inputFile.Close(); } catch { MessageBox.Show("Problem with disk file."); } }
private void btnCheck_Click(object sender, EventArgs e) { //Iterate through the array or list to see if the account number entered in //the Textbox control is a valid number or not. Display an appropriate message within the lblMessage label.
} } }
Design:

program73 Enter a charge account: d Check
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
