Nogg
Nogg

Reputation: 337

Trying to build solution (debug it) and recieving an error saying the .exe is missing

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace as2
{
  class Program
  {
    static void Main(string[] args)
    {
      int id = 0, stock = 0, published = 0, newstock = 0;
      double price = 0.00;
      string type = " ", title = " ", author = " ";

      Program inventroy = new Program();
      inventroy.read_one_record(id, stock, published, 
        price, type, title, author);

      Console.WriteLine("Update Number In Stock");
      Console.WriteLine("=======================");
      Console.Write("Item ID: ");
      Console.Write(id);
      Console.WriteLine("Item Type: ");
      Console.Write(type);
    }

    void read_one_record(int id, int stock, int published, 
      double price, string type, string title, string author)
    {
      StreamReader myFile = File.OpenText("Inventory.dat");

      id = myFile.Read();
      stock = myFile.Read();
      published = myFile.Read();
      stock = myFile.Read();
      price = myFile.Read();
      type = myFile.ReadLine();
      title = myFile.ReadLine();
      author = myFile.ReadLine();

      myFile.Close();
    }

    void write_one_record(int id, int newstock, 
      int published, double price, string type, 
      string title, string author)
    {
      StreamWriter myFile = File.OpenWrite("Inventory.dat");

      myFile.WriteLine(id);
      myFile.WriteLine(newstock);
      myFile.WriteLine(published);
      myFile.WriteLine(price);
      myFile.WriteLine(type);
      myFile.WriteLine(title);
      myFile.WriteLine(author);

      myFile.Close();
    }
  }
}

Code is meant to open an inventory file, pull in the info, pass it back to main where in main I will ask the user to update the stock #. Then pass that number to writefunction where it writes it. For some reason when I try to launch to see if it works (code is not 100$ complete yet should still compile). It says something along the lines that the projects .exe is missing and cannot debug.

Upvotes: 0

Views: 257

Answers (1)

Joachim Isaksson
Joachim Isaksson

Reputation: 180887

You're not getting an EXE because you have an error in your code at the line

StreamWriter myFile = File.OpenWrite("Inventory.dat");

A FileStream isn't the same as a StreamWriter, but you can create a StreamWriter using

StreamWriter myFile = new StreamWriter(File.OpenWrite("Inventory.dat"));

Upvotes: 1

Related Questions