d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Vb Triangles Of Asterisks > Needing Help With Simple Vb
Add Reply New Topic New Poll
Member
Posts: 1
Joined: Sep 29 2012
Gold: 0.00
Sep 29 2012 10:11pm
I have read a previous post reguarding this topic and though it was somewhat helpful, my problem is a bit more difficult. I'm to make four different triangles of asterisks that show one below the other.

*
**
***
****
*****
******
*******
********
*********
**********

**********
*********
********
*******
******
*****
****
***
**
*


**********
*********
********
*******
******
*****
****
***
**
*

*
**
***
****
*****
******
*******
********
*********
**********

however this is in a windows form. i have to use two buttons one for printing this when the size is between 3 and 15. and the other buttono is to clear all of these..

this isnt working right andim not sure what ive done wrong. here is what i have so far:

Public Class Form1

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
'pattern A
Dim i As Integer
For i = 1 To 10
TextBox1.Text = TextBox1.Text & String(i, "*") & vbCrLf

Next
'pattern B
Dim i As Integer
For i = 10 To 1 Step -1
TextBox1.Text = TextBox1.Text & String(i, "*") & vbCrLf

Next
'pattern C
Dim Asterisk As String
Dim outer As Integer
Dim inner As Integer

For outer = 10 To 1 Step -1
Asterisk = Space(10 - outer)
For inner = 1 To outer
Asterisk = Asterisk & "*"
Next

Next
'pattern D
Dim Asterisk As String
Dim outer As Integer
Dim inner As Integer

For outer = 1 To 10
Asterisk = Space(10 - outer)
For inner = 1 To outer
Asterisk = Asterisk & "*"
Next

Next


End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

End Sub
End Class





any help will be greatly appreciated
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 29 2012 10:22pm
1. Why are you putting anything in the text changed event? you should be handling the button's on click event
2. post what it looks like with your code
3. isolate each triangle to a separate method. this way you can easily test one piece at a time, and possibly reuse it as well
4. if you're having problems with loops, then start off without the loops. you can refactor piece by piece to make sure it's working correctly
5. write out your string to a string buffer (or whatever it's called in .NET). after it's fully written out, set the textbox's text to the string. this will help to decouple your logic from your UI, and also aid in #3

This post was edited by carteblanche on Sep 29 2012 10:51pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll