Hi friends,
I have an interesting problem in vb.net. And I am struggling to get a solution for this trying for the past 3days.. It’s to calculate moving average for the inputs given by the user..
The following are the steps to make it clear..
1, get 2user inputs in textbox(1st input is number is periods, 2nd is moving range)
2, after getting both the user inputs, the user will click on an input button which must dynamically generate rows for the number of periods given by the user as well as a calculate button must appear dynamically.
3, the user again inputs the values the all the dynamically generated rows and when he presses calculate button, the moving average for the given moving range must appear in another column
I have done with half way and I have attached my progress here.. I would greatly appreciate if u complete it for me.. thanks in advance
CODE
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim TxtDyn1 As TextBox()
Dim TxtDyn2 As TextBox()
Dim TxtDyn3 As TextBox()
Dim TxtDyn4 As TextBox()
Dim numofper As Integer
Try
'to check the textbox for empty
If Not TextBox1.Text Is String.Empty Then
numofper = TextBox1.Text
ReDim TxtDyn1(numofper)
ReDim TxtDyn2(numofper)
ReDim TxtDyn3(numofper)
ReDim TxtDyn4(numofper)
Else
Exit Sub
End If
'To create the dynamic text box and add the controls to panel
For i As Integer = 0 To numofper - 1
TxtDyn1(i) = New TextBox
Panel1.Controls.Add(TxtDyn1(i))
Next
For j As Integer = 0 To numofper - 1
TxtDyn2(j) = New TextBox
Panel2.Controls.Add(TxtDyn2(j))
Next
For k As Integer = 0 To numofper - 1
TxtDyn3(k) = New TextBox
Panel3.Controls.Add(TxtDyn3(k))
Next
For l As Integer = 0 To numofper - 1
TxtDyn4(l) = New TextBox
Panel4.Controls.Add(TxtDyn4(l))
Next
Dim mybutton As New Button
mybutton.Text = "button 2"
AddHandler mybutton.Click, AddressOf PrintMessage
Me.Controls.Add(mybutton)
Catch ex As Exception
MsgBox("Enter a valid Number")
End Try
End Sub
Private Sub PrintMessage(ByVal sender As System.Object, ByVal e As System.EventArgs)
MsgBox("Dynamic event happened!")
End Sub
End Class
Mod edit - Fixed code tags.