It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

Need help with code

Moderator: dafunkymunky

Need help with code

Postby Ksmartman on Fri Feb 04, 2011 1:50 am

Ok my question states-

Request an odd number, and display a triangle similar to the one in figure 6. , with the input number of starts in the top row.

-So basically we ask the user for an odd number and take their input and make a triangle descending to zero.

Figure 6.
********
*******
******
*****
****
***
**
*

My code:

Dim i As Integer
Dim num As String = txtout.text


For i = 1
txtout.AppendText("*")
Next i
txtout.AppendText(ControlChars.NewLine)
For i = 1
txtout.AppendText("*")
Next i
txtout.AppendText(ControlChars.NewLine)

---Im stuck from here, any help is appreciated.
Ksmartman
 
Posts: 1
Joined: Fri Feb 04, 2011 1:46 am

Re: Need help with code

Postby sanjon on Thu Feb 24, 2011 9:47 am

I just saw this post and thought I could help you out. Here is what I'd do:

Code: Select all
Public Class Form1
    Dim input, i, tempnum As Integer
    Dim output As String
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        input = 5
        i = 0
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Do Until i = input
            tempnum = input
            Do Until tempnum = 0
                output = output & "*"
                tempnum -= 1
            Loop
            output = output & vbNewLine
            input -= 1
        Loop
        MessageBox.Show(output)
    End Sub
End Class


I just added one button to the form to execute the command. In this example I set the input to 5. You can set this value to the number that the user enters.
sanjon
 
Posts: 40
Joined: Sun Dec 05, 2010 6:20 pm


Who is online

Users browsing this forum: No registered users and 4 guests