I mean for DOS it works but when I bring the code over to C# windows.forms every time I click on the button that's suppose to print out the double sided Asterisk Pyramid like this below:
* * * * * * * * * * * * * * * * * * * *
It only prints out one Asterisk mark, not even an entire row of asterisk. Help would be appreciated.
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 Asterisks
{
public partial class frmAsterisks : Form
{
public frmAsterisks()
{
InitializeComponent();
}
public void Asterisk(string TemporaryText)
{
//local variables
int Asterisks;
int Asterisk2;
int Asterisk3;
int Text;
int Rows = 0;
//I assign the variable Text to the textbox here.
Text = Convert.ToInt32(this.txbAsterisks.Text);
//if the value is less then 1 then throw an invalid argument to the user.
if (Text < 1)
{
//This is the first line in the command that asks the user for a number.
MessageBox.Show("You entered in a number or a value that can not be excepted, therefore it is an invalid value. Please enter in a number that is greater then 0 but not 0 itself.", "Invalid input", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
this.lstAsterisks.Text = null;
}
//This prints the top half of the hourglass, which is the inverse of the bottom half
for (Rows = 0; Rows < Text; Rows++)
{
//This for loop defines the space lenght between the corner of the textbox and the location of the the asterisks.
for (Asterisks = Text; Asterisks >= Rows; Asterisks--)
{
//Console.write
TemporaryText = "";
}
//This is where the first asterisks is being print, but I left it empty.
for (Asterisk2 = 1; Asterisk2 <= Rows + 1; Asterisk2++)
{
TemporaryText = " ";
}
//This prints out the asterisks after number 1 of asterisk. ex. 3,4,5
for (Asterisk3 = Text; Asterisk3 >= Rows + 1; Asterisk3--)
{
TemporaryText = " *";
}
//This draws out or prints out the asterisks on the bottom half.
//Console.Writeline
this.lstAsterisks.Text = Convert.ToString(TemporaryText);
}
//This prints the bottom half of the hourglass
for (Rows = 0; Rows < Text; Rows++)
{
//This for loop defines the space lenght between the corner of the textbox and the location of the the asterisks.
for (Asterisks = Text; Asterisks >= Rows; Asterisks--)
{
TemporaryText = " ";
}
//This is to print the first asterisks with one space to the left of the asterisks
for (Asterisk2 = 1; Asterisk2 <= Rows + 1; Asterisk2++)
{
TemporaryText = " *";
}
//This prints out the asterisks after number 1 of asterisk. ex. 3,4,5
for (Asterisk3 = Text; Asterisk3 <= Rows - 1; Asterisk3++)
{
TemporaryText = "*";
}
//This draws out or prints out the asterisks on the bottom half.
this.lstAsterisks.Text = Convert.ToString(TemporaryText);
}
}
private void btnAsterisks_Click(object sender, EventArgs e)
{
//This is to call the function above.
Asterisk(this.lstAsterisks.Text);
}
}
}
This post has been edited by macosxnerd101: 09 November 2010 - 05:43 PM
Reason for edit:: Added end code tag.

New Topic/Question
Reply




MultiQuote








|