Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

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

        Random m_objRandom = new Random();


        private void button1_Click(object sender, EventArgs e)
        {



            for (int lcv = 1; lcv <= 50; lcv++)
            {
                int random = m_objRandom.Next(1, 10) ;
                TextBoxRandom.Text += lcv;
                TextBoxRandom.Text = Convert.ToString(random);

                if (lcv % 5)
                {
                    TextBoxRandom.Text= "\t" + random;
                }
            }



        }
    }
}




Its supposed to look like this https://docs.google.com/a/stfrancisprep.org/file/d/0BysHYxF8DhNlTFM3aTNmbUd0ams/edit[^]
Posted
Comments
deepankarbhatnagar 12-Dec-14 11:06am    
Not getting your requirement, please elaborate it.
OriginalGriff 12-Dec-14 11:13am    
If you want people to look at images on google docs, then you need to give them permission... :sigh:

Don't post image links (particularly ones nobody but you can look at). Instead, edit your question and demonstrate the text you want to see.
If you use the "code" widget above the edit textbox, it will preserve any formatting for you.
Don't be lazy, make it easy for us to help you!

Use the "Improve question" widget to edit your question and provide better information.
Sergey Alexandrovich Kryukov 12-Dec-14 12:37pm    
Numbers don't have "format". You are "converting" number to strings, why? What's the problem? Read about formatting and format things the way you want.
—SA

Please see my comment to the question.

Don't use the class Convert, use one of the int.ToString, the one with a parameter(s) defining formatting of the string: http://msdn.microsoft.com/en-us/library/System.Int32.ToString%28v=vs.110%29.aspx[^].

Read about format specifiers:
http://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/0c899ak8(v=vs.110).aspx[^].

—SA
 
Share this answer
 
I can guess you want to insert tab between each block of 5 digits, so...

C#
Random m_objRandom = new Random();
StringBuilder sb = new StringBuilder();

for (int lcv = 0; lcv < 50; lcv++)
{
	int random = m_objRandom.Next(1, 10);
	if ((lcv % 5)==0)
	{
		sb.Append("\t" + random);
	}
	else
	{
		sb.Append(random);
	}
}

Console.WriteLine(sb.ToString());

Result:
82623  37792  42854  83117  73372  67543  39464  48761  11917  66761
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900