harp Chapter 7 P: 6 Boys and Girls Name search Name Search for boys name from a text file called Boys names. Need to display if it is a popular name, and what postion it is in. I have only written code for a boy search and have not coded the postion text box let. I can't get anything to display in the NameSearchText box ?? using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Search_Names_B_and_G { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void searchNameButton_Click(object sender, EventArgs e) {
C Sharp Chapter 7 P: 6 Boys and Girls Name search
Name Search for boys name from a text file called Boys names. Need to display if it is a popular name, and what postion it is in. I have only written code for a boy search and have not coded the postion text box let. I can't get anything to display in the NameSearchText box ??
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Search_Names_B_and_G
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void searchNameButton_Click(object sender, EventArgs e)
{
}// declare varaibles
string[] boysNames;
private void Form1_Load(object sender, EventArgs e)
{// Call the
SearchBoys_Click(sender, e);
}
private void SearchBoys_Click(object sender, EventArgs e)
{// use a try block
try
{
// Declare a StreamReader variable.
StreamReader inputFile;
// Open the file and get a StreamReader object.
inputFile = File.OpenText("C:\\Users\\shari\\OneDrive\\BoysNames.txt");//able to open txt in Visual
int namesList = 0; // varaible for the amount of names = 200
//loop executes till the end of the file
while (!inputFile.EndOfStream)
{
//Read the input from the file
inputFile.ReadLine();
//move to the next name by increment by +1
namesList++;
}
//create an array varaible for the Name List
boysNames = new string[namesList];
// Open the boys file
inputFile = File.OpenText("BoysNames.txt");
int index = 0;
//Loop executes until the end of file / Use (!) operator for bool T or F
while (index < boysNames.Length && !inputFile.EndOfStream)
{//insert buys names into the array
boysNames[index] = inputFile.ReadLine();
}
//increment the index
index++;
// Close the file
inputFile.Close();
}
catch (Exception ex)
{
//Display a message error
MessageBox.Show(ex.Message);
}
// Set search label to empty
NameSearchTextBox.Text = "";
// (!=) Not equal an empty string
if (NameSearchTextBox.Text!= "")
{// check if popular name
Boolean popularBoysName = false;
for (int i = 0; i < boysNames.Length; i++)
{
if (boysNames[i] == NameSearchTextBox.Text)
{
popularBoysName = true;
break;
}
}
//Display the name in label
if (popularBoysName == true)
{
popularTextBox.Text += NameSearchTextBox.Text + " is a popular boys name/n";
}
else
{
popularTextBox.Text += NameSearchTextBox.Text + " is not a populor buys name./n";
}
}
}
}
}
Name list , i was not able to upload the txt file
Jacob
Michael
Joshua
Matthew
Daniel
Christopher
Andrew
Ethan
Joseph
William
Anthony
David
Alexander
Nicholas
Ryan
Tyler
James
John
Jonathan
Noah
Brandon
Christian
Dylan
Samuel
Benjamin
Zachary
Nathan
Logan
Justin
Gabriel
Jose
Austin
Kevin
Elijah
Caleb
Robert
Thomas
Jordan
Cameron
Jack
Hunter
Jackson
Angel
Isaiah
Evan
Isaac
Mason
Luke
Jason
Gavin
Jayden
Aaron
Connor
Aiden
Aidan
Kyle
Juan
Charles
Luis
Adam
Lucas
Brian
Eric
Adrian
Nathaniel
Sean
Alex
Carlos
Bryan
Ian
Owen
Jesus
Landon
Julian
Chase
Cole
Diego
Jeremiah
Steven
Sebastian
Xavier
Timothy
Carter
Wyatt
Brayden
Blake
Hayden
Devin
Cody
Richard
Seth
Dominic
Jaden
Antonio
Miguel
Liam
Patrick
Carson
Jesse
Tristan
Alejandro
Henry
Victor
Trevor
Bryce
Jake
Riley
Colin
Jared
Jeremy
Mark
Caden
Garrett
Parker
Marcus
Vincent
Kaleb
Kaden
Brady
Colton
Kenneth
Joel
Oscar
Josiah
Jorge
Cooper
Ashton
Tanner
Eduardo
Paul
Edward
Ivan
Preston
Maxwell
Alan
Levi
Stephen
Grant
Nicolas
Omar
Dakota
Alexis
George
Collin
Eli
Spencer
Gage
Max
Cristian
Ricardo
Derek
Micah
Brody
Francisco
Nolan
Ayden
Dalton
Shane
Peter
Damian
Jeffrey
Brendan
Travis
Fernando
Peyton
Conner
Andres
Javier
Giovanni
Shawn
Braden
Jonah
Cesar
Bradley
Emmanuel
Manuel
Edgar
Erik
Mario
Edwin
Johnathan
Devon
Erick
Wesley
Oliver
Trenton
Hector
Malachi
Jalen
Raymond
Gregory
Abraham
Elias
Leonardo
Sergio
Donovan
Colby
Marco
Bryson
Martin
Trending now
This is a popular solution!
Step by step
Solved in 3 steps