以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  求助,命令行运行代码是报错  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=180291)

--  作者:夜点蚊香
--  发布时间:2022/10/12 16:38:00
--  求助,命令行运行代码是报错
生成数据的时候,的在同一行填入一个不重复的数据  
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:工序.foxdb
报错如下

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

命令框代码如下
Dim Arys As List(Of String())
Arys = DataTables("工序表").GetUniqueValues("", "工序号","姓名")
DataTables("人机工位图").RemoveFor("[姓名] <> \'\'")
Dim kc As Row
Dim ys,a1,a2,b1,b2 As String
Dim int1,int2,iint1,iint2,int,hint As Integer
ys = "一"
iint1 = 0
iint2 = 0

\'注意循环变量是字符型数组,所以类型是String(),而不是String
For Each Ary As String() In Arys
    Dim dt As DataTable =DataTables("工序表")
    If ys = "一" Then
        \'先判断当前行第一组数据的数量
        iint1 = dt.compute("count(姓名)","[工序号] =  \'" & Ary(0) & "\' and [姓名] =  \'" & Ary(1) & "\'")
        a1 = Ary(0)
        a2 = Ary(1)
    Else If ys = "二" Then
        
        \'再判断判断当前第二组数据的数量
        iint2 = dt.compute("count(姓名)","[工序号] =  \'" & Ary(0) & "\' and [姓名] =  \'" & Ary(1) & "\'")
        b1 = Ary(0)
        b2 = Ary(1)
    End If
    If ys = "二" Then
        If iint1 > iint2 Then
            int = iint1
        Else If iint1 < iint2 Then
            int = iint2
        Else If iint1 = iint2 Then
            int = iint1
        End If
        
        \' 一 时 给当前行赋值
        hint = 0
        \'遍历第一组数据
        Dim drs1 As List(Of DataRow)
        drs1 = DataTables("工序表").Select("[工序号] =  \'" & a1 & "\' and [姓名] =  \'" & a2 & "\'")
        For Each dr As DataRow In drs1
            If hint < int Then
                kc = Tables("人机工位图").addnew() \'先新增一行
                int1 = dt.compute("sum(工时)","[工序号] =  \'" & a1 & "\' and [姓名] =  \'" & a2 & "\'")
                kc("工序号") = dr("工序号")
                kc("姓名") = dr("姓名")
                kc("工序名称") = dr("工序名称")
                kc("工时") = Int1
                kc("设备") = dr("设备")
                kc("颜色") = ys
                Dim drs2 As DataRow
                drs2 = DataTables("工序表").find("[工序号] <>  \'" & b1 & "\' and [姓名] =  \'" & b2 & "\'")
                int2 = dt.compute("sum(工时)","[工序号] =  \'" & b1 & "\' and [姓名] =  \'" & b2 & "\'")

                kc("工序号1") = drs2("工序号")
MessageBox.Show(1)
                kc("姓名1") = drs2("姓名")
                kc("工序名称1") = drs2("工序名称")
                kc("工时1") = Int2
                kc("设备1") = drs2("设备")
                
            End If
        Next
    End If
    
    \'下面的代码是用来区分颜色的
    If ys = "二" Then
        ys = "一"
    Else If ys = "一" Then
        ys = "二"
    End If
Next
[此贴子已经被作者于2022/10/12 16:38:51编辑过]

--  作者:有点蓝
--  发布时间:2022/10/12 16:53:00
--  
参考:http://www.foxtable.com/webhelp/topics/0396.htm,看示例三,加上判断
--  作者:夜点蚊香
--  发布时间:2022/10/12 17:02:00
--  
判断加上了, 有数据 ,不知道为什么数据没出来
Dim Arys As List(Of String())
Arys = DataTables("工序表").GetUniqueValues("", "工序号","姓名")
DataTables("人机工位图").RemoveFor("[姓名] <> \'\'")
Dim kc As Row
Dim ys,a1,a2,b1,b2 As String
Dim int1,int2,iint1,iint2,int,hint As Integer
ys = "一"
iint1 = 0
iint2 = 0

\'注意循环变量是字符型数组,所以类型是String(),而不是String
For Each Ary As String() In Arys
    Dim dt As DataTable =DataTables("工序表")
    If ys = "一" Then
        \'先判断当前行第一组数据的数量
        iint1 = dt.compute("count(姓名)","[工序号] =  \'" & Ary(0) & "\' and [姓名] =  \'" & Ary(1) & "\'")
        a1 = Ary(0)
        a2 = Ary(1)
    Else If ys = "二" Then
        
        \'再判断判断当前第二组数据的数量
        iint2 = dt.compute("count(姓名)","[工序号] =  \'" & Ary(0) & "\' and [姓名] =  \'" & Ary(1) & "\'")
        b1 = Ary(0)
        b2 = Ary(1)
    End If
    If ys = "二" Then
        If iint1 > iint2 Then
            int = iint1
        Else If iint1 < iint2 Then
            int = iint2
        Else If iint1 = iint2 Then
            int = iint1
        End If
        
        \' 一 时 给当前行赋值
        hint = 0
        \'遍历第一组数据
        Dim drs1 As List(Of DataRow)
        drs1 = DataTables("工序表").Select("[工序号] =  \'" & a1 & "\' and [姓名] =  \'" & a2 & "\'")
        For Each dr As DataRow In drs1
            If hint < int Then
                kc = Tables("人机工位图").addnew() \'先新增一行
                int1 = dt.compute("sum(工时)","[工序号] =  \'" & a1 & "\' and [姓名] =  \'" & a2 & "\'")
                kc("工序号") = dr("工序号")
                kc("姓名") = dr("姓名")
                kc("工序名称") = dr("工序名称")
                kc("工时") = Int1
                kc("设备") = dr("设备")
                kc("颜色") = ys
                Dim drs2 As DataRow

                drs2 = DataTables("工序表").find("[工序号] <>  \'" & b1 & "\' and [姓名] =  \'" & b2 & "\'")
                int2 = dt.compute("sum(工时)","[工序号] =  \'" & b1 & "\' and [姓名] =  \'" & b2 & "\'")
                If drs2 IsNot Nothing Then
                    kc("工序号1") = drs2("工序号")
                    kc("姓名1") = drs2("姓名")
                    kc("工序名称1") = drs2("工序名称")
                    kc("工时1") = Int2
                    kc("设备1") = drs2("设备")
                End If
            End If
        Next
    End If
    
    \'下面的代码是用来区分颜色的
    If ys = "二" Then
        ys = "一"
    Else If ys = "一" Then
        ys = "二"
    End If
Next
[此贴子已经被作者于2022/10/12 17:02:21编辑过]

--  作者:有点蓝
--  发布时间:2022/10/12 17:04:00
--  
要么数据有问题,要么条件有问题
--  作者:夜点蚊香
--  发布时间:2022/10/12 17:08:00
--  
搞定了,筛选条件弄错了