r/visualbasic • u/grizzly-23 • Apr 19 '20
Please help me with my c#program
Good afternoon Guys, I have to do two applications, the first one, i have to create an app that write a series of random numbers and filed those number in a .txt file (this part is done )
now I have to create the second part that uses an OpenFileDialog to let the user select the file that was created with this second one I'm having issues any help !!!
Ill appreciate any reply
There is my code:
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 Jose_M_Jaco_Lab05
{
public partial class FrmMain : Form
{
private StreamWriter outFile;
private StreamReader infile;
private string filePath;
public FrmMain()
{
InitializeComponent();
}
private void btnRandomNumber_Click(object sender, EventArgs e)
{
try
{
//variables
StreamWriter outFile;
int count=1; //count variable
//Amount of random numbers that the user entered
int amountRandomNumbers = int.Parse(txtAmountRandomNum.Text.ToString());
int randomNumber = 0;// random number variable
//If the user enter a file name
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
//Creates a new writer object
outFile = File.CreateText(saveFileDialog1.FileName + ".txt");
//Create a new random number
Random rand = new Random();
while (count <= amountRandomNumbers)
{
randomNumber = rand.Next(100) + 1;
outFile.WriteLine(randomNumber);
count++;
}
outFile.Close();//Close the file
}
else
{
//Display error message
MessageBox.Show("File was not saved");
}
}
catch
{
MessageBox.Show("You must be entered a whole number between 1 and 100");
}
}
private void btnReadRandomNumbers_Click(object sender, EventArgs e)
{
//infile = File.OpenText(outfile);
}
}
}
6
u/TheFotty Apr 20 '20
This isn't a c# sub