Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 6th, 2004, 3:54 AM   #11
lostcauz
Hobbyist Programmer
 
Join Date: Nov 2004
Location: 1691 miles East of L.A.
Posts: 159
Rep Power: 4 lostcauz is on a distinguished road
Private Sub Command1_Click()
  Dim numlines As Integer
  Dim i As Integer, j As Integer, k As Integer, b As Integer
  Text2.Text = vbNullString
  j = 0: b = 0
  numlines = Val(Text1.Text)
  For i = 1 To numlines
  b = b + i
  For k = 1 To b - 1
   If j = 0 Then Exit For
   j = j + 1
   Text2.Text = Text2.Text & j & " "
  Next k
  j = j + 1
  Text2.Text = Text2.Text & j & vbCrLf
  Next i
End Sub

'2 textboxes and one command button
'text2 should be large enough to hold the output
'and should have multiline=true along with vert.
'scrollbar unless prefer to print to form
'Likely could have done a better way but it's late.
'output:
'1
'2 3 4
'5 6 7 8 9 10
'11 12 13 14 15 16 17 18 19 20
'21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
__________________
-- lostcauz

Stepped in what?...
Behind whose barn?...
I didn't even know they had a cow!
lostcauz is offline   Reply With Quote
Old Nov 6th, 2004, 8:32 AM   #12
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Congratulations. BTW, the number of numbers in each row is are the triangular numbers - 1, 3, 6, 10, 15, 21 etc. The formula for the number of numbers in each row is ½n(n+1), or ½n² + ½n, where n is the row number.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Nov 7th, 2004, 12:09 AM   #13
lostcauz
Hobbyist Programmer
 
Join Date: Nov 2004
Location: 1691 miles East of L.A.
Posts: 159
Rep Power: 4 lostcauz is on a distinguished road
Quote:
Originally posted by Ooble@Nov 6 2004, 02:32 PM
Congratulations. BTW, the number of numbers in each row is are the triangular numbers - 1, 3, 6, 10, 15, 21 etc. The formula for the number of numbers in each row is ½n(n+1), or ½n² + ½n, where n is the row number.
Private Sub Command2_Click()
  Dim i As Integer, j As Integer, k As Integer, b As Integer
  
  For i = 1 To Val(Text1.Text)
   b = (i / 2) * (i + 1)
   For k = 1 To b
    j = j + 1
    Text2.Text = Text2.Text & j & " "
   Next k
   Text2.Text = Text2.Text & vbCrLf
  Next i

End Sub

That does look nicer.
__________________
-- lostcauz

Stepped in what?...
Behind whose barn?...
I didn't even know they had a cow!
lostcauz is offline   Reply With Quote
Old Nov 7th, 2004, 9:33 AM   #14
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
A lot nicer - congrats.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:56 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC