尽管退出条件得到满足,IBM iSeries AS400 VBscript宏循环仍未退出

时间:2018-05-23 18:34:50

标签: vbscript ibm-midrange iseries-navigator

我已在VBA中为我们的IBM iSeries / AS400 /绿色屏幕环境创建了一个宏,该环境在采购订单中查找项目编号,然后更改其价格并退出采购订单。在宏内是一个循环,用于解析采购订单的每一行,然后如果在第一页上找不到该数字,则向下翻页到下一行。这是循环的代码:

'ItemNum and Price are entered by the user within Excel
Do Until IBMItemNum = ItemNum
    If NumRow = 11 Then
        'There are ten lines within purchase orders, after which one must page down
        'to see the rest of the purchase order. This is where the problem occurs
        autECLSession.autECLPS.SendKeys "[pagedn]"
        NumRow = 1
    End If
    IBMItemNum = autECLSession.autECLPS.GetText(NumRow, 2, 5)
    If IBMItemNum = ItemNum Then
        autECLSession.autECLPS.SetCursorPos NumRow, 66
        autECLSession.autECLPS.SendKeys Price
        autECLSession.autECLPS.SendKeys "[field+]"
        autECLSession.autECLPS.SendKeys "[enter]"
        'After the item has been found and the price entered, the macro exits the PO
        'Entering PageDown after the PO has been exited crashes the AS400 session
        Exit Do
    Else
        'Check the next row
        NumRow = NumRow + 1
    End If
Loop

当且仅当我从循环中删除PageDown SendKeys命令时,此宏可以连续成功读取采购订单第一页上的每个数字。但是,即使ItemNum是PO上的第一个IBMItemNum,宏也不会退出循环并向下翻页(这也意味着循环重复了10次以上)。我的代码是否缺少退出条件?

1 个答案:

答案 0 :(得分:0)

autECLSession.autECLPS.SendKeys "[enter]"之后您需要延迟。这将为屏幕提供更新时间。

Sleep API是理想的Sleep 250将停止您的代码500毫秒(1/2秒)。

Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)

最简单的解决方法是使用大延迟。或者,您可以使用较小的延迟并使用GetText查看屏幕是否已更新。

'ItemNum and Price are entered by the user within Excel
Do
    If NumRow = 11 Then
        'There are ten lines within purchase orders, after which one must page down
        'to see the rest of the purchase order. This is where the problem occurs
        autECLSession.autECLPS.SendKeys "[pagedn]"
        NumRow = 1
    End If
    IBMItemNum = autECLSession.autECLPS.GetText(NumRow, 2, 5)
    If IBMItemNum = ItemNum Then
        autECLSession.autECLPS.SetCursorPos NumRow, 66
        autECLSession.autECLPS.SendKeys Price
        autECLSession.autECLPS.SendKeys "[field+]"
        autECLSession.autECLPS.SendKeys "[enter]"
        Sleep 500
        'After the item has been found and the price entered, the macro exits the PO
        'Entering PageDown after the PO has been exited crashes the AS400 session
        Exit Do 'Not needed
    Else
        'Check the next row
        NumRow = NumRow + 1
    End If
    DoEvents

Loop Until IBMItemNum = ItemNum