473,513 Members | 3,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Vb.net Interesting Problem- Moving Average

31 New Member
Hi friends,
I have an interesting problem in vb.net. And I am struggling to get a solution for this..m trying for the past 3days.. It’s to calculate moving average for the inputs given by the user..

The following are the steps..
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 for all the dynamically generated rows and when by pressing calculate button, the moving average for the given moving range must appear in another column

Im half way through and I have attached my progress here.. I would greatly appreciate if u complete it for me.. thanks in advance

Expand|Select|Wrap|Line Numbers
  1. Partial Public Class _Default
  2.     Inherits System.Web.UI.Page
  3.  
  4. Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  5.  
  6.         Dim TxtDyn1 As TextBox()
  7.         Dim TxtDyn2 As TextBox()
  8.         Dim TxtDyn3 As TextBox()
  9.         Dim TxtDyn4 As TextBox()
  10.         Dim numofper As Integer
  11.  
  12.         Try
  13.  
  14.             'to check the textbox for empty
  15.  
  16.             If Not TextBox1.Text Is String.Empty Then
  17.                 numofper = TextBox1.Text
  18.                 ReDim TxtDyn1(numofper)
  19.                 ReDim TxtDyn2(numofper)
  20.                 ReDim TxtDyn3(numofper)
  21.                 ReDim TxtDyn4(numofper)
  22.  
  23.             Else
  24.                 Exit Sub
  25.             End If
  26.  
  27.             'To create the dynamic text box and add the controls to panel
  28.             For i As Integer = 0 To numofper - 1
  29.                 TxtDyn1(i) = New TextBox
  30.                 Panel1.Controls.Add(TxtDyn1(i))
  31.             Next
  32.             For j As Integer = 0 To numofper - 1
  33.                 TxtDyn2(j) = New TextBox
  34.                 Panel2.Controls.Add(TxtDyn2(j))
  35.             Next
  36.             For k As Integer = 0 To numofper - 1
  37.                 TxtDyn3(k) = New TextBox
  38.                 Panel3.Controls.Add(TxtDyn3(k))
  39.             Next
  40.             For l As Integer = 0 To numofper - 1
  41.                 TxtDyn4(l) = New TextBox
  42.                 Panel4.Controls.Add(TxtDyn4(l))
  43.             Next
  44.  
  45.             Dim mybutton As New Button     (THIS S NOT WORKING )
  46.             mybutton.Text = "button 2"
  47.             AddHandler mybutton.Click, AddressOf button2.click
  48.             Me.Controls.Add(mybutton)
  49.  
  50.         Catch ex As Exception
  51.             MsgBox("Enter a valid Number")
  52.         End Try
  53.  
  54.     End Sub
  55.  
  56.  
  57. End Class
Oct 4 '08 #1
5 2688
Plater
7,872 Recognized Expert Expert
Why not use a DataGridView?
You can tell it to have X amount of columns and Y amount of rows, as well as a button column for doing the calculate?
That would let your user enter data in the correct format?
Oct 6 '08 #2
adarshyam
31 New Member
ya i dont know how to use datagridview.. im new to vb.net.. can you please help me in finishing from this point.. because i have my submission tomorrow
Oct 6 '08 #3
Plater
7,872 Recognized Expert Expert
Well I cannot give you answers to your homework assignments.If its due this soon, you might not want to make such a drastic switch.

What part of that button code is not working?
Oct 6 '08 #4
adarshyam
31 New Member
i have created two text boxes for user input,.. 1st box ll get the number of rows needed in the columns and 2nd box ll get the moving average range. and for example if the user enters 10 and clicks on button1, then 10 rows of text boxes will be created dynamically.. til this i have done..

Now what i want is to display another button dynamically after the rows r displayed .. button name calculate.. and after the user enters all values in column no.3 and presses calculate button, the moving average for the given range(textbox2) must be calculated in column no.4 .. [ column 1 &2 are just for misc inputs so not important]. for ex..
textbox 1 10
textbox 2 2

10
20
10 15
40 15
10 25
20 25
10 15
20 15
10 15
20 15


hope u understand my prob.. pls help me with some ideas
Oct 6 '08 #5
adarshyam
31 New Member
can you please help me correcting errors.. i was trying it for days..


Partial Public Class _Default
Inherits System.Web.UI.Page

Dim textdynamic1 As New ArrayList()
Dim textdynamic2 As New ArrayList()
Dim textdynamic3 As New ArrayList()
Dim textdynamic4 As New ArrayList()

Dim TxtDyn1 As TextBox()
Dim TxtDyn2 As TextBox()
Dim TxtDyn3 As TextBox()
Dim TxtDyn4 As TextBox()

Dim numofper As Integer
Dim nval As Integer

Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


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, save them in session state

For i As Integer = 0 To numofper - 1
TxtDyn1(i) = New TextBox
Panel1.Controls.Add(TxtDyn1(i))
textdynamic1.Add(textdynamic1)
Session("key1") = textdynamic1
Next
For j As Integer = 0 To numofper - 1
TxtDyn2(j) = New TextBox
Panel2.Controls.Add(TxtDyn2(j))
textdynamic2.Add(textdynamic2)
Session("key2") = textdynamic2
Next
For k As Integer = 0 To numofper - 1
TxtDyn3(k) = New TextBox
Panel3.Controls.Add(TxtDyn3(k))
textdynamic3.Add(textdynamic3)
Session("key3") = textdynamic3
Next
For l As Integer = 0 To numofper - 1
TxtDyn4(l) = New TextBox
Panel4.Controls.Add(TxtDyn4(l))
textdynamic4.Add(textdynamic4)
Session("key4") = textdynamic4
TxtDyn4(l).Enabled = False

Next

Catch ex As Exception
MsgBox("Enter a valid Number")
End Try

End Sub


Public Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
nval = TextBox2.Text

Dim sum As Integer
Dim k As Integer
Dim l As Integer

'retrieving values from session state and calculating moving average

If Session("key3") IsNot Nothing Then
If Session("key4") IsNot Nothing Then
Dim newArr1 As ArrayList = DirectCast(Session("key3"), ArrayList)
Dim newArr2 As ArrayList = DirectCast(Session("key4"), ArrayList)

For t As Integer = (nval + 1) To numofper
Do
Do
sum += TxtDyn3(k).Text
k += 1

Loop While k <= nval

TxtDyn4(l).Text = sum / nval
l += 1

Loop While l <= numofper
Next
End If
End If


End Sub


End Class
Oct 7 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

56
4048
by: Dave Vandervies | last post by:
I just fixed a bug that some of the correctness pedants around here may find useful as ammunition. The problem was that some code would, very occasionally, die with a segmentation violation error. (Not as infrequent as some bugs that have been discussed here in the past, but maybe once in an overnight run of the program when it was...
7
3017
by: git_cs | last post by:
Hey, guys and gals Somedays ago, I had asked for the DES algorithm in C language. Although I have written the algorthim in C myself, I am facing a peculiar problem, which I hope some of u guys and gals solve. I use Turbo C++ version 3.0 and WINXP as the operating system. Pls observe the following program. 1 #include<stdio.h>...
23
2000
by: Bruno R. Dias | last post by:
Perhaps it would be interesting to program a virtual machine simulating an ancient computer (such as the pdp-7). Then, it would be rather interesting to code for it (porting gcc to it maybe?). I think it would be fun to play with the long-forgotten art of coding in machine language. And what about a fictional computer, such as one that works...
7
2839
by: David Sworder | last post by:
Hi, I'm developing an application that will support several thousand simultaneous connections on the server-side. I'm trying to maximize throughput. The client (WinForms) and server communicate via a socket connection (no remoting, no ASP.NET). The client sends a message to the server that contains some instructions and the server responds...
1
259
by: Rakesh Roberts | last post by:
I think I have a very interesting cookie problem. I use form authentications on my application. Through out my application I started using a toggle control that persists its value for the session using cookies that it writes to on the client side (using javascript). What happens sometimes it that the application forces the user back to the...
2
2091
by: sasifiqbal | last post by:
Hi, One of my developers are facing an interesting problem regarding UserControl invalidation. The problem is: We have two forms in our application. Form A does nothing except loading of Form B and Form B contains an array of UserButton kind of contol (we have created our own buttons deriving from UserButton). All the drawings...
27
2304
by: Frederick Gotham | last post by:
I thought it might be interesting to share experiences of tracking down a subtle or mysterious bug. I myself haven't much experience with tracking down bugs, but there's one in particular which comes to mind. I was writing usable which dealt with strings. As per usual with my code, I made it efficient to the extreme. One thing I did was...
5
1955
by: Will Honea | last post by:
I've hit an interesting trap trying to migrate data off an OS/2 server running version 7.2 (fp14) over to 8.2 on Linux. Seems that one table has a column defined in the DDL as "BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH +1, INCREMENT BY +2, NO CACHE)". Any rows in that table will kill db2move. EXPORT to IXF succeeds, but...
11
1541
by: onkar.n.mahajan | last post by:
Is it possible to from function call on fly in C programming language ? I am faced with an interesting problem in that I need to take function name and arguments on fly (actually from Database as string ) and form a function call based on that ? something like FUN_NAME="fun1" , ARGS ="arg1,arg2,arg3" , for this pair function call...
4
1875
by: Andrew | last post by:
I am having an interesting namespace conflict. When we use a third party lib we create a company assembly for any descending classes to go in. I have simplified the problem into the example below. We are using the third party assembly Abc.Reports so we have an assembly called ComanyName.Abc. The problem is when I try to use the class...
0
7269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7394
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7123
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4756
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3237
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.