borderAndreaVB free resources for Visual Basic developersborder

ASP.NET 3.5 Hosting - DiscountASP.NET

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2008 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Next Topic (Duplicate OLED Chart to another OLEDB container) New Topic New Poll Post Reply
AndreaVB Forum : VB General : numbers in triangular form
Poster Message
frennii
Level: Trainee

Registered: 15-02-2008
Posts: 3

icon numbers in triangular form

we have a project:

create an application that will display on the listbox the following:

                        1
                      21
                    321
                  4321
                54321
              654321
            7654321
          87654321
        987654321
    10987654321

but what i created is exactly like this:

1
22
333
4444
55555
666666
7777777
88888888
999999999
1111111111

please help. here's my code:

Private Sub lsttriangle_KeyPress(KeyAscii As Integer)
Dim n As Integer  'Number of rows
        Dim i As Integer 'Counter
    n = Val(InputBox("Enter number of rows"))
    For i = 1 To n
        lsttriangle.AddItem String(i, Asc(i))
    Next i

End Sub








15-02-2008 at 12:40 PM
View Profile Send Email to User Show All Posts | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1632
icon Re: numbers in triangular form


Private Sub lsttriangle_KeyPress(KeyAscii As Integer)
Dim n As Integer  'Number of rows
        Dim i As Integer 'Counter
        Dim output as String

        n = Val(InputBox("Enter number of rows"))
        output = ""

        For iLine = 1 to n
                For i = iLine To 1 step -1 'may need to just add the 1
                    output = output & chr(i)
                Next
                lsttriangle.AddItem output
        Next
End Sub


____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)

15-02-2008 at 02:06 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 1007
icon Re: numbers in triangular form

Hi
Minor modification to get the text right-aligned:

lsttriangle.additem right(string(" ",iLine) & output,iLine)

Can't remember if listbox has property for alignment, however, you can set it to rightalign using api.


____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

16-02-2008 at 02:34 AM
View Profile Send Email to User Show All Posts | Quote Reply
frennii
Level: Trainee

Registered: 15-02-2008
Posts: 3
icon Re: numbers in triangular form

quote:
JLRodgers wrote:

Private Sub lsttriangle_KeyPress(KeyAscii As Integer)
Dim n As Integer  'Number of rows
        Dim i As Integer 'Counter
        Dim output as String

        n = Val(InputBox("Enter number of rows"))
        output = ""

        For iLine = 1 to n
                For i = iLine To 1 step -1 'may need to just add the 1
                    output = output & chr(i)
                Next
                lsttriangle.AddItem output
        Next
End Sub



when run the output is this:


16-02-2008 at 02:50 PM
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 1007
icon Re: numbers in triangular form

hi
you need to clear the variable:

Private Sub lsttriangle_KeyPress(KeyAscii As Integer)
Dim n As Integer  'Number of rows
        Dim i As Integer 'Counter
        Dim output as String

        n = Val(InputBox("Enter number of rows"))
        
        For iLine = 1 to n
                output = ""

                For i = iLine To 1 step -1 'may need to just add the 1
                    output = output & i
                Next
                lsttriangle.AddItem output
        Next
End Sub



[Edited by stickleprojects on 17-02-2008 at 11:01 PM GMT]

____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

16-02-2008 at 09:50 PM
View Profile Send Email to User Show All Posts | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1632
icon Re: numbers in triangular form

Oops, sorry about the not clearing part.  I just typed it out without testing it.

[Edited by JLRodgers on 17-02-2008 at 06:42 PM GMT]

____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)

18-02-2008 at 12:38 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
frennii
Level: Trainee

Registered: 15-02-2008
Posts: 3
icon Re: numbers in triangular form

its already working, thank you very much but how can i set it into right alignment?ü   thank you again..ü

18-02-2008 at 01:18 AM
View Profile Send Email to User Show All Posts | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1632
icon Re: numbers in triangular form

Not sure if there's code here or not... but a quick search in google for it yielded:
http://vbnet.mvps.org/code/listapi/listrightalignstylebits.htm


____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)

18-02-2008 at 05:23 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : VB General : numbers in triangular form
Next Topic (Duplicate OLED Chart to another OLEDB container) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2008 Andrea Tincaniborder