Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate a random customer number and display it in a textbox
    text
    copied!<p>im totally stuck here on creating a random number. Ideally not the same number twice as its a customer number.</p> <p>I then need to display it in my tb_id (textbox) and write the line into a customer file.</p> <p>Any help here would be great.</p> <pre><code>private void button1_Click(object sender, EventArgs e) { **var rng = new Random();** // Here I need to write the random number (it's a customer number) to the tb_id text box. so I'm able to write it to their customer file afterwards. try { string fileName = string.Format(tb_surname.Text); if (tb_firstname.Text == "" || fileName == "" || tb_postcode.Text == "") { MessageBox.Show("Missing values from textboxes!"); } else if (File.Exists(fileName + "Text")) { if (MessageBox.Show("Warning: There is already a file with the surname you enter already on the system. Contents will be replaced - do you want to continue?", "File Demo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly) == DialogResult.Yes) { //write lines of text to file StreamWriter outputStream = File.CreateText(fileName + ".Txt"); outputStream.WriteLine(tb_firstname.Text); outputStream.WriteLine(tb_surname.Text); outputStream.WriteLine(tb_surname.Text); **outputStream.WriteLine(tb_id.Text);** outputStream.Close(); MessageBox.Show("Text saved to file successfully!"); this.Close(); } } } // ... } </code></pre> <p>part 2</p> <pre><code> // creating a random number here for the customer id Guid g = Guid.NewGuid(); tb_id.Text = g.ToString(); </code></pre> <p>to write Guid number to a text file.</p> <pre><code> outputStream.WriteLine(tb_id.Text); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload