1) Code Block One below in Blue Works, but the issue is It does not allow the user to enter a value - it is understandable because Script is in execution stat. please see my comments in the codes to better understand what i am referring to
public partial class Form1 : Form
{
private const int size = 100;
private int Count = 0;
private int[] AccountNumber = new int[size];
public Form1()
{
InitializeComponent();
}
private void ValidateButton_Click(object sender, EventArgs e)
{
try
{
// Read the values from File
StreamReader InPutFile;
InPutFile = File.OpenText(@"C:\Users\ahmadf1\Documents\C Sharp Exercises\Source Code and Chapter Tutorial Files\Chap07\ChargeAccounts.txt");
while (!InPutFile.EndOfStream && Count < AccountNumber.Length)
{
AccountNumber[Count] = int.Parse(InPutFile.ReadLine());
Count++;
}
InPutFile.Close();
//Populate values in List Box
for (int index = 0; index < AccountNumber.Length; index++)
{
DisplayListBox.Items.Add(AccountNumber[index]);
}
//Prompt the user to enter the values to be searched in the array.
MessageBox.Show("Enter a Number in the List");
//How do I make the program to allow the user Entera values.
//In this sequence it does not, scripts keep executing after MessageBox prompt is acknowledged.
// If i enter the value before executing the whole script, then the logic below works.
int InputNumber;
if (int.TryParse(NumbertextBox.Text, out InputNumber))
{
MessageBox.Show(InputNumber.ToString());
for (int index = 0; index < Count; index++)
{
MessageBox.Show(AccountNumber[index].ToString());
if (InputNumber == AccountNumber[index])
{
MessageBox.Show("Number is Valid");
}
else
{
MessageBox.Show("Number is not Valid");
}
}
}
else if (NumbertextBox.Text == "")
{
MessageBox.Show("No Value is Entered");
}
else
{
MessageBox.Show("Invalid Data Type");
}
}
catch
{
MessageBox.Show("Something is Wrong");
}
}
public partial class Form1 : Form
{
private const int size = 100;
private int Count = 0;
private int[] AccountNumber = new int[size];
public Form1()
{
InitializeComponent();
}
private void ValidateButton_Click(object sender, EventArgs e)
{
try
{
// Read the values from File
StreamReader InPutFile;
InPutFile = File.OpenText(@"C:\Users\ahmadf1\Documents\C Sharp Exercises\Source Code and Chapter Tutorial Files\Chap07\ChargeAccounts.txt");
while (!InPutFile.EndOfStream && Count < AccountNumber.Length)
{
AccountNumber[Count] = int.Parse(InPutFile.ReadLine());
Count++;
}
InPutFile.Close();
//Populate values in List Box
for (int index = 0; index < AccountNumber.Length; index++)
{
DisplayListBox.Items.Add(AccountNumber[index]);
}
//Prompt the user to enter the values to be searched in the array.
MessageBox.Show("Enter a Number in the List");
private void FindNumberButton_Click(object sender, EventArgs e)
{
int InputNumber;
if (int.TryParse(NumbertextBox.Text, out InputNumber))
{
MessageBox.Show(InputNumber.ToString());
for (int index=0; index<Count; index++)
{
MessageBox.Show(AccountNumber[index].ToString());
if(InputNumber == AccountNumber[index])
{
MessageBox.Show("Number is Valid");
}
else
{
MessageBox.Show("Number is not Valid");
}
}
}
else if (NumbertextBox.Text == "")
{
MessageBox.Show("No Value is Entered");
}
else
{
MessageBox.Show("Invalid Data Type");
}
}
}
}