Hello,
I asked this question in the c++ forums but I've since moved the small program that I was working on over to C# Forms.
have a current file that I am opening. Each line of said file looks like this:
D40001~10997~811~DANIWEB~555-555-5555~7.70~I~2111
There are around 5000 lines with different DXXXXX numbers. I want the user to input a dnumber (DXXXXX) and have it search the file for said Dnumber and then display the name that is associated with the Dnumber. So typing in 'D40001' should display the name Daniweb. Here is my code but I've went through 5 tutorials on the net and cannot find out how to search this file and do what I want it to do. From the searching that I did do, they said that I need to parse the file and then match the DXXXXX and display the screen. I'm clueless to how to do this. Here is the code that I have so far. Also, this is not for homework. I'm too poor for school. :]
here is the code that I currently have.
namespace DealerNumberSearch
{
partial class Form1
{
///<summary>
/// Required designer variable.
///</summary>
private System.ComponentModel.IContainer components = null;
///<summary>
/// Clean up any resources being used.
///</summary>
///<param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
public void OpenFile()
{
// Try to open the file
try
{
file = new FileStream("dealers.tdl", FileMode.Open, FileAccess.Read);
}
// If file doesnt exist, throw up an error message.
catch (Exception)
{
MessageBox.Show("The file could not be found!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
}
public void SearchText()
{
stream = new StreamReader(file);
line = stream.ReadLine();
}
#region Windows Form Designer generated code
///<summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///</summary>
private void InitializeComponent()
{
this.goButton = new System.Windows.Forms.Button();
this.getNumber = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// goButton
//
this.goButton.Location = new System.Drawing.Point(201, 40);
this.goButton.Name = "goButton";
this.goButton.Size = new System.Drawing.Size(33, 20);
this.goButton.TabIndex = 0;
this.goButton.Text = "GO";
this.goButton.UseVisualStyleBackColor = true;
this.goButton.Click += new System.EventHandler(this.goButton_Click);
//
// getNumber
//
this.getNumber.Location = new System.Drawing.Point(57, 40);
this.getNumber.Name = "getNumber";
this.getNumber.Size = new System.Drawing.Size(100, 20);
this.getNumber.TabIndex = 1;
this.getNumber.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(122, 149);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 13);
this.label1.TabIndex = 3;
this.label1.Text = "label1";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.label1);
this.Controls.Add(this.getNumber);
this.Controls.Add(this.goButton);
this.Name = "Form1";
this.Text = "DNS - Dealer Number Search";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private FileStream file;
private StreamReader stream;
private string line;
private string val1;
private System.Windows.Forms.Button goButton;
private System.Windows.Forms.TextBox getNumber;
private System.Windows.Forms.Label label1;
}
}