Hello everyone,

I am very new to programming, and I recently tried to develop a C++ application, but came accross alot of problems, and was advised to try C#.

Now, I have basicly used the same code...A bit different, And everything is working, except one thing.

String str1 = ("1");
String str2 = ("0");
String str3 = ("10^");
str1 = str1 + str2;
this.richTextBox1.Text = str1;
this.richTextBox2.Text = str3 + Convert.ToString(str1.Length -1);

I want, to have str1 + str2, then have that add on str2, then that add on str2, ect, forever.

Now, when I was working with integers, the old value would override so if I had

X = 10
Y = 10
X*Y=Y

Making Y 100

Then did X*Y again, the answer would be 1,000, ect. But this doesn't work with strings.

Can someone help me here?

I don't really get what you are trying to do.
the way you have it, textbox 1 should have "10" in it and
textbox two should have "10^1" in it.

What are you wanting to have in the two boxes?

I don't really get what you are trying to do.
the way you have it, textbox 1 should have "10" in it and
textbox two should have "10^1" in it.

What are you wanting to have in the two boxes?

Yes, That is what is happening...

I want to, when I click the start button for it to have 1 then add 0's on the end until the stop button is pressed, then in the other text box it shows the index form of that number.

I just need to continuously add str2

use +=

str1="1";
str2="0";
str1+=str2; //str1 is now "10"
str1+=str2; //str1 is now "100"
str1+=str2; //str1 is now "1000"

use +=

str1="1";
str2="0";
str1+=str2; //str1 is now "10"
str1+=str2; //str1 is now "100"
str1+=str2; //str1 is now "1000"

This code doesn't do anything different to mine.....

I want all of this code under a button...So when I press the button a second time, it adds another zero onto what is already there.

Here is my code, under the button so far...

private void button1_Click(object sender, EventArgs e)
{
this.toolStripStatusLabel1.Text = "Running";
this.richTextBox1.Text = "";
this.richTextBox2.Text = "";
if (this.toolStripStatusLabel1.Text == "Running")
{
String str1 = ("1");
String str2 = ("0");
String str3 = ("10^");
//str1 += str2;
//System.Text.StringBuilder.Append(str1);
str1 = str1 + str2;
this.richTextBox1.Text = str1;
this.richTextBox2.Text = str3 + Convert.ToString(str1.Length -1);
}
else
{

}
}

I want to make it, so when I click the button, it shows a 10, Then I click the button again, it shows 100, then again, 1000.

All help apreaciated.

Brendan.

private void button1_Click(object sender, EventArgs e)
{

if( this.richTextBox1.Text == "")
    richTextBox1.Text = "1";
    
this.toolStripStatusLabel1.Text = "Running";
//this.richTextBox1.Text = "";
this.richTextBox2.Text = "";
if (this.toolStripStatusLabel1.Text == "Running")
{
	
String str1 = richTextBox1.Text;
String str2 = ("0");
String str3 = ("10^");
//str1 += str2;
//System.Text.StringBuilder.Append(str1);
str1 = str1 + str2;
this.richTextBox1.Text = str1;
this.richTextBox2.Text = str3 + Convert.ToString(str1.Length -1);
}
else
{

}
}

Thank you heaps!!!

Now...When I tried adding a break and contine it didn't work...Said there wasn't an enclosing loop....

private void button1_Click(object sender, EventArgs e)
{
if (this.richTextBox1.Text == "")
{
richTextBox1.Text = "1";
}
this.toolStripStatusLabel1.Text = "Running";
//this.richTextBox1.Text = "";
this.richTextBox2.Text = "";
if (this.toolStripStatusLabel1.Text == "Running")
{
String str1 = richTextBox1.Text;
String str2 = ("0");
String str3 = ("10^");
//str1 += str2;
//System.Text.StringBuilder.Append(str1);
str1 = str1 + str2;
this.richTextBox1.Text = str1;
this.richTextBox2.Text = str3 + Convert.ToString(str1.Length - 1);
}
else
{
break;
}
continue;
}

Oh dear Wreef you are trying to program without learning programming first. You really need to get a book for beginners and start from the beginning, you are trying to jump in the middle.

I get the impression you are doing this in an ASP.NET aspx web page? or are you doing a windows forms project (a desktop application)?

Anyway assuming web page (cos you mentioned web browser in an earlier post) Then I would advise doing this client side (in the browser) using javascript. Here is an example:

googleplex.htm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
	<title>Googleplexer - By Holly styles</title>
	<META NAME="Generator" CONTENT="CodePad">
	<META NAME="Author" CONTENT="">
	<META NAME="Keywords" CONTENT="">
	<META NAME="Description" CONTENT="">
         <script type="text/javascript">
         	//global variable to keep tabs on the running state of our machine
                 var running = false;
                 
                 function multByTen()
                 {
                         var curNum;
                         if(running) //check we are still running;
                         {
                              curNum = document.getElementById("googlenum").value;
                              curNum = curNum + "0";
                              document.getElementById("googlenum").value = curNum;
                              document.getElementById("googleindex").value = "10^" + (curNum.length -1);
                              
                              //to keep things going call myself(this function) every second - 1000 = milliseconds
                              window.setTimeout(multByTen, 1000);
                         } 
                 }
                 
                 function startGoogleplex()
                 {
                 	//set state to running
                         running = true;
                         //call the function to start things going
                         multByTen();
                 }
         </script>
</head>
<body>

	<input id="googlenum" type="text" value="1" style="width: 400px;">
         <br>
         <input id="googleindex" type="text" value="10^">
         <br>
         <input id="googlestart" type="button" onclick="startGoogleplex();" value="Start">
         <input id="googlestop" type="button" onclick="javascript: running = false;" value="Stop">

</body>
</html>

Stick this in a plain old .htm file and browse to it using IE or Firefox or whatever browser you use.

Sorry, I am actualy doing a windows form.

That other post was for another project....Sorry about confussion.

This program was just for me to get the idea of strings, ect, All I want is the repeat function so I don't have to keep clicking the button.

All my program works now, except for this repeat.

help appreaciated.

I promise I'll get a book :p

Ok, I got it working using the While statement.

private void button1_Click(object sender, EventArgs e)
{
if (this.richTextBox1.Text == "")
{
richTextBox1.Text = "1";
}
this.toolStripStatusLabel1.Text = "Running";
this.richTextBox2.Text = "";
while (this.toolStripStatusLabel1.Text == "Running")
{
String str1 = richTextBox1.Text;
String str2 = ("0");
String str3 = ("10^");
str1 = str1 + str2;
this.richTextBox1.Text = str1;
this.richTextBox2.Text = str3 + Convert.ToString(str1.Length - 1);
}
}

Problem is, as most of you can tell from reading the code...Is it crashes! Is there anyway to slow the process down? So it goes fast, but just fast enough so my computer can handle it?

This article has been dead for over six months. Start a new discussion instead.