Question

Ive started this program for you already. In canvas is a .zip file that you can download containing much of this program alrI OOI box. Pointer FontDialog OpenFileDialog ASaveFileDialog The file location where the SaveFileDialog should default to wheQuick Launch (Ctri+Q) FileWriter-Microsoft Visual Studio File Edit View Project Build Debug Team Tools Test Analyze Window Heusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace FileWriter
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void btnCreate_Click(object sender, EventArgs e)
{
try
{
//write code that assigns the value in the textbox to an Integer variable


if // write code that validates whether or not the data entered in the textbox is greater than or equal to 1 *
{

try
{


SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.CheckFileExists = false;
saveFileDialog1.InitialDirectory = //complete the code for the InitialDirectory property
saveFileDialog1.RestoreDirectory = true;

if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
string strFileName = saveFileDialog1.FileName;
FileStream fileOut = new FileStream(strFileName, FileMode.Create);
StreamWriter writer = new StreamWriter(fileOut);

//Create an object of the Random class
Random rand = new Random();
int randomNumber = rand.Next(0, 100);

for (/* program a loop condition that repeats a number of times equal to the number entered in the textbox */
{
//write code that generates a random number and writes it into the .txt file

writer.WriteLine(randomNumber.ToString());
}
//close the writer object
}
}
catch
{
MessageBox.Show("Error saving the changes to the data file.",
"Error Saving Data", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("Please enter an integer greater than zero");
}
}

  
catch
{
MessageBox.Show("Please enter an integer greater than zero");
}

}
}
}

I've started this program for you already. In canvas is a .zip file that you can download containing much of this program already developed. Your task will be to program a few, specific areas of the program. Download the program, open it, and look at the source code in Form1.cs. Everywhere you see a green comment is code that you are responsible for programming. The "Create File" button needs to open a SaveFileDialog where the user can create a custom filename for the file. Make sure to include a SaveFileDialog control in your application. You can find this in your Toolbox. Pointer ColorDialog FolderBrowserDialog FontDialog OpenFileDialog ileDialog The file location where the SaveFileDialog should default to when saving the file (using the code InitialDirectory Application.StartupPath) is the Debug folder, which is located inside the Bin folder for your project. After the file is saved, there should be several randomly generated numbers in the newly created .txt file. - The numbers must be randomly generated - The numbers must be between O and 100 - Each number should be on a separate line - The quantity of numbers should match the number value entered into the textbox in the form
I OOI box. Pointer FontDialog OpenFileDialog ASaveFileDialog The file location where the SaveFileDialog should default to when saving the file (using the code InitialDirectory Application.StartupPath) is the Debug folder, which is located inside the Bin folder for your project. After the file is saved, there should be several randomly generated numbers in the newly created .txt file. The numbers must be randomly generated - The numbers must be between 0 and 100 Each number should be on a separate line The quantity of numbers should match the number value entered into the textbox in the form The textbox should only be allowed to accept integer values of 1 or greater. Do not allow a non-integer value to be entered - this can be accomplished by typing an int.Parse() method inside a try-catch statement; this should be the first data validation in your program. Do not allow a number less than one to be entered this can be accomplished with an if-else statement. Include an "Exit" button to close the form.
Quick Launch (Ctri+Q) FileWriter-Microsoft Visual Studio File Edit View Project Build Debug Team Tools Test Analyze Window Help Thuong DoanTD Toolbox Search Toolbox p General Forml.cs* ㄨ Solution Explorer ρ FileWriter -Ί .; FileWriter.Formi О" btnCreate-Click(object sender. Event A @ . -®, S () 25 //write code that assigns the value In the textbox to an Integer variable Search Solution Explorer (Ctri+ 27 Elf (/-write code that validates whether or not the data entered in the textbox is Solution FileWriter' (1 project) FileWriter DProperties 30 DReferences App.config DProgram.cs 32 Form1.cs 35 36 37 38 39 SaveFileDialog saveFileDialogi new SaveFileDialog); saveFileDialog1.Filter txt files (.txt).txt All files (.*" saveFileDialog1.FilterIndex - 1; saveFileDialog1.CheckFileExists-false; saveFileDialog1.InitialDirectoryI/complete the code for the InitialDirec RestoreD - true Solution Explorer lf (saveFileDialogi. ShowDialog() = DialogResult.OK) string strFileName-saveFileDialog1.FileName; FileStrean fileout new Filestream(strFileNane, FileMode.Create); Streanklriter writer new streanklriter(fileOut); 46 47 //Create an object of the Random class Random rand new Random(); int randonNumber rand . Next(0, 100); for (program a loop condition that repeats a number of times equal t 53 //write code that generates a random number and writes it into the writer.WriteLine (randomNumber.Tostring)); 57 58 //close the writer object 100% Ln 75 Col 14 Ch 14 Add to Source Control 12:22 AM O Type here to search ^%a) / 4, ENG 3/20/2019
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Design

Form1 Enter number Create Exit

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace FileWriters
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnCreate_Click_1(object sender, EventArgs e)
{

}

private void btnCreate_Click(object sender, EventArgs e)
{
try
{
// assign value from text box to integer variable
int number = Int32.Parse(txtNumber.Text);

if (number > -1)
{
try
{

SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.CheckFileExists = false;
saveFileDialog1.InitialDirectory = Application.StartupPath;
saveFileDialog1.RestoreDirectory = true;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
string strFileName = saveFileDialog1.FileName;
FileStream fileOut = new FileStream(strFileName, FileMode.Create);
StreamWriter writer = new StreamWriter(fileOut);
//Create an object of the Random class
Random rand = new Random();
int randomNumber;
for (int i = 0; i < number; i++)
{
//write code that generates a random number and writes it into the .txt file
randomNumber = rand.Next(0, 100);
writer.WriteLine(randomNumber.ToString());
}
//close the writer object
writer.Close();
}
}
catch
{
MessageBox.Show("Error saving the changes to the data file.",
"Error Saving Data", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("Please enter an integer greater than zero");
}
}

catch
{
MessageBox.Show("Please enter an integer greater than zero");
}
}

private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}

File Edit Format View Help h4 92 28

Add a comment
Know the answer?
Add Answer to:
Using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; u...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please use Python for this program Random Number File Writer Write a program that writes a...

    Please use Python for this program Random Number File Writer Write a program that writes a series of random numbers to a file. Each random number should be in the range 1 through 500. The program should let the user specify how many random numbers to put into the file. The name of the file to write to should be 'random.txt'. Submit the random.txt file generated by your program with the assignment. Sample program execution: Python 3.4.3 Shell Eile Edit...

  • I need help in Python. This is a two step problem So I have the code...

    I need help in Python. This is a two step problem So I have the code down, but I am missing some requirements that I am stuck on. Also, I need help verifying the problem is correct.:) 7. Random Number File Writer Write a program that writes a series of random numbers to a file. Each random number should be in the range of 1 through 500. The application should let the user specify how many random numbers the file...

  • Read your notes concerning 2D arrays with particular attention to the syntax of passing arrays as...

    Read your notes concerning 2D arrays with particular attention to the syntax of passing arrays as parameters to functions. Write the pseudocode (algorithm) for the following program definition: A text file contains a square matrix of integer numbers. The file contains an integer number indicating the identical number of rows and columns followed by the data itself (that number cannot be larger than 100). For example, a file containing a 3x3 matrix would contain 3 followed by 9 other integer...

  • Write a python program and pseudocode The Program Using Windows Notepad (or similar program), create a...

    Write a python program and pseudocode The Program Using Windows Notepad (or similar program), create a file called Numbers.txt in your the same folder as your Python program. This file should contain a list on floating point numbers, one on each line. The number should be greater than zero but less than one million. Your program should read the following and display: The number of numbers in the file (i.e. count them) (counter) The maximum number in the file (maximum)...

  • Select the correct answer. (1)     Which of the following will open a file named MyFile.txt and...

    Select the correct answer. (1)     Which of the following will open a file named MyFile.txt and allow you to read data from it?                (a)      File file = new File("MyFile.txt");           (b)      FileWriter inputFile = new FileWriter();           (c)       File file = new File("MyFile.txt");                      FileReader inputFile = new FileReader(file);           (d)      FileWriter inputFile = new FileWriter("MyFile.txt"); (2)     How many times will the following do - while loop be executed?                      int x = 11;             do {             x...

  • This is a JAVA language The files provided in the code editor to the right contain...

    This is a JAVA language The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. Note: DebugData2.txt does not need to be edited. It is used by the program. DebugData2.txt 435-9845 239-9845 981-9883 384-5656 875-3784 874-8120 DebugThirteen2.java // Program reads in a file of phone numbers without area codes // inserts "(312)...

  • If necessary, create a new project named Intermediate24 Project and save it in the Cpp8\Chap14 folder....

    If necessary, create a new project named Intermediate24 Project and save it in the Cpp8\Chap14 folder. Also create a new source file named Intermediate24.cpp. If you are using Microsoft Visual C++, copy the Intermediate24.txt file from the Cpp8\Chap14 folder to the Cpp8\Chap14\Intermediate24 Project folder. Use a text editor to open the Intermediate24.txt file, which contains payroll codes and salaries. Close the Intermediate24.txt file. Create a program that allows the user to enter a payroll code. The program should search for...

  • I need help writing these 2 programs please include all the indents :) In this programming...

    I need help writing these 2 programs please include all the indents :) In this programming challenge you are to create two Python programs: randomwrite.py andrandomread.py. One program, randomwrite.py, is to write a set of random numbers to a file. The second program, randomread.py, is to read a set of random numbers from a file, counts how many were read, displays the random numbers, and displays the total count of random numbers. Random Number File Writer (randomwrite.py) Create a program...

  • CIST 2371 Introduction to Java Unit 03 Lab Due Date: ________ Part 1 – Using methods...

    CIST 2371 Introduction to Java Unit 03 Lab Due Date: ________ Part 1 – Using methods Create a folder called Unit03 and put all your source files in this folder. Write a program named Unit03Prog1.java. This program will contain a main() method and a method called printChars() that has the following header: public static void printChars(char c1, char c2) The printChars() method will print out on the console all the characters between c1 and c2 inclusive. It will print 10...

  • There is a file called mat2.txt in our files area under the Assignments folder. Download it...

    There is a file called mat2.txt in our files area under the Assignments folder. Download it and save it in the same folder where this Matlab file (HW08_02.m) is saved. It may be worth opening that text file to see how it is set out. Note well, however, that the file might have a different number of lines and different number of numbers on each line. Write a Matlab program that does the following: Prompt the user for an input...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT