以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  两个代码如何合并  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=23997)

--  作者:181741400
--  发布时间:2012/9/26 15:05:00
--  两个代码如何合并

Dim names1 As List(Of String) = DataTables("一一与一二对比").GetUniqueValues("", "在岗人员对比_一一年")
Dim names2 As List(Of String) = DataTables("一一与一二对比").GetUniqueValues("", "在岗人员对比_一二年")
Dim names3 As New List(Of String)
For Each name As String In names1
    If Not names2.Contains(name) Then
        names3.add(name)
    End If
Next

For i As Integer = 0 To names3.Count - 1
    Tables("一一与一二对比").Rows(i)("增加") = names3(i)
Next

 

分隔…………………………………………………………………………分隔,下面是令一段代码

Dim names1 As List(Of String) = DataTables("一一与一二对比").GetUniqueValues("", "在岗人员对比_一二年")
Dim names2 As List(Of String) = DataTables("一一与一二对比").GetUniqueValues("", "在岗人员对比_一一年")
Dim names3 As New List(Of String)
For Each name As String In names1
    If Not names2.Contains(name) Then
        names3.add(name)
    End If
Next

For i As Integer = 0 To names3.Count - 1
    Tables("一一与一二对比").Rows(i)("减少") = names3(i)
Next

 

 

就是上面的代码!要分两个按钮才能执行,想给他合并到一个按钮事件里,如何实现?


--  作者:狐狸爸爸
--  发布时间:2012/9/26 15:21:00
--  

Dim names1 As List(Of String) = DataTables("一一与一二对比").GetUniqueValues("", "在岗人员对比_一一年")
Dim names2 As List(Of String) = DataTables("一一与一二对比").GetUniqueValues("", "在岗人员对比_一二年")
Dim names3 As New List(Of String)
Dim names4 As New List(Of String)
For Each name As String In names1
    If Not names2.Contains(name) Then
        names3.add(name)
    End If
Next
For Each name As String In names2
    If Not names1.Contains(name) Then
        names4.add(name)
    End If
Next
For i As Integer = 0 To names3.Count - 1
    Tables("一一与一二对比").Rows(i)("增加") = names3(i)
Next
For i As Integer = 0 To names4.Count - 1
    Tables("一一与一二对比").Rows(i)("减少") = names3(i)
Next


--  作者:lin_hailun
--  发布时间:2012/9/26 16:40:00
--  
 这个问题,其实,增加的和减少的,都是一样的内容吧,只是填写到的位置不同。
 

Dim names1 As List(Of String) = DataTables("一一与一二对比").GetUniqueValues("", "在岗人员对比_一一年")
Dim names2 As List(Of String) = DataTables("一一与一二对比").GetUniqueValues("", "在岗人员对比_一二年")
Dim names3 As New List(Of String)


Dim flag As Boolean = false

If names1 < names2 then   \'左边的人数少,即是 减少

    dim temp As List(Of String) = names1

    names1 = names2

    names2 = names1

    flag = true

End If


For Each name As String In names1
    If Not names2.Contains(name) Then
        names3.add(name)
    End If
Next

For i As Integer = 0 To names3.Count - 1

    If flag = false Then

        Tables("一一与一二对比").Rows(i)("增加") = names3(i)

    Else  

        Tables("一一与一二对比").Rows(i)("减少") = names3(i)

    End If

Next