首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

!怎么对数据进行滚动求和?多谢

2012-02-03 
!!!如何对数据进行滚动求和?谢谢有如下所示的数据,第一列是其序号,第二列是数据,现在需要对数据进行滚动求

!!!如何对数据进行滚动求和?谢谢
有如下所示的数据,第一列是其序号,第二列是数据,现在需要对数据进行滚动求和,即从第1个累加到第10个,然后从第2个再累加到第11个,从第3个累加到第12个,每次对10个数据进行求和,请问如何处理,数据是以txt文件格式存放的(文件本身无法上传,所以把数据放下面了,请大家帮助时将数据放txt文件里面处理)。
谢谢啦!

10
24
33
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
190
202
210
220
230
249
250
260
270
280
290
300
310
320
330
347
350
360
370
380
392
400
410
420
430
440
450
460
470
480
490
500


[解决办法]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fileContents As String
fileContents = My.Computer.FileSystem.ReadAllText("e:\Test.txt")
Dim 分隔符 As String = " " '各列数据分隔符号
Dim 数据项() = Split(fileContents, vbCrLf)
Dim i As Integer
Dim 和 As Decimal = 0
Dim 数据 As Decimal
Dim 临时数据
Dim 错误数 As Integer = 0

Dim DGV As New DataGridView
DGV.AllowUserToAddRows = False
DGV.Dock = DockStyle.Top
DGV.Columns.Add("序号Column", "序号")
DGV.Columns.Add("数据Column", "数据")
DGV.Columns.Add("前十项和Column", "前十项和")

DGV.Columns("序号Column").ValueType = i.GetType
DGV.Columns("数据Column").ValueType = 数据.GetType
DGV.Columns("前十项和Column").ValueType = 和.GetType

For i = 0 To 数据项.Length - 1
临时数据 = Split(数据项(i), 分隔符)
If 临时数据.length > 2 Then
Try
If Val(临时数据(0)) > 0 And Val(临时数据(1)) >= 0 Then
DGV.Rows.Add()
DGV.Rows(i).Cells("序号Column").Value = Val(临时数据(0))
DGV.Rows(i).Cells("数据Column").Value = Val(临时数据(1))
End If
Catch ex As Exception
错误数 += 1
End Try
End If
Next


DGV.Sort(DGV.Columns("序号Column"), System.ComponentModel.ListSortDirection.Ascending) '按 序号 升序

For i = 0 To DGV.RowCount - 1

和 += DGV.Rows(i).Cells("数据Column").Value
If i >= 9 Then
DGV.Rows(i).Cells("前十项和Column").Value = 和
和 = 和 - DGV.Rows(i - 9).Cells("数据Column").Value
End If
Next
Me.Controls.Add(DGV)
End Sub

热点排行