#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    8
    Rep Power
    0

    Need Help with Code


    I had to write a code that displays this
    *****
    *****
    *****
    I had to use the For...Next statements. The code works, except when I hit the start button to calculate it displays this
    *****
    *****
    *****
    If I hit it again it adds to it.
    *****
    *****
    *****
    *****
    *****
    *****
    and it keeps going if I keep hitting the button. How can I stop it at the first calculation?

    Here is the code.

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    For x As Integer = 1 To 3 Step 3
    For y As Integer = 1 To 9 Step 2
    asterisksLabel.Text = asterisksLabel.Text & "*"
    Next y
    asterisksLabel.Text = asterisksLabel.Text & ControlChars.NewLine
    Next x
    For x As Integer = 1 To 3 Step 2
    For y As Integer = 1 To 9 Step 2
    asterisksLabel.Text = asterisksLabel.Text & "*"
    Next y
    asterisksLabel.Text = asterisksLabel.Text & ControlChars.NewLine
    Next x
    End Sub
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    289
    Rep Power
    45
    It is doing exactly what you told it to do. It is adding 3 sets of 5 asterisks to the existing text each time you click the command button. If you want to refresh the displayed text, you must clear the box first:
    asterisksLabel.Text = ""

    J.A. Coutts
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    8
    Rep Power
    0

    Thanks


    I finally figured it out that I needed that before the code started. Thanks for the information

IMN logo majestic logo threadwatch logo seochat tools logo