Solved

file read in as a string and divide into Date form C#

Posted on 2006-10-24
2
301 Views
Last Modified: 2010-04-16
I am writing a GUI program in C#.  The program reads in a file using the "split" format.  I read in a string date = split[0];  When it is read in the string is set to 05 06 06.  I need to now take that string which is done in a method in the "Main" file and transfer it to another class that accept a string and divide it to month, day, and year. And also override the ToString() method to print it as mm/dd/yy.  I don't know how to take that string date from the method and transfer it to another class and then also how to convert it into the date formate as listed above

Below is the Form1.cs class which reads in the file

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;


namespace WindowsApplication2
{
      [Serializable]
      public class Form1 : System.Windows.Forms.Form
      {
            private System.Windows.Forms.Label label1;
            private System.Windows.Forms.Label label2;
            private System.Windows.Forms.TextBox saledate;
            private System.Windows.Forms.Button button1;
            private System.Windows.Forms.GroupBox groupBox1;
            private System.Windows.Forms.Label label3;
            private System.Windows.Forms.Label label4;
            private System.Windows.Forms.Label label5;
            private System.Windows.Forms.Label label6;
            private System.Windows.Forms.Label label7;
            private System.Windows.Forms.Label label8;
            private System.Windows.Forms.Label label9;
            private System.Windows.Forms.TextBox textBox2;
            private System.Windows.Forms.TextBox maker;
            private System.Windows.Forms.TextBox model;
            private System.Windows.Forms.TextBox year;
            private System.Windows.Forms.TextBox textBox6;
            private System.Windows.Forms.TextBox mileage;
            private System.Windows.Forms.TextBox price;
            private System.Windows.Forms.GroupBox customerinformation;
            private System.Windows.Forms.Label label10;
            private System.Windows.Forms.Label label11;
            private System.Windows.Forms.Label label12;
            private System.Windows.Forms.TextBox id;
            private System.Windows.Forms.TextBox name;
            private System.Windows.Forms.TextBox address;
            private System.Windows.Forms.Label label13;
            private System.Windows.Forms.Label label14;
            private System.Windows.Forms.Label label15;
            private System.Windows.Forms.Label label16;
            private System.Windows.Forms.TextBox textBox4;
            private System.Windows.Forms.TextBox idnumber;
            private System.Windows.Forms.TextBox expdate;
            private System.Windows.Forms.Label label17;
            private System.Windows.Forms.Label label18;
            private System.Windows.Forms.Label label19;
            private System.Windows.Forms.Label label20;
            private System.Windows.Forms.Label label21;
            private System.Windows.Forms.Label label23;
            private System.Windows.Forms.Label label24;
            private System.Windows.Forms.Label label25;
            private System.Windows.Forms.Label label27;
            private System.Windows.Forms.Label label28;
            private System.Windows.Forms.Label label29;
            private System.Windows.Forms.Label label30;
            private System.Windows.Forms.TextBox textBox7;
            private System.Windows.Forms.TextBox textBox8;
            private System.Windows.Forms.TextBox textBox9;
            private System.Windows.Forms.TextBox textBox10;
            private System.Windows.Forms.GroupBox borrowedamount;
            private System.Windows.Forms.TextBox downpayment;
            private System.Windows.Forms.TextBox taxamount;
            private System.Windows.Forms.TextBox numberofmonths;
            private System.Windows.Forms.TextBox monthlypayment;
            private System.Windows.Forms.TextBox taxrate;
            private System.Windows.Forms.TextBox interestrate;
            private System.Windows.Forms.TextBox recordnumber;
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.Container components = null;

            public Form1()
            {
                  //
                  // Required for Windows Form Designer support
                  //
                  InitializeComponent();

                  //
                  // TODO: Add any constructor code after InitializeComponent call
                  //
            }

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if (components != null)
                        {
                              components.Dispose();
                        }
                  }
                  base.Dispose( disposing );
            }

            #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.label1 = new System.Windows.Forms.Label();
                  this.label2 = new System.Windows.Forms.Label();
                  this.recordnumber = new System.Windows.Forms.TextBox();
                  this.saledate = new System.Windows.Forms.TextBox();
                  this.button1 = new System.Windows.Forms.Button();
                  this.groupBox1 = new System.Windows.Forms.GroupBox();
                  this.price = new System.Windows.Forms.TextBox();
                  this.mileage = new System.Windows.Forms.TextBox();
                  this.textBox6 = new System.Windows.Forms.TextBox();
                  this.year = new System.Windows.Forms.TextBox();
                  this.model = new System.Windows.Forms.TextBox();
                  this.maker = new System.Windows.Forms.TextBox();
                  this.textBox2 = new System.Windows.Forms.TextBox();
                  this.label9 = new System.Windows.Forms.Label();
                  this.label8 = new System.Windows.Forms.Label();
                  this.label7 = new System.Windows.Forms.Label();
                  this.label6 = new System.Windows.Forms.Label();
                  this.label5 = new System.Windows.Forms.Label();
                  this.label4 = new System.Windows.Forms.Label();
                  this.label3 = new System.Windows.Forms.Label();
                  this.customerinformation = new System.Windows.Forms.GroupBox();
                  this.expdate = new System.Windows.Forms.TextBox();
                  this.textBox4 = new System.Windows.Forms.TextBox();
                  this.idnumber = new System.Windows.Forms.TextBox();
                  this.label16 = new System.Windows.Forms.Label();
                  this.label15 = new System.Windows.Forms.Label();
                  this.label14 = new System.Windows.Forms.Label();
                  this.label13 = new System.Windows.Forms.Label();
                  this.address = new System.Windows.Forms.TextBox();
                  this.name = new System.Windows.Forms.TextBox();
                  this.id = new System.Windows.Forms.TextBox();
                  this.label12 = new System.Windows.Forms.Label();
                  this.label11 = new System.Windows.Forms.Label();
                  this.label10 = new System.Windows.Forms.Label();
                  this.borrowedamount = new System.Windows.Forms.GroupBox();
                  this.interestrate = new System.Windows.Forms.TextBox();
                  this.taxrate = new System.Windows.Forms.TextBox();
                  this.monthlypayment = new System.Windows.Forms.TextBox();
                  this.numberofmonths = new System.Windows.Forms.TextBox();
                  this.textBox10 = new System.Windows.Forms.TextBox();
                  this.textBox9 = new System.Windows.Forms.TextBox();
                  this.textBox8 = new System.Windows.Forms.TextBox();
                  this.textBox7 = new System.Windows.Forms.TextBox();
                  this.taxamount = new System.Windows.Forms.TextBox();
                  this.downpayment = new System.Windows.Forms.TextBox();
                  this.label30 = new System.Windows.Forms.Label();
                  this.label29 = new System.Windows.Forms.Label();
                  this.label28 = new System.Windows.Forms.Label();
                  this.label25 = new System.Windows.Forms.Label();
                  this.label24 = new System.Windows.Forms.Label();
                  this.label20 = new System.Windows.Forms.Label();
                  this.label18 = new System.Windows.Forms.Label();
                  this.label17 = new System.Windows.Forms.Label();
                  this.label19 = new System.Windows.Forms.Label();
                  this.label21 = new System.Windows.Forms.Label();
                  this.label23 = new System.Windows.Forms.Label();
                  this.label27 = new System.Windows.Forms.Label();
                  this.groupBox1.SuspendLayout();
                  this.customerinformation.SuspendLayout();
                  this.borrowedamount.SuspendLayout();
                  this.SuspendLayout();
                  //
                  // label1
                  //
                  this.label1.Location = new System.Drawing.Point(16, 24);
                  this.label1.Name = "label1";
                  this.label1.Size = new System.Drawing.Size(88, 16);
                  this.label1.TabIndex = 0;
                  this.label1.Text = "Record Number:";
                  //
                  // label2
                  //
                  this.label2.Location = new System.Drawing.Point(16, 64);
                  this.label2.Name = "label2";
                  this.label2.Size = new System.Drawing.Size(64, 16);
                  this.label2.TabIndex = 1;
                  this.label2.Text = "Sale Date:";
                  //
                  // recordnumber
                  //
                  this.recordnumber.Location = new System.Drawing.Point(120, 24);
                  this.recordnumber.Name = "recordnumber";
                  this.recordnumber.Size = new System.Drawing.Size(104, 20);
                  this.recordnumber.TabIndex = 2;
                  this.recordnumber.Text = "";
                  this.recordnumber.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
                  //
                  // saledate
                  //
                  this.saledate.Location = new System.Drawing.Point(120, 64);
                  this.saledate.Name = "saledate";
                  this.saledate.Size = new System.Drawing.Size(104, 20);
                  this.saledate.TabIndex = 3;
                  this.saledate.Text = "";
                  //
                  // button1
                  //
                  this.button1.Location = new System.Drawing.Point(72, 112);
                  this.button1.Name = "button1";
                  this.button1.Size = new System.Drawing.Size(128, 40);
                  this.button1.TabIndex = 4;
                  this.button1.Text = "Next";
                  this.button1.Click += new System.EventHandler(this.button1_Click);
                  //
                  // groupBox1
                  //
                  this.groupBox1.Controls.Add(this.price);
                  this.groupBox1.Controls.Add(this.mileage);
                  this.groupBox1.Controls.Add(this.textBox6);
                  this.groupBox1.Controls.Add(this.year);
                  this.groupBox1.Controls.Add(this.model);
                  this.groupBox1.Controls.Add(this.maker);
                  this.groupBox1.Controls.Add(this.textBox2);
                  this.groupBox1.Controls.Add(this.label9);
                  this.groupBox1.Controls.Add(this.label8);
                  this.groupBox1.Controls.Add(this.label7);
                  this.groupBox1.Controls.Add(this.label6);
                  this.groupBox1.Controls.Add(this.label5);
                  this.groupBox1.Controls.Add(this.label4);
                  this.groupBox1.Controls.Add(this.label3);
                  this.groupBox1.Location = new System.Drawing.Point(16, 168);
                  this.groupBox1.Name = "groupBox1";
                  this.groupBox1.Size = new System.Drawing.Size(256, 344);
                  this.groupBox1.TabIndex = 5;
                  this.groupBox1.TabStop = false;
                  this.groupBox1.Text = "Car Information";
                  //
                  // price
                  //
                  this.price.Location = new System.Drawing.Point(112, 312);
                  this.price.Name = "price";
                  this.price.Size = new System.Drawing.Size(128, 20);
                  this.price.TabIndex = 14;
                  this.price.Text = "";
                  //
                  // mileage
                  //
                  this.mileage.Location = new System.Drawing.Point(112, 264);
                  this.mileage.Name = "mileage";
                  this.mileage.Size = new System.Drawing.Size(128, 20);
                  this.mileage.TabIndex = 13;
                  this.mileage.Text = "";
                  //
                  // textBox6
                  //
                  this.textBox6.Location = new System.Drawing.Point(112, 216);
                  this.textBox6.Name = "textBox6";
                  this.textBox6.Size = new System.Drawing.Size(128, 20);
                  this.textBox6.TabIndex = 12;
                  this.textBox6.Text = "";
                  //
                  // year
                  //
                  this.year.Location = new System.Drawing.Point(112, 168);
                  this.year.Name = "year";
                  this.year.Size = new System.Drawing.Size(128, 20);
                  this.year.TabIndex = 11;
                  this.year.Text = "";
                  //
                  // model
                  //
                  this.model.Location = new System.Drawing.Point(112, 120);
                  this.model.Name = "model";
                  this.model.Size = new System.Drawing.Size(128, 20);
                  this.model.TabIndex = 10;
                  this.model.Text = "";
                  //
                  // maker
                  //
                  this.maker.Location = new System.Drawing.Point(112, 72);
                  this.maker.Name = "maker";
                  this.maker.Size = new System.Drawing.Size(128, 20);
                  this.maker.TabIndex = 9;
                  this.maker.Text = "";
                  //
                  // textBox2
                  //
                  this.textBox2.Location = new System.Drawing.Point(112, 32);
                  this.textBox2.Name = "textBox2";
                  this.textBox2.Size = new System.Drawing.Size(128, 20);
                  this.textBox2.TabIndex = 8;
                  this.textBox2.Text = "";
                  //
                  // label9
                  //
                  this.label9.Location = new System.Drawing.Point(8, 312);
                  this.label9.Name = "label9";
                  this.label9.Size = new System.Drawing.Size(40, 16);
                  this.label9.TabIndex = 7;
                  this.label9.Text = "Price:";
                  //
                  // label8
                  //
                  this.label8.Location = new System.Drawing.Point(8, 272);
                  this.label8.Name = "label8";
                  this.label8.Size = new System.Drawing.Size(48, 16);
                  this.label8.TabIndex = 6;
                  this.label8.Text = "Mileage:";
                  //
                  // label7
                  //
                  this.label7.Location = new System.Drawing.Point(8, 224);
                  this.label7.Name = "label7";
                  this.label7.Size = new System.Drawing.Size(40, 16);
                  this.label7.TabIndex = 5;
                  this.label7.Text = "Color:";
                  //
                  // label6
                  //
                  this.label6.Location = new System.Drawing.Point(8, 176);
                  this.label6.Name = "label6";
                  this.label6.Size = new System.Drawing.Size(40, 16);
                  this.label6.TabIndex = 4;
                  this.label6.Text = "Year:";
                  //
                  // label5
                  //
                  this.label5.Location = new System.Drawing.Point(8, 128);
                  this.label5.Name = "label5";
                  this.label5.Size = new System.Drawing.Size(40, 16);
                  this.label5.TabIndex = 3;
                  this.label5.Text = "Model:";
                  //
                  // label4
                  //
                  this.label4.Location = new System.Drawing.Point(8, 80);
                  this.label4.Name = "label4";
                  this.label4.Size = new System.Drawing.Size(40, 16);
                  this.label4.TabIndex = 2;
                  this.label4.Text = "Maker:";
                  //
                  // label3
                  //
                  this.label3.Location = new System.Drawing.Point(8, 32);
                  this.label3.Name = "label3";
                  this.label3.Size = new System.Drawing.Size(88, 16);
                  this.label3.TabIndex = 1;
                  this.label3.Text = "Stock Number:";
                  //
                  // customerinformation
                  //
                  this.customerinformation.Controls.Add(this.expdate);
                  this.customerinformation.Controls.Add(this.textBox4);
                  this.customerinformation.Controls.Add(this.idnumber);
                  this.customerinformation.Controls.Add(this.label16);
                  this.customerinformation.Controls.Add(this.label15);
                  this.customerinformation.Controls.Add(this.label14);
                  this.customerinformation.Controls.Add(this.label13);
                  this.customerinformation.Controls.Add(this.address);
                  this.customerinformation.Controls.Add(this.name);
                  this.customerinformation.Controls.Add(this.id);
                  this.customerinformation.Controls.Add(this.label12);
                  this.customerinformation.Controls.Add(this.label11);
                  this.customerinformation.Controls.Add(this.label10);
                  this.customerinformation.Location = new System.Drawing.Point(288, 8);
                  this.customerinformation.Name = "customerinformation";
                  this.customerinformation.Size = new System.Drawing.Size(528, 216);
                  this.customerinformation.TabIndex = 6;
                  this.customerinformation.TabStop = false;
                  this.customerinformation.Text = "Customer Information";
                  //
                  // expdate
                  //
                  this.expdate.Location = new System.Drawing.Point(344, 160);
                  this.expdate.Name = "expdate";
                  this.expdate.Size = new System.Drawing.Size(152, 20);
                  this.expdate.TabIndex = 12;
                  this.expdate.Text = "";
                  //
                  // textBox4
                  //
                  this.textBox4.Location = new System.Drawing.Point(344, 104);
                  this.textBox4.Name = "textBox4";
                  this.textBox4.Size = new System.Drawing.Size(152, 20);
                  this.textBox4.TabIndex = 11;
                  this.textBox4.Text = "";
                  //
                  // idnumber
                  //
                  this.idnumber.Location = new System.Drawing.Point(344, 56);
                  this.idnumber.Name = "idnumber";
                  this.idnumber.Size = new System.Drawing.Size(152, 20);
                  this.idnumber.TabIndex = 10;
                  this.idnumber.Text = "";
                  //
                  // label16
                  //
                  this.label16.Location = new System.Drawing.Point(256, 160);
                  this.label16.Name = "label16";
                  this.label16.Size = new System.Drawing.Size(64, 24);
                  this.label16.TabIndex = 9;
                  this.label16.Text = "Exp. Date:";
                  //
                  // label15
                  //
                  this.label15.Location = new System.Drawing.Point(256, 112);
                  this.label15.Name = "label15";
                  this.label15.Size = new System.Drawing.Size(40, 24);
                  this.label15.TabIndex = 8;
                  this.label15.Text = "State:";
                  //
                  // label14
                  //
                  this.label14.Location = new System.Drawing.Point(256, 56);
                  this.label14.Name = "label14";
                  this.label14.Size = new System.Drawing.Size(64, 24);
                  this.label14.TabIndex = 7;
                  this.label14.Text = "ID Number:";
                  //
                  // label13
                  //
                  this.label13.Location = new System.Drawing.Point(240, 24);
                  this.label13.Name = "label13";
                  this.label13.Size = new System.Drawing.Size(128, 16);
                  this.label13.TabIndex = 6;
                  this.label13.Text = "Licence Information:";
                  //
                  // address
                  //
                  this.address.Location = new System.Drawing.Point(72, 168);
                  this.address.Name = "address";
                  this.address.Size = new System.Drawing.Size(160, 20);
                  this.address.TabIndex = 5;
                  this.address.Text = "";
                  //
                  // name
                  //
                  this.name.Location = new System.Drawing.Point(72, 112);
                  this.name.Name = "name";
                  this.name.Size = new System.Drawing.Size(160, 20);
                  this.name.TabIndex = 4;
                  this.name.Text = "";
                  //
                  // id
                  //
                  this.id.Location = new System.Drawing.Point(72, 56);
                  this.id.Name = "id";
                  this.id.Size = new System.Drawing.Size(160, 20);
                  this.id.TabIndex = 3;
                  this.id.Text = "";
                  //
                  // label12
                  //
                  this.label12.Location = new System.Drawing.Point(8, 168);
                  this.label12.Name = "label12";
                  this.label12.Size = new System.Drawing.Size(56, 16);
                  this.label12.TabIndex = 2;
                  this.label12.Text = "Address:";
                  //
                  // label11
                  //
                  this.label11.Location = new System.Drawing.Point(16, 112);
                  this.label11.Name = "label11";
                  this.label11.Size = new System.Drawing.Size(40, 16);
                  this.label11.TabIndex = 1;
                  this.label11.Text = "Name:";
                  //
                  // label10
                  //
                  this.label10.Location = new System.Drawing.Point(16, 56);
                  this.label10.Name = "label10";
                  this.label10.Size = new System.Drawing.Size(24, 16);
                  this.label10.TabIndex = 0;
                  this.label10.Text = "ID:";
                  //
                  // borrowedamount
                  //
                  this.borrowedamount.Controls.Add(this.interestrate);
                  this.borrowedamount.Controls.Add(this.taxrate);
                  this.borrowedamount.Controls.Add(this.monthlypayment);
                  this.borrowedamount.Controls.Add(this.numberofmonths);
                  this.borrowedamount.Controls.Add(this.textBox10);
                  this.borrowedamount.Controls.Add(this.textBox9);
                  this.borrowedamount.Controls.Add(this.textBox8);
                  this.borrowedamount.Controls.Add(this.textBox7);
                  this.borrowedamount.Controls.Add(this.taxamount);
                  this.borrowedamount.Controls.Add(this.downpayment);
                  this.borrowedamount.Controls.Add(this.label30);
                  this.borrowedamount.Controls.Add(this.label29);
                  this.borrowedamount.Controls.Add(this.label28);
                  this.borrowedamount.Controls.Add(this.label25);
                  this.borrowedamount.Controls.Add(this.label24);
                  this.borrowedamount.Controls.Add(this.label20);
                  this.borrowedamount.Controls.Add(this.label18);
                  this.borrowedamount.Controls.Add(this.label17);
                  this.borrowedamount.Controls.Add(this.label19);
                  this.borrowedamount.Controls.Add(this.label21);
                  this.borrowedamount.Controls.Add(this.label23);
                  this.borrowedamount.Controls.Add(this.label27);
                  this.borrowedamount.Location = new System.Drawing.Point(288, 240);
                  this.borrowedamount.Name = "borrowedamount";
                  this.borrowedamount.Size = new System.Drawing.Size(528, 272);
                  this.borrowedamount.TabIndex = 7;
                  this.borrowedamount.TabStop = false;
                  this.borrowedamount.Text = "Load Information";
                  //
                  // interestrate
                  //
                  this.interestrate.Location = new System.Drawing.Point(368, 216);
                  this.interestrate.Name = "interestrate";
                  this.interestrate.Size = new System.Drawing.Size(128, 20);
                  this.interestrate.TabIndex = 17;
                  this.interestrate.Text = "";
                  //
                  // taxrate
                  //
                  this.taxrate.Location = new System.Drawing.Point(368, 168);
                  this.taxrate.Name = "taxrate";
                  this.taxrate.Size = new System.Drawing.Size(128, 20);
                  this.taxrate.TabIndex = 16;
                  this.taxrate.Text = "";
                  //
                  // monthlypayment
                  //
                  this.monthlypayment.Location = new System.Drawing.Point(368, 120);
                  this.monthlypayment.Name = "monthlypayment";
                  this.monthlypayment.Size = new System.Drawing.Size(128, 20);
                  this.monthlypayment.TabIndex = 15;
                  this.monthlypayment.Text = "";
                  //
                  // numberofmonths
                  //
                  this.numberofmonths.Location = new System.Drawing.Point(368, 72);
                  this.numberofmonths.Name = "numberofmonths";
                  this.numberofmonths.Size = new System.Drawing.Size(128, 20);
                  this.numberofmonths.TabIndex = 14;
                  this.numberofmonths.Text = "";
                  //
                  // textBox10
                  //
                  this.textBox10.Location = new System.Drawing.Point(368, 24);
                  this.textBox10.Name = "textBox10";
                  this.textBox10.Size = new System.Drawing.Size(128, 20);
                  this.textBox10.TabIndex = 13;
                  this.textBox10.Text = "";
                  //
                  // textBox9
                  //
                  this.textBox9.Location = new System.Drawing.Point(120, 216);
                  this.textBox9.Name = "textBox9";
                  this.textBox9.Size = new System.Drawing.Size(128, 20);
                  this.textBox9.TabIndex = 12;
                  this.textBox9.Text = "";
                  //
                  // textBox8
                  //
                  this.textBox8.Location = new System.Drawing.Point(120, 160);
                  this.textBox8.Name = "textBox8";
                  this.textBox8.Size = new System.Drawing.Size(128, 20);
                  this.textBox8.TabIndex = 11;
                  this.textBox8.Text = "";
                  //
                  // textBox7
                  //
                  this.textBox7.Location = new System.Drawing.Point(120, 112);
                  this.textBox7.Name = "textBox7";
                  this.textBox7.Size = new System.Drawing.Size(128, 20);
                  this.textBox7.TabIndex = 10;
                  this.textBox7.Text = "";
                  //
                  // taxamount
                  //
                  this.taxamount.Location = new System.Drawing.Point(120, 64);
                  this.taxamount.Name = "taxamount";
                  this.taxamount.Size = new System.Drawing.Size(128, 20);
                  this.taxamount.TabIndex = 9;
                  this.taxamount.Text = "";
                  //
                  // downpayment
                  //
                  this.downpayment.Location = new System.Drawing.Point(120, 24);
                  this.downpayment.Name = "downpayment";
                  this.downpayment.Size = new System.Drawing.Size(128, 20);
                  this.downpayment.TabIndex = 8;
                  this.downpayment.Text = "";
                  //
                  // label30
                  //
                  this.label30.Location = new System.Drawing.Point(264, 224);
                  this.label30.Name = "label30";
                  this.label30.Size = new System.Drawing.Size(88, 24);
                  this.label30.TabIndex = 7;
                  this.label30.Text = "Interest Rate:";
                  //
                  // label29
                  //
                  this.label29.Location = new System.Drawing.Point(264, 168);
                  this.label29.Name = "label29";
                  this.label29.Size = new System.Drawing.Size(88, 24);
                  this.label29.TabIndex = 6;
                  this.label29.Text = "Tax Rate:";
                  //
                  // label28
                  //
                  this.label28.Location = new System.Drawing.Point(264, 120);
                  this.label28.Name = "label28";
                  this.label28.Size = new System.Drawing.Size(96, 24);
                  this.label28.TabIndex = 5;
                  this.label28.Text = "Monthly Payment:";
                  //
                  // label25
                  //
                  this.label25.Location = new System.Drawing.Point(16, 160);
                  this.label25.Name = "label25";
                  this.label25.Size = new System.Drawing.Size(104, 24);
                  this.label25.TabIndex = 4;
                  this.label25.Text = "Borrowed Amount:";
                  //
                  // label24
                  //
                  this.label24.Location = new System.Drawing.Point(16, 224);
                  this.label24.Name = "label24";
                  this.label24.Size = new System.Drawing.Size(88, 24);
                  this.label24.TabIndex = 3;
                  this.label24.Text = "Interest Amount:";
                  //
                  // label20
                  //
                  this.label20.Location = new System.Drawing.Point(264, 24);
                  this.label20.Name = "label20";
                  this.label20.Size = new System.Drawing.Size(80, 24);
                  this.label20.TabIndex = 2;
                  this.label20.Text = "Loan Amount:";
                  //
                  // label18
                  //
                  this.label18.Location = new System.Drawing.Point(264, 72);
                  this.label18.Name = "label18";
                  this.label18.Size = new System.Drawing.Size(104, 24);
                  this.label18.TabIndex = 1;
                  this.label18.Text = "Number of Months:";
                  //
                  // label17
                  //
                  this.label17.Location = new System.Drawing.Point(16, 24);
                  this.label17.Name = "label17";
                  this.label17.Size = new System.Drawing.Size(88, 24);
                  this.label17.TabIndex = 0;
                  this.label17.Text = "Down Payment:";
                  //
                  // label19
                  //
                  this.label19.Location = new System.Drawing.Point(16, 64);
                  this.label19.Name = "label19";
                  this.label19.Size = new System.Drawing.Size(88, 24);
                  this.label19.TabIndex = 1;
                  this.label19.Text = "Tax Amount:";
                  //
                  // label21
                  //
                  this.label21.Location = new System.Drawing.Point(16, 112);
                  this.label21.Name = "label21";
                  this.label21.Size = new System.Drawing.Size(88, 24);
                  this.label21.TabIndex = 2;
                  this.label21.Text = "Total Cost:";
                  //
                  // label23
                  //
                  this.label23.Location = new System.Drawing.Point(16, 72);
                  this.label23.Name = "label23";
                  this.label23.Size = new System.Drawing.Size(88, 16);
                  this.label23.TabIndex = 1;
                  this.label23.Text = "label18";
                  //
                  // label27
                  //
                  this.label27.Location = new System.Drawing.Point(16, 72);
                  this.label27.Name = "label27";
                  this.label27.Size = new System.Drawing.Size(88, 24);
                  this.label27.TabIndex = 1;
                  this.label27.Text = "label18";
                  //
                  // Form1
                  //
                  this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                  this.ClientSize = new System.Drawing.Size(848, 534);
                  this.Controls.Add(this.borrowedamount);
                  this.Controls.Add(this.customerinformation);
                  this.Controls.Add(this.groupBox1);
                  this.Controls.Add(this.button1);
                  this.Controls.Add(this.saledate);
                  this.Controls.Add(this.recordnumber);
                  this.Controls.Add(this.label2);
                  this.Controls.Add(this.label1);
                  this.Name = "Form1";
                  this.Load += new System.EventHandler(this.Form1_Load);
                  this.groupBox1.ResumeLayout(false);
                  this.customerinformation.ResumeLayout(false);
                  this.borrowedamount.ResumeLayout(false);
                  this.ResumeLayout(false);

            }
            #endregion

            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {

                  ReadSales();
                  

                  Application.Run(new Form1());
            }

            public static void ReadSales()
            {
                  try
                  {
                        StreamReader fileReader;
                        string fileName = "sales.txt";
             
                        fileReader = new StreamReader(fileName);
                        string sLine;
                        string [] split;                        
                        const char delm = '|';

                        // get the first line
                        sLine = fileReader.ReadLine();

                        while (sLine != null)
                        {                
                              // process the current line            
                              split = sLine.Split(delm);

                              string date = split[0];
                              string ids = split[1];
                              string sn = split[2];
                              double dp = double.Parse(split[3]);
                              double nom = double.Parse(split[4]);

                        

                              // get the next line
                              sLine = fileReader.ReadLine();
                        }
                  }
                  catch(FileNotFoundException)
                  {
                        MessageBox.Show( "File sales.txt Does Not Exist", "Error",
                              MessageBoxButtons.OK, MessageBoxIcon.Error );
                  }
            }

      }
}
0
Comment
Question by:jmkotman
2 Comments
 
LVL 9

Accepted Solution

by:
sasapopovic earned 500 total points
ID: 17803325
Do you have more then one line in that file?

If not then you can make next changes:

Change next two methods like this:

          [STAThread]
          static void Main()
          {
               string date = ReadSales();
               Form1 form1 = new Form1();
               form1.Date = date;
               
               Application.Run(form1);
          }
          public static string ReadSales()
          {
               string date = null;
               try
               {
                    StreamReader fileReader;
                    string fileName = "sales.txt";
             
                    fileReader = new StreamReader(fileName);
                    string sLine;
                    string [] split;                    
                    const char delm = '|';
                    // get the first line
                    sLine = fileReader.ReadLine();
                    while (sLine != null)
                    {                
                         // process the current line          
                         split = sLine.Split(delm);
                         date = split[0];
                         string ids = split[1];
                         string sn = split[2];
                         double dp = double.Parse(split[3]);
                         double nom = double.Parse(split[4]);
                   
                         // get the next line
                         sLine = fileReader.ReadLine();
                    }
               }
               catch(FileNotFoundException)
               {
                    MessageBox.Show( "File sales.txt Does Not Exist", "Error",
                         MessageBoxButtons.OK, MessageBoxIcon.Error );
               }
               return date;
          }

And change the beginning of Form1 class like this:

namespace WindowsApplication2
{
     [Serializable]
     public class Form1 : System.Windows.Forms.Form
     {
            private string _date = null;
            
            public string Date
            {
                  get
                  {
                        return this._date;
                  }
                  set
                  {
                        this._date = value;
                  }
            }




Now in your Form1.cs you can access the date like this: this.Date.

I hope this is what you need.

Just a tip, I would never design application like that. You can always perform the reading on place where you need that string and not in main method.

Regards,
Sasa
0
 

Author Comment

by:jmkotman
ID: 17812647
Yes there is more then one line in the file being read.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now