以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  求一段代码,谢谢  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=53541)

--  作者:jiajunchi
--  发布时间:2014/7/10 10:40:00
--  求一段代码,谢谢

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:001.table

图片点击可在新窗口打开查看此主题相关图片如下:qq图片20140710104058.jpg
图片点击可在新窗口打开查看

求一段代码:第一列里自动选一组数据(个数不限)之和等于1645,但是:第二列对应的一组数据之和等于14.15,如果没有,选最接近一组也行!将对应的数据标示出来.谢谢

[此贴子已经被作者于2014-7-10 10:41:59编辑过]

--  作者:有点甜
--  发布时间:2014/7/10 10:44:00
--  

参考例子,组合排列

 

http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=46436&skin=0


--  作者:有点甜
--  发布时间:2014/7/10 11:34:00
--  

调用代码,因为组合排列运行较慢,红色地方你手动去调比较好

 

Dim t As Table = Tables("Sheet1")
Dim a(t.rows.Count-1) As String
For i As Integer = 0 To t.rows.Count - 1
    a(i) = i
Next
Dim b(t.rows.Count) As String
For i As Integer = 6 To 6 \' = 1 to t.rows.Count
    Functions.Execute("loop", a, t.rows.Count, i, b, i)
Next

msgbox("查询完毕")

 

-----------------------------------------

 

内部函数 loop

 

Dim a() As String = args(0)
Dim n As Integer = args(1)
Dim m As Integer = args(2)
Dim b() As String = args(3)
Dim Mm As Integer = args(4)

For i As Integer = n To m Step -1
    b(m-1) = i-1
    If m > 1 Then
        Functions.Execute("loop", a, i-1, m-1, b, Mm)
    Else
        Dim sum1 As Double = 0
        Dim sum2 As Double = 0
        Dim t As Table = Tables("Sheet1")
        For j As Integer = 0 To Mm - 1
            sum1 += t.rows(a(b(j)))("第一列")
            sum2 += t.rows(a(b(j)))("第二列")
        Next
        If sum1 = 1645 AndAlso sum2 >= 14 AndAlso sum2 <= 15 Then
            Dim result As String = ""
            For j As Integer = 0 To Mm - 1
                result &= a(b(j))+1 & ","             
            Next
            output.show("找到,行(" & result.Trim(",") & "),第二列和:(" & sum2 & ")" )
        End If
    End If
Next