• 0

[C#] Writing data to a .dat file


Question

Hi!

I have a window application.

User makes some selection from different combo boxes, then when hitted the "ADD TO CART" button, the data selected will be copied to some labels next to it.

But now, i need to transfer/copy all that data from the labels to a file named: computer.dat

How do i do that? I'm really having problems with that.

I have this there:

void storeInFile(Part *d)
  	{
    FileStream file = new FileStream("computer.dat", FileMode.OpenOrCreate, FileAccess.Read);

    for (int i=0; i<d->dataCount; i++)
    {
    	file << d->pb[i].processor <<"\n\n";
    	file << d->pb[i].memory <<"\n"<< endl; 
    	file << d->pb[i].harddrive <<"\n"<< endl; 
    	file << d->pb[i].cdrom <<"\n"<< endl;
    	file << d->pb[i].floppydrive <<"\n"<< endl; 
    	file << d->pb[i].keyboard <<"\n"<< endl; 
    	file << d->pb[i].monitor <<"\n"<< endl; 
    	file << d->pb[i].mouse <<"\n"<< endl; 
    }
    file.Close();	// close computer.dat
  	}

but im not sure if that's correct.

Please help me..:)

Thanks,

Link to comment
https://www.neowin.net/forum/topic/376679-c-writing-data-to-a-dat-file/
Share on other sites

Recommended Posts

  • 0

OK!

Did it!

But now i get 27 errors.

-Pointers may only be used in an unsafe context

-Only assingemtn, call, increment, decrement, and object expresions can be used as a statement

-'WindowApplication1.Form1.Part' does not contain a definition for 'pb'

And those 3 errors keep repeating like 4 more times in the Task List.

  • 0
  marie said:
Yes i know, i kinda copy and pasted a code made some time ago in C++ and was tring to fix it and put it to work into C#, but i think i failed at it.

Can somebody please help me there? :cry:

586574180[/snapback]

take a good long look into "FileStream" on the MSDN. hint "file <<" :no:

get rid of the pointer *d and try something else, dont worry (i did the same mistakes like that before)

  • 0
  marie said:
Okay, thanks for the site.

But hmmm.. what i need to write is what's in the labels.

How do i do that?

586574212[/snapback]

it should be

comboBox1.SelectedItem.ToString();

where "comboBox1" is the name of your ....well combobox

opps. you said label

label1.Text.ToString()

"label1" name of your label

Edited by dolimite35
  • 0

You could try something like this:

 ? ? ? ?void storeInFile()
 ? ? ? ?{
 ? ? ? ? ? ?// create a file stream, for "computer.dat"
 ? ? ? ? ? ?FileStream fs = new FileStream("computer.dat", FileMode.CreateNew, FileAccess.ReadWrite);
 ? ? ? ? ? ?// create a stream writer
 ? ? ? ? ? ?StreamWriter sw = new StreamWriter(fs);

 ? ? ? ? ? ?//write to file (buffer), where label1 and label2 are your labels.
 ? ? ? ? ? ?sw.Write(label1.Text.ToString() + Environment.NewLine);
 ? ? ? ? ? ?sw.Write(label2.Text.ToString() + Environment.NewLine);

 ? ? ? ? ? ?// flush buffer (so the text really goes into the file)
 ? ? ? ? ? ?sw.Flush();
 ? ? ? ? ? ?// close stream writer and file
 ? ? ? ? ? ?sw.Close();
 ? ? ? ? ? ?fs.Close();
 ? ? ? ?}

Edited by BigCheese
  • 0
  lnatan25 said:
Doesn't the Close() do a flush as well, or is it needed to flush the stream manually? And as stated above, ToStrings() on label1/2.Text is really a waste, as the Text property is string.

586574669[/snapback]

Yeah. Flush() is useless immediately before Close().

Close() calls Dispose(), which calls Flush().

  • 0

OK, So this is my code:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;



namespace WindowsApplication1
{
	/// &lt;summary&gt;
	/// Summary description for Form1.
	/// &lt;/summary&gt;
	public class Form1 : System.Windows.Forms.Form
	{
  private System.Windows.Forms.ComboBox comboBox1;
  private System.Windows.Forms.ComboBox comboBox2;
  private System.Windows.Forms.ComboBox comboBox3;
  private System.Windows.Forms.ComboBox comboBox4;
  private System.Windows.Forms.ComboBox comboBox5;
  private System.Windows.Forms.ComboBox comboBox6;
  private System.Windows.Forms.ComboBox comboBox7;
  private System.Windows.Forms.ComboBox comboBox8;
  private System.Windows.Forms.Label label1;
  private System.Windows.Forms.Label label2;
  private System.Windows.Forms.TextBox textBox1;
  private System.Windows.Forms.Label label3;
  private System.Windows.Forms.TextBox textBox2;
  private System.Windows.Forms.PictureBox pictureBox1;
  private System.Windows.Forms.Button button1;
  private System.Windows.Forms.GroupBox groupBox1;
  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.Label label10;
  private System.Windows.Forms.Label label11;
  private System.Windows.Forms.Label label12;
  private System.Windows.Forms.Label label13;
  private System.Windows.Forms.TextBox textBox3;
  /// &lt;summary&gt;
  /// Required designer variable.
  /// &lt;/summary&gt;
  private System.ComponentModel.Container components = null;


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

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

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

  #region Windows Form Designer generated code
  /// &lt;summary&gt;
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// &lt;/summary&gt;
  private void InitializeComponent()
  {
  	System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
  	this.comboBox1 = new System.Windows.Forms.ComboBox();
  	this.comboBox2 = new System.Windows.Forms.ComboBox();
  	this.comboBox3 = new System.Windows.Forms.ComboBox();
  	this.comboBox4 = new System.Windows.Forms.ComboBox();
  	this.comboBox5 = new System.Windows.Forms.ComboBox();
  	this.comboBox6 = new System.Windows.Forms.ComboBox();
  	this.comboBox7 = new System.Windows.Forms.ComboBox();
  	this.comboBox8 = new System.Windows.Forms.ComboBox();
  	this.label1 = new System.Windows.Forms.Label();
  	this.label2 = new System.Windows.Forms.Label();
  	this.textBox1 = new System.Windows.Forms.TextBox();
  	this.label3 = new System.Windows.Forms.Label();
  	this.textBox2 = new System.Windows.Forms.TextBox();
  	this.pictureBox1 = new System.Windows.Forms.PictureBox();
  	this.button1 = new System.Windows.Forms.Button();
  	this.groupBox1 = new System.Windows.Forms.GroupBox();
  	this.label12 = new System.Windows.Forms.Label();
  	this.label11 = new System.Windows.Forms.Label();
  	this.label10 = new System.Windows.Forms.Label();
  	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.label13 = new System.Windows.Forms.Label();
  	this.textBox3 = new System.Windows.Forms.TextBox();
  	this.groupBox1.SuspendLayout();
  	this.SuspendLayout();
  	// 
  	// comboBox1
  	// 
  	this.comboBox1.DropDownWidth = 320;
  	this.comboBox1.Items.AddRange(new object[] {
                 "Intel? Pentium? 4 Processor (2.80GHz, 533 FSB) [add $30]",
                 "Intel? Pentium? 4 Processor (3GHz, 800 FSB) [add $50]",
                 "Intel? Pentium? D 820 (2.8GHz, 800MHz FSB) [add $150]",
                 "Intel? Pentium? D 840 (3.2GHz, 800MHz FSB) [add $200]"});
  	this.comboBox1.Location = new System.Drawing.Point(24, 144);
  	this.comboBox1.Name = "comboBox1";
  	this.comboBox1.Size = new System.Drawing.Size(320, 21);
  	this.comboBox1.TabIndex = 0;
  	this.comboBox1.Text = "Select Processor Desired";
  	// 
  	// comboBox2
  	// 
  	this.comboBox2.DropDownWidth = 300;
  	this.comboBox2.Items.AddRange(new object[] {
                 "512MB Dual Channel DDR SDRAM at 400MHz [add $39]",
                 "1GB Dual Channel DDR SDRAM at 533MHz [add $60]",
                 "2GB Dual Channel DDR2 SDRAM at 533MHz [add $220]",
                 "4GB Dual Channel DDR2 SDRAM at 533MHz [add $500]"});
  	this.comboBox2.Location = new System.Drawing.Point(24, 192);
  	this.comboBox2.Name = "comboBox2";
  	this.comboBox2.Size = new System.Drawing.Size(320, 21);
  	this.comboBox2.TabIndex = 1;
  	this.comboBox2.Text = "Select Memory Desired";
  	// 
  	// comboBox3
  	// 
  	this.comboBox3.DropDownWidth = 250;
  	this.comboBox3.Items.AddRange(new object[] {
                 "80GB Serial ATA (7200rpm) (80S) [add $39]",
                 "160GB Serial ATA (7200rpm) (160S) [add $49]",
                 "250GB Serial ATA (7200rpm) (250S) [add $100]",
                 "400GB Serial ATA (7200rpm) (400S) [add $310]"});
  	this.comboBox3.Location = new System.Drawing.Point(24, 248);
  	this.comboBox3.Name = "comboBox3";
  	this.comboBox3.Size = new System.Drawing.Size(320, 21);
  	this.comboBox3.TabIndex = 2;
  	this.comboBox3.Text = "Select Hard Drive Desired";
  	// 
  	// comboBox4
  	// 
  	this.comboBox4.DropDownWidth = 325;
  	this.comboBox4.Items.AddRange(new object[] {
                 "16X CD/DVD burner (DVD+/-RW) [add $20]",
                 "16x DVD-ROM Drive + 16x DVD+/-RW  [add $30]",
                 "24X CD-RW / DVD Combo Drive [add $40]",
                 "8X CD/DVD burner (DVD+/-RW) [add $50]"});
  	this.comboBox4.Location = new System.Drawing.Point(24, 304);
  	this.comboBox4.Name = "comboBox4";
  	this.comboBox4.Size = new System.Drawing.Size(320, 21);
  	this.comboBox4.TabIndex = 3;
  	this.comboBox4.Text = "Select CD-Rom Desired";
  	// 
  	// comboBox5
  	// 
  	this.comboBox5.DropDownWidth = 200;
  	this.comboBox5.Items.AddRange(new object[] {
                 "3.5 inches Floppy Drive 1.44MB [add $30]",
                 "None [add $0]"});
  	this.comboBox5.Location = new System.Drawing.Point(24, 360);
  	this.comboBox5.MaxDropDownItems = 5;
  	this.comboBox5.Name = "comboBox5";
  	this.comboBox5.Size = new System.Drawing.Size(320, 21);
  	this.comboBox5.TabIndex = 4;
  	this.comboBox5.Text = "Select Floppy Drive Desired";
  	// 
  	// comboBox6
  	// 
  	this.comboBox6.Items.AddRange(new object[] {
                 "USB Keyboard  [add $20] ",
                 "Wireless Keyboard [add $50]"});
  	this.comboBox6.Location = new System.Drawing.Point(24, 416);
  	this.comboBox6.Name = "comboBox6";
  	this.comboBox6.Size = new System.Drawing.Size(320, 21);
  	this.comboBox6.TabIndex = 5;
  	this.comboBox6.Text = "Select Keyboard Desired";
  	// 
  	// comboBox7
  	// 
  	this.comboBox7.DropDownWidth = 245;
  	this.comboBox7.Items.AddRange(new object[] {
                 "15 inch E153FP Analog Flat Panel [add $100] ",
                 "17 inch E173FP Analog Flat Panel [add $160]",
                 "20 inch UltraSharp? Widescreen Digital Flat Panel [add $270]",
                 "No Monitor [add $0]"});
  	this.comboBox7.Location = new System.Drawing.Point(24, 472);
  	this.comboBox7.Name = "comboBox7";
  	this.comboBox7.Size = new System.Drawing.Size(320, 21);
  	this.comboBox7.TabIndex = 6;
  	this.comboBox7.Text = "Select Monitor Desired";
  	// 
  	// comboBox8
  	// 
  	this.comboBox8.DropDownWidth = 250;
  	this.comboBox8.Items.AddRange(new object[] {
                 "Dell? 2-button USB mouse [add $19] ",
                 "Dell Optical USB Mouse [add $29]",
                 "Logitech? MX? 518 Optical Mouse [add $50]",
                 "No Mouse [add $0]"});
  	this.comboBox8.Location = new System.Drawing.Point(24, 528);
  	this.comboBox8.Name = "comboBox8";
  	this.comboBox8.Size = new System.Drawing.Size(320, 21);
  	this.comboBox8.TabIndex = 7;
  	this.comboBox8.Text = "Select Mouse Desired";
  	// 
  	// label1
  	// 
  	this.label1.Font = new System.Drawing.Font("Edwardianpt ITC", 25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  	this.label1.Location = new System.Drawing.Point(184, 8);
  	this.label1.Name = "label1";
  	this.label1.Size = new System.Drawing.Size(288, 48);
  	this.label1.TabIndex = 8;
  	this.label1.Text = "Customize Your Computer";
  	// 
  	// label2
  	// 
  	this.label2.Font = new System.Drawing.Font("Microsoft Serif", 8.6F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  	this.label2.Location = new System.Drawing.Point(88, 88);
  	this.label2.Name = "label2";
  	this.label2.Size = new System.Drawing.Size(72, 16);
  	this.label2.TabIndex = 9;
  	this.label2.Text = "First Name";
  	// 
  	// textBox1
  	// 
  	this.textBox1.AcceptsTab = true;
  	this.textBox1.Location = new System.Drawing.Point(168, 88);
  	this.textBox1.Name = "textBox1";
  	this.textBox1.Size = new System.Drawing.Size(120, 20);
  	this.textBox1.TabIndex = 10;
  	this.textBox1.Text = "";
  	// 
  	// label3
  	// 
  	this.label3.Font = new System.Drawing.Font("Microsoft Serif", 8.6F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  	this.label3.Location = new System.Drawing.Point(376, 88);
  	this.label3.Name = "label3";
  	this.label3.Size = new System.Drawing.Size(72, 16);
  	this.label3.TabIndex = 11;
  	this.label3.Text = "Last Name";
  	// 
  	// textBox2
  	// 
  	this.textBox2.AcceptsTab = true;
  	this.textBox2.Location = new System.Drawing.Point(448, 88);
  	this.textBox2.Name = "textBox2";
  	this.textBox2.Size = new System.Drawing.Size(128, 20);
  	this.textBox2.TabIndex = 12;
  	this.textBox2.Text = "";
  	// 
  	// pictureBox1
  	// 
  	this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image
  	this.pictureBox1.Location = new System.Drawing.Point(512, 8);
  	this.pictureBox1.Name = "pictureBox1";
  	this.pictureBox1.Size = new System.Drawing.Size(64, 64);
  	this.pictureBox1.TabIndex = 14;
  	this.pictureBox1.TabStop = false;
  	// 
  	// button1
  	// 
  	this.button1.FlatStyle = System.Windows.Forms.FlatStyle.System;
  	this.button1.ImageAlign = System.Drawing.ContentAlignment.TopCenter;
  	this.button1.Location = new System.Drawing.Point(144, 568);
  	this.button1.Name = "button1";
  	this.button1.Size = new System.Drawing.Size(80, 24);
  	this.button1.TabIndex = 16;
  	this.button1.Text = "Add To Cart";
  	this.button1.Click += new System.EventHandler(this.button1_Click);
  	// 
  	// groupBox1
  	// 
  	this.groupBox1.Controls.Add(this.textBox3);
  	this.groupBox1.Controls.Add(this.label13);
  	this.groupBox1.Controls.Add(this.label12);
  	this.groupBox1.Controls.Add(this.label11);
  	this.groupBox1.Controls.Add(this.label10);
  	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.Location = new System.Drawing.Point(368, 136);
  	this.groupBox1.Name = "groupBox1";
  	this.groupBox1.Size = new System.Drawing.Size(320, 456);
  	this.groupBox1.TabIndex = 17;
  	this.groupBox1.TabStop = false;
  	this.groupBox1.Text = "Items on your Cart";
  	// 
  	// label12
  	// 
  	this.label12.Font = new System.Drawing.Font("Microsoft Serif", 8.9F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  	this.label12.Location = new System.Drawing.Point(16, 16);
  	this.label12.Name = "label12";
  	this.label12.Size = new System.Drawing.Size(296, 32);
  	this.label12.TabIndex = 8;
  	// 
  	// label11
  	// 
  	this.label11.Location = new System.Drawing.Point(16, 392);
  	this.label11.Name = "label11";
  	this.label11.Size = new System.Drawing.Size(288, 24);
  	this.label11.TabIndex = 7;
  	// 
  	// label10
  	// 
  	this.label10.Location = new System.Drawing.Point(16, 344);
  	this.label10.Name = "label10";
  	this.label10.Size = new System.Drawing.Size(288, 32);
  	this.label10.TabIndex = 6;
  	// 
  	// label9
  	// 
  	this.label9.Location = new System.Drawing.Point(16, 304);
  	this.label9.Name = "label9";
  	this.label9.Size = new System.Drawing.Size(288, 24);
  	this.label9.TabIndex = 5;
  	// 
  	// label8
  	// 
  	this.label8.Location = new System.Drawing.Point(16, 264);
  	this.label8.Name = "label8";
  	this.label8.Size = new System.Drawing.Size(288, 24);
  	this.label8.TabIndex = 4;
  	// 
  	// label7
  	// 
  	this.label7.Location = new System.Drawing.Point(16, 216);
  	this.label7.Name = "label7";
  	this.label7.Size = new System.Drawing.Size(288, 24);
  	this.label7.TabIndex = 3;
  	// 
  	// label6
  	// 
  	this.label6.Location = new System.Drawing.Point(16, 168);
  	this.label6.Name = "label6";
  	this.label6.Size = new System.Drawing.Size(288, 32);
  	this.label6.TabIndex = 2;
  	// 
  	// label5
  	// 
  	this.label5.Location = new System.Drawing.Point(16, 112);
  	this.label5.Name = "label5";
  	this.label5.Size = new System.Drawing.Size(288, 40);
  	this.label5.TabIndex = 1;
  	// 
  	// label4
  	// 
  	this.label4.Location = new System.Drawing.Point(16, 64);
  	this.label4.Name = "label4";
  	this.label4.Size = new System.Drawing.Size(288, 32);
  	this.label4.TabIndex = 0;
  	// 
  	// label13
  	// 
  	this.label13.Location = new System.Drawing.Point(168, 432);
  	this.label13.Name = "label13";
  	this.label13.Size = new System.Drawing.Size(40, 16);
  	this.label13.TabIndex = 9;
  	this.label13.Text = "Total";
  	// 
  	// textBox3
  	// 
  	this.textBox3.Location = new System.Drawing.Point(208, 424);
  	this.textBox3.Name = "textBox3";
  	this.textBox3.TabIndex = 10;
  	this.textBox3.Text = "$";
  	// 
  	// Form1
  	// 
  	this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  	this.ClientSize = new System.Drawing.Size(712, 606);
  	this.Controls.Add(this.groupBox1);
  	this.Controls.Add(this.button1);
  	this.Controls.Add(this.pictureBox1);
  	this.Controls.Add(this.textBox2);
  	this.Controls.Add(this.label3);
  	this.Controls.Add(this.textBox1);
  	this.Controls.Add(this.label2);
  	this.Controls.Add(this.label1);
  	this.Controls.Add(this.comboBox8);
  	this.Controls.Add(this.comboBox7);
  	this.Controls.Add(this.comboBox6);
  	this.Controls.Add(this.comboBox5);
  	this.Controls.Add(this.comboBox4);
  	this.Controls.Add(this.comboBox3);
  	this.Controls.Add(this.comboBox2);
  	this.Controls.Add(this.comboBox1);
  	this.Name = "Form1";
  	this.Text = "Form1";
  	this.groupBox1.ResumeLayout(false);
  	this.ResumeLayout(false);

  }
  #endregion

  public class Part
  { // begins class Part
  
  	private
    int hardware;
  	int dataCount;
  	double qty;

  	public
    Part() {} // default constructor
  	void parts_Name(int parts)
  	{
    this.hardware = parts;
  	}

  	void parts_Price(double price)
  	{
    this.qty = price;
  	}

  /*	void storeInFile()
  	{
    FileStream file = new FileStream("computer.dat", FileMode.OpenOrCreate, FileAccess.Write);

    
    for (int i=0; i&lt;d-&gt;dataCount; i++)
    {
    	file &lt;&lt; d-&gt;pb[i].processor &lt;&lt;"\n\n";
    	file &lt;&lt; d-&gt;pb[i].memory &lt;&lt;"\n"&lt;&lt; endl; 
    	file &lt;&lt; d-&gt;pb[i].harddrive &lt;&lt;"\n"&lt;&lt; endl; 
    	file &lt;&lt; d-&gt;pb[i].cdrom &lt;&lt;"\n"&lt;&lt; endl;
    	file &lt;&lt; d-&gt;pb[i].floppydrive &lt;&lt;"\n"&lt;&lt; endl; 
    	file &lt;&lt; d-&gt;pb[i].keyboard &lt;&lt;"\n"&lt;&lt; endl; 
    	file &lt;&lt; d-&gt;pb[i].monitor &lt;&lt;"\n"&lt;&lt; endl; 
    	file &lt;&lt; d-&gt;pb[i].mouse &lt;&lt;"\n"&lt;&lt; endl;
    }
    file.Close();	// close computer.dat
  	}
  	*/

  	void storeInFile()
  	{
    // create a file stream, for "computer.dat"
    FileStream fs = new FileStream("computer.dat", FileMode.CreateNew, FileAccess.ReadWrite);
    // create a stream writer
    StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.ASCII);

    //write to file (buffer), where textBox1 is your text box
    sw.Write(label4.Text.ToString() + Environment.NewLine);
    sw.Write(label5.Text.ToString() + Environment.NewLine);
    sw.Write(label6.Text.ToString() + Environment.NewLine);
    sw.Write(label7.Text.ToString() + Environment.NewLine);
    sw.Write(label8.Text.ToString() + Environment.NewLine);
    sw.Write(label9.Text.ToString() + Environment.NewLine);
    sw.Write(label10.Text.ToString() + Environment.NewLine);
    sw.Write(label11.Text.ToString() + Environment.NewLine);

    // flush buffer (so the text really goes into the file)
    sw.Flush();
    // close stream writer and file
    sw.Close();
    fs.Close();
  	}




  } // end class Part

  public class Processor :  Part
  {
            
  }

  public class Memory : Part
  {

  }

  public class HardDrive : Part
  {

  }

  public class CDRom : Part
  {

  }

  public class Floppy : Part
  {

  }

  public class Keyboard : Part
  {

  }

  public class Monitor : Part
  {

  }

  public class Mouse : Part
  {

  }


  


  /// &lt;summary&gt;
  /// The main entry point for the application.
  /// &lt;/summary&gt;
  [STAThread]
  static void Main() 
  {
  	Application.Run(new Form1());
  }



  private void button1_Click(object sender, System.EventArgs e)
  {
  	label12.Text = textBox1.Text += textBox2.Text += ", thanks for selecting us as your preferred brand!";
  	label4.Text = comboBox1.Text;
  	label5.Text = comboBox2.Text;
  	label6.Text = comboBox3.Text;
  	label7.Text = comboBox4.Text;
  	label8.Text = comboBox5.Text;
  	label9.Text = comboBox6.Text;
  	label10.Text = comboBox7.Text;
  	label11.Text = comboBox8.Text;

  } // end button1_Click


	}
}

    

  • 0
  marie said:
Why it isnt C#?

What is wrong?

It is working, what i still need it to do, is safe the selections into a .dat file and calculate the total.

586574987[/snapback]

The context in which you are using the << operator is OK for C++ because the ostream overloads it to write to the stream. However, the <</>> operators in C# are bitshift operators. When you create streams in C#, you use the methods on the object to read and write with them.

By the way, you can use the WriteLine method to avoid having to concatenate the Environment.NewLine to your output.

  • 0
  Kawahee said:
This is why I love unmanaged C++, no bull**** :)

586574866[/snapback]

i wouldnt say its "bull****" just another way to do things, other may find c++ "bull****" with C# here to help. Heck, the crazy VB :wacko: or assembly :wacko: :wacko: :wacko: people may look down at c++ folks

  • 0

You're trying to access the labels from inside another class. You can't do that. This is a quick workaround.

A new storeInFile

  void storeInFile()
  {
   // create a file stream, for "computer.dat"
   FileStream fs = new FileStream("computer.dat", FileMode.CreateNew, FileAccess.ReadWrite);
   // create a stream writer
   StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.ASCII);

   //write to file (buffer), where textBox1 is your text box
   sw.WriteLine(owner.label4.Text);
   sw.WriteLine(owner.label5.Text);
   sw.WriteLine(owner.label6.Text);
   sw.WriteLine(owner.label7.Text);
   sw.WriteLine(owner.label8.Text);
   sw.WriteLine(owner.label9.Text);
   sw.WriteLine(owner.label10.Text);
   sw.Write(owner.label11.Text);

   // close stream writer and file
   sw.Close();
   fs.Close();
  }

A new constructor for 'Part'

  private Form1 owner;
  public Part(Form1 Owner)
  {
  	owner = Owner;
  }

Each inheritted part will need to look like this now: (For whatever reason, we can't simply inherit constructors and ignore this crap. Go figure.)

 public class Memory : Part
 {
  public Memory(Form1 Owner) : base(Owner)
  {
  }
 }

Also, from a purely observational standpoint, why is this a windows application? This seems like something that would be much better suited to a web application.

  • 0

This is a windows application, because the professor asked for it to be a windows application..

;)

and by the way, what does

  private Form1 owner;

does?

Sorry for all the questions, i really need to get this to work, but i also really want to learn from it.

C# to me, seems more interesting that C++.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Plasma 6.5 brings improved Emoji Selector, better performance in Activity manager, and more by David Uzondu This week saw the long-awaited release of KDE Plasma 6.4, bringing better window management and a whole lot of color management features. Apart from the release of 6.4, the KDE team was able to get other work done, and this was all outlined in the latest issue of This Week in Plasma, which details what is coming down the pipe for future versions. Looking ahead to Plasma 6.5, the developers are making some notable changes to improve performance and general usability. To prevent its database from growing endlessly and causing performance problems over time, the Activity Manager service will now only store the last four months of your history by default. The Emoji selector app is also getting a much-needed redesign that makes the window more compact and moves the sidebar button to the header for a cleaner look. Other little details for 6.5 are being polished up too. The unpopular vertical line separating the date and time on the horizontal Digital Clock widget is gone; if you want it back, you can add it yourself with a custom date format. The "Add New" button has also been moved to the top toolbar in the Shortcuts page within Settings, freeing up some valuable screen real estate. The devs also reduced the minimum size of custom tiling tiles, a small but significant fix for anyone with an ultrawide monitor. In addition to that, the Networks widget's captive portal banner now uses inline header styling, so it doesn't look like a bunch of frames stacked inside each other anymore. Of course, before we get to 6.5, the current release needs some attention. Plasma 6.4's first bug fix release, 6.4.1, addresses issues like broken item selection in the Folder View widget and a bug that could cause the system to lock or suspend faster than intended. Keyboard navigation in list views in Discover feels smoother now, and text is easier to read in certain list items in KRunner. The devs also cleaned up how list items look when you press or click them in Discover. 6.4.1 also fixes a bug where the clipboard history popup would fail to select the top item, and makes the Earth Science Picture of The Day wallpaper plugin work again after its data source changed. Here's the full list of fixes: Fixed several issues in the Folder View widget that caused selecting or opening items to not work when using certain non-default view settings, when the view was scrollable, or when using a touchscreen. Fixed a bug in the Meta+V clipboard popup that sometimes failed to pre-select the top-most item. The Clipboard settings window’s shortcuts page no longer shows columns for local shortcuts that don’t do anything, since the clipboard is global in scope. Fixed the Earth Science Picture of the Day wallpaper plugin after the source data changed formatting again. Made a few fixes to the “Missing Backends” section of Discover’s settings window that kept it from working properly. Fixed a bug that prevented direct scan-out (and its performance benefits) from activating on rotated screens. Fixed an issue where the system could lock or suspend sooner than expected after an app stopped blocking those actions. Installing a new wallpaper plugin no longer causes the plugin list combobox to appear blank. The team even went back to squash some bugs in the older 6.3.6, tackling an issue that could cause keyboard shortcuts to get lost during a system upgrade and fixing an overflow bug with KRunner's faded completion text. Plasma 6.4.1 is set to arrive on June 24th, with 6.3.6 following on July 8th.
    • UniGetUI 3.2.1 Beta 1 by Razvan Serea UniGetUI is an application whose main goal is to create an intuitive GUI for the most common CLI package managers for Windows 10 and Windows 11, such as Winget, Scoop and Chocolatey. With UniGetUI, you'll be able to download, install, update and uninstall any software that's published on the supported package managers — and so much more. UniGetUI features Install, update and remove software from your system easily at one click: UniGetUI combines the packages from the most used package managers for windows: WinGet, Chocolatey, Scoop, Pip, Npm and .NET Tool. Discover new packages and filter them to easily find the package you want. View detailed metadata about any package before installing it. Get the direct download URL or the name of the publisher, as well as the size of the download. Easily bulk-install, update or uninstall multiple packages at once selecting multiple packages before performing an operation Automatically update packages, or be notified when updates become available. Skip versions or completely ignore updates in a per-package basis. Manage your available updates at the touch of a button from the Widgets pane or from Dev Home pane with UniGetUI Widgets. The system tray icon will also show the available updates and installed package, to efficiently update a program or remove a package from your system. Easily customize how and where packages are installed. Select different installation options and switches for each package. Install an older version or force to install a 32bit architecture. [But don't worry, those options will be saved for future updates for this package] Share packages with your friends to show them off that program you found. Here is an example: Hey @friend, Check out this program! Export custom lists of packages to then import them to another machine and install those packages with previously-specified, custom installation parameters. Setting up machines or configuring a specific software setup has never been easier. Backup your packages to a local file to easily recover your setup in a matter of seconds when migrating to a new machine UniGetUI 3.2.1 Beta 1 changelog: Added per-package-manager default install options Added the ability to run pre-install/update/uninstall and post-install/update/uninstall commands Added the ability to kill process(es) before a package is installed/updated/uninstalled Block custom command-line arguments (and pre/post commands) behind a SecureSetting switch SecureSettings are settings that require administrator privileges to be switched. Bundles won't import custom arguments & custom commands by default Bundles will show a security report when importing potentially dangerous settings Added a better crash message for when UniGetUI files are missing Deep improvements to how bundles and InstallOptions are loaded from disk. Improvements to WebView lifecycle Download: UniGetUI 3.2.1 Beta 1 | 51.7 MB (Open Source) Links: WingetUI Home Page | GitHub | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • I'm just waiting on what they will do when outlook doesn't load properly, and you have to set a new profile as a test.
    • Weekend PC Game Deals: Rhythm bundles, fishing festivals, and DRM-free summer sales by Pulasthi Ariyasinghe Weekend PC Game Deals is where the hottest gaming deals from all over the internet are gathered into one place every week for your consumption. So kick back, relax, and hold on to your wallets. The Humble Store introduced the June Tunes collection this week. Coming in with music and rhythm titles, the bundle begins with Wanderson, Everhood, and Onde in the first tier for $5. Going up a tier by paying $8 gets you three more games: Rhythm Fighter, One Btn Bosses, and Oddada. Lastly, Trombone Champ, DJMAX RESPECT V, and Ragnarock lead the final tier, which are yours for $10. Just yesterday, Humble also brought out the Serenity Forge Storyteller's Bundle. This carries 12 indie games inside it, including LISA the Joyful and LISA the Painful, Neversong, Death's Gambit, Smile for Me, Long Gone Days, and more, all split into three tiers of prices. Replacing Two Point Hospital, The Operator landed as the latest freebie on the Epic Games Store earlier this week. The 2024-released indie title has you taking the role of a new hire at the Federal Department of Intelligence (FDI). Here you have to analyze evidence, fact-check, and try to solve a streak of mysterious crimes using the agency's advanced investigative software. However, as the story progresses, a conspiracy is revealed that paints the FDI in a different light. The Operator giveaway on the Epic Games Store is slated to last until June 26. On the same day, Sable will become the next freebie in the promotion. Free Events If you're looking to try out some games over the weekend without opening your wallet, there are three games having free weekend offers right now. Starting off, Paradox is offering its grand strategy experience, Victoria 3, to try out. The title has a much higher focus on state management than war and roleplaying compared to the company's other games. If that's too much of a tough start, Len's Island is temporarily free-to-play now too. This is a top-down perspective survival game with support for up to eight players in co-op, with combat, farming, dungeon diving, and other elements being included. Lastly, Dead by Daylight should be the most familiar to most. The multiplayer four-versus-one asymmetric survival horror game has you assuming the roles of survivors or the killer to see who can come out on top. Big Deals With the Steam Summer Sale only being days away, most publishers and developers are laying low to prepare for the big event. Still, we found quite a few games having some attractive discounts. Here's our hand-picked big deals list for this weekend: Red Dead Redemption – $29.99 on Steam Mount & Blade II: Bannerlord – $24.99 on Steam Timberborn – $24.49 on Steam BERSERK and the Band of the Hawk – $23.99 on Steam Wo Long: Fallen Dynasty – $23.99 on Steam Disney Epic Mickey: Rebrushed – $23.99 on Steam Jagged Alliance 3 – $22.49 on Steam [NINJA GAIDEN: Master Collection] NINJA GAIDEN Σ2 – $19.99 on Steam Alone in the Dark – $19.99 on Steam Last Train Home – $19.99 on Steam Len's Island – $19.49 on Steam Nightingale – $17.99 on Steam DYNASTY WARRIORS 8: Xtreme Legends Complete Edition – $16.99 on Steam Mortal Kombat 1 – $16.49 on Steam SOMA – $14.99 on Steam Victoria 3 – $14.99 on Steam Trepang2 – $14.99 on Steam Blasphemous 2 – $14.99 on Steam Wreckfest – $14.99 on Steam Expeditions: Rome – $14.84 on Steam EA SPORTS FC 25 – $13.99 on Steam STAR WARS Jedi: Survivor – $13.99 on Steam DRAGON BALL Z: KAKAROT – $12.99 on Gamesplanet Amnesia: The Bunker – $12.49 on Steam DREDGE – $12.49 on Steam Dead Space – $11.99 on Steam DAVE THE DIVER – $11.99 on Steam WILD HEARTS – $10.49 on Steam It Takes Two – $9.99 on Steam Dragon Age Inquisition – $9.99 on Steam Haven – $9.99 on Steam Hellboy Web of Wyrd – $9.99 on Steam Nova Lands – $9.99 on Steam BIOMUTANT – $9.99 on Steam Destroy All Humans! 2 - Reprobed – $9.99 on Steam Ghostrunner 2 – $9.99 on Steam Need for Speed Unbound – $9.79 on Steam Call of the Wild: The Angler – $8.99 on Steam DEAD OR ALIVE 6 – $8.99 on Steam Operation: Tango – $8.99 on Steam Katana ZERO – $8.99 on Steam Dead by Daylight – $7.99 on Steam Killer Frequency – $7.49 on Steam Nioh: Complete Edition – $7.49 on Steam Overcooked! 2 – $6.24 on Steam A Way Out – $5.99 on Steam Mass Effect Legendary Edition – $5.99 on Steam Darksiders Genesis – $5.99 on Steam Mortal Kombat 11 – $4.99 on Steam Titanfall 2 – $4.49 on Steam Golf With Your Friends – $4.49 on Steam STAR WARS Battlefront II – $3.99 on Steam Yoku's Island Express – $3.99 on Steam theHunter: Call of the Wild – $3.99 on Steam RoboCop: Rogue City – $3.74 on Fanatical Battlefield 2042 – $2.99 on Steam Road Redemption – $2.99 on Steam Shadow Warrior 2 – $2.99 on Steam Battlefield V – $2.49 on Steam Ultimate Fishing Simulator – $1.99 on Steam DRM-free Specials The GOG store has already kicked off its own summer sale, putting thousands of DRM-free games on sale. Here are some highlights: Cyberpunk 2077 - $23.99 on GOG God of War - $19.99 on GOG Fallout 4: Game of the Year Edition - $15.99 on GOG Fallout 4: Game of the Year Edition - $15.99 on GOG Dino Crisis Bundle - $15.29 on GOG Devil May Cry HD Collection & 4SE Bundle - $14.84 on GOG The Witcher 3: Wild Hunt - Complete Edition - $9.99 on GOG Vampire: The Masquerade - Bloodlines - $9.99 on GOG SPORE Collection - $7.49 on GOG Papers, Please - $4.99 on GOG Terraria - $4.99 on GOG SWAT 4: Gold Edition - $4.99 on GOG DOOM (2016) - $3.99 on GOG DOOM 3 - $3.99 on GOG CrossCode - $3.99 on GOG Mad Max - $2.99 on GOG Heroes of Might and Magic 3: Complete - $2.49 on GOG Heroes of Might and Magic 4: Complete - $2.49 on GOG World in Conflict: Complete Edition - $2.49 on GOG Alan Wake - $1.49 on GOG Mortal Kombat 1+2+3 - $1.49 on GOG RollerCoaster Tycoon Deluxe - $1.19 on GOG Keep in mind that availability and pricing for some deals could vary depending on the region. That's it for our pick of this weekend's PC game deals, and hopefully, some of you have enough self-restraint not to keep adding to your ever-growing backlogs. As always, there are an enormous number of other deals ready and waiting all over the interwebs, as well as on services you may already subscribe to if you comb through them, so keep your eyes open for those, and have a great weekend.
    • Is there a 'recovery' settings option in Settings? The one where we can rollback to a previous restore point. I find it very useful if there is some issue and I have to rollback to the last stable point.
  • Recent Achievements

    • Contributor
      GravityDead went up a rank
      Contributor
    • Week One Done
      BlakeBringer earned a badge
      Week One Done
    • Week One Done
      Helen Shafer earned a badge
      Week One Done
    • First Post
      emptyother earned a badge
      First Post
    • Week One Done
      Crunchy6 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      672
    2. 2
      ATLien_0
      269
    3. 3
      Michael Scrip
      240
    4. 4
      Steven P.
      165
    5. 5
      +FloatingFatMan
      159
  • Tell a friend

    Love Neowin? Tell a friend!