以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- if问题 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=110196) |
||||||||||||||||||||||||||||||||||||
-- 作者:jick0526 -- 发布时间:2017/11/28 17:59:00 -- if问题 老师,请问下,如果第一列一样,第二列数值大的会自动输入到第三列,代码要怎么写,谢谢!下面是例子
|
||||||||||||||||||||||||||||||||||||
-- 作者:有点甜 -- 发布时间:2017/11/28 18:13:00 -- Dim t As Table = Tables("表A") Dim pr As Row = Nothing Dim max As String = 0 For Each r As Row In t.rows If pr IsNot Nothing AndAlso pr("第一列") <> r("第一列") Then pr("第三列")= max max = r("第二列") Else If r("第二列") > max Then max = r("第二列") End If r("第三列")= Nothing End If pr = r Next If pr IsNot Nothing Then pr("第三列")= max end if |
||||||||||||||||||||||||||||||||||||
-- 作者:jick0526 -- 发布时间:2017/11/28 18:24:00 -- 老师,上面的代码放进去后,在第一列一输入数字,整个软件就关掉 |
||||||||||||||||||||||||||||||||||||
-- 作者:有点甜 -- 发布时间:2017/11/28 18:48:00 -- 不是写到datacolchanged事件,而是单独做一个按钮执行代码。 |
||||||||||||||||||||||||||||||||||||
-- 作者:jick0526 -- 发布时间:2017/11/30 20:15:00 -- 老师,请问下,上面的代码如果改为第一列一样,第二列数值排在第二大的会自动输入到第三列,代码要怎么写,谢谢! |
||||||||||||||||||||||||||||||||||||
-- 作者:有点甜 -- 发布时间:2017/11/30 22:33:00 -- Dim t As Table = Tables("表A") Dim pr As Row = Nothing Dim max1 As String = 0 Dim max2 As String = 0 Dim i As Integer = 0 For Each r As Row In t.rows If pr IsNot Nothing AndAlso pr("第一列") <> r("第一列") Then i = 0 pr("第三列")= max2 max1 = r("第二列") max2 = r("第二列") r("第三列")= Nothing ElseIf pr Is Nothing Then max1 = r("第二列") max2 = r("第二列") r("第三列")= Nothing i = 0 Else If r("第二列") > max1 Then max2 = max1 max1 = r("第二列") ElseIf r("第二列") > max2 Then max2 = r("第二列") elseif i = 1 then max2 = r("第二列") End If r("第三列")= Nothing End If pr = r i += 1 Next If pr IsNot Nothing Then pr("第三列")= max2 end if |