【问题标题】:Setting the row value to previous value in a while loop when a condition is met满足条件时,将行值设置为 while 循环中的前一个值
【发布时间】:2019-10-22 12:45:48
【问题描述】:

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

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 中的下一项时,代码会崩溃。

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

谢谢任

【问题讨论】:

  • “代码崩溃”——哪个错误? “当行计数器为 0 时,它需要转到 b 中的下一项”——为什么你的 while 不循环检查 i == 0 呢? i的初始值是多少?
  • i==0 的初始值。我也检查了 cntRow = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").RowCount if cntRow==0: 我在 if 条件下添加了这个仍然不起作用。
  • 没有错误,因为应用程序无法找到它并且代码处于尝试和除块中

标签: python-3.x sap-gui


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-18
    • 2017-03-04
    • 2018-12-22
    • 1970-01-01
    • 2023-01-12
    • 1970-01-01
    相关资源
    最近更新 更多