Visual basic. triangular


mattman

Still Fresh
Joined
Jul 23, 2006
Messages
66
so im in community college learning programming.... and have written VB code to determine a triangular number in a series.


first though i felt (for my own learning i needed to figure out how to actually produce a triangular number and this is what i came up with (it works)


Dim n As Integer 'number


Dim C As Integer ' counter


C = TextBox1.Text


n = (C + 1) * © / 2


Label1.Text = ("this is the triangular number of the count or input = " & n)


so then having figure this out I went and forged ahead with making a loop and producing a series


Dim N As Integer 'answer


Dim C As Integer ' counter


Dim S As Integer = Val(TextBox1.Text) ' series


N = (C + 1) * © / 2 ' sum for N


S = Val(TextBox1.Text) '0


C = 0


Do While C <= S ' start of loop c less/equal to S


For C = C To S


N = (C + 1) * © / 2 ' sum for N


ListBox1.Items.Add("triangular number of count or input = " & N) ' displays result of sum


Next C


Loop


Next piece for my own interest is figuring out a way of producing the next number in the triangle series with any input. ie if i input 8 the closest triangle number higher than 8 would be 10. unfortunately i havn't figured this out but i think i am close. so i think this is what programming is all about.. although im not a fan of vb its as good a place to start
 
Back
Top