Foxtable(狐表)用户栏目专家坐堂 → 两个代码如何合并


  共有9019人关注过本帖树形打印复制链接

主题:两个代码如何合并

帅哥哟,离线,有人找我吗?
181741400
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:40 积分:604 威望:0 精华:0 注册:2012/3/17 17:29:00
两个代码如何合并  发帖心情 Post By: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

 

 

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


 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47497 积分:251403 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By: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
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:6708 积分:34304 威望:0 精华:11 注册:2012/8/18 23:10:00
  发帖心情 Post By: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


 回到顶部