首页 > 解决方案 > 满足条件时,将行值设置为 while 循环中的前一个值

问题描述

如果满足条件,我正在尝试将行值重新设置为前一行值。一旦满足条件,现有行将被删除。

for b in BR:
while i < cntRows:
    rowValue= session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").GetCellValue(i,"ZCOMMENTS")
    print(rowValue)
    if rowValue!="Orphan Impound":
        if debitAmt==disRcvAmt:
            impMatch="Dollar Amount Matched"
            session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").currentCellRow=i
            session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectedRows=i
            session.findById("wnd[0]/tbar[1]/btn[13]").press()
            i-=1
        else:
            i+=1
continue

当我使用 i-=1 并且当行计数器为 0 时它需要转到 b 中的下一项时,代码会在返回到上一行时崩溃。

我如何在这两种情况下停止崩溃。

谢谢任

标签: python-3.xsap-gui

解决方案


找出解决方案并通过添加此部分停止崩溃

cntRow=session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").RowCount
if cntRow <0:
    session.findById("wnd[0]").sendVKey(3)
    session.findById("wnd[0]").sendVKey(2)
    break
elif cntRow==i:
    break
elif cntRow>0:
    if k<0:
       i=-1
    else:
       i==k

推荐阅读