大概知道了~
以您提供资料进行分析
所以我写出2种不同的加总判断
希望对您有帮助~
资料一(A)为单纯数字时分析 「一般大都用这种方式」
把资料一当作阵列位置并把资料三作加总即可
TEMP(DATA1) += DATA3
搜寻时找到阵列位置就可以找到加总值
输出加总值= TEMP(输入资料一值)
资料二(B)为字串时分析 「也可以利用二维阵列」
把资料二放到暂存阵列当索引
启动暂存阵列回圈
当暂存资料中索引有资料二 就把资料三加总
复制程式
TEMP1(i) = DATA1(i)
For j = 0 To UBound(TEMP1)
If TEMP1(j) = DATA1(i) Then
TEMP2(j) += DATA2(i)
Exit For
End If
Next
搜寻时
启动暂存阵列回圈
当暂存资料中索引为输入值时 输出加总值
复制程式
For j = 0 To UBound(TEMP1)
If TEMP1(j) = TextBox2.Text Then
Label1.Text = TEMP2(j)
Exit For
End If
Next
附件为执行程式压缩档vb2008
程式完整原码:
复制程式
Public Class Form1
Dim DATA0() As Object = {"111", "222", "333", "111", "444", "222"}
Dim DATA1() As Object = {"AA", "BB", "CC", "DD", "AA", "FF"}
Dim DATA2() As Object = {"6", "1", "2", "4", "5", "3"}
Dim TEMP(999) As Integer
Dim TEMP1(UBound(DATA0)) As String
Dim TEMP2(UBound(DATA0)) As Integer
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TextBox1.Text = "资料一" & vbTab & "资料二" & vbTab & "资料三" & vbTab & vbTab & "一 加总 二" & vbNewLine & "=======================" & vbTab & vbTab & "==============" & vbNewLine
For i = 0 To UBound(DATA0)
TEMP(CInt(DATA0(i))) += CInt(DATA2(i))
TEMP1(i) = DATA1(i)
For j = 0 To UBound(TEMP1)
If TEMP1(j) = DATA1(i) Then
TEMP2(j) += DATA2(i)
Exit For
End If
Next
TextBox1.Text &= DATA0(i) & vbTab & DATA1(i) & vbTab & DATA2(i) & vbTab & vbTab & TEMP(CInt(DATA0(i)))
For j = 0 To UBound(TEMP1)
If TEMP1(j) = DATA1(i) Then
TextBox1.Text &= vbTab & TEMP2(j)
Exit For
End If
Next
TextBox1.Text &= vbNewLine
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = ""
Label1.Text = TEMP(CInt(TextBox2.Text))
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Label1.Text = ""
For j = 0 To UBound(TEMP1)
If TEMP1(j) = TextBox2.Text Then
Label1.Text = TEMP2(j)
Exit For
End If
Next
End Sub
End Class
个人解法.请各位先进指导~