IBM iSeries环境下VBScript读取字段报错:Refresh方法不被支持
Let’s dive straight into fixing your script error. The core issue here is that the autECLPS presentation space object in PCOMM doesn’t have a Refresh() method—this is a common mix-up with other automation tools. Let’s walk through the fixes step by step.
Step 1: Replace Refresh() with valid screen synchronization
Instead of trying to call Refresh(), use PCOMM’s built-in methods to sync your script with the host screen. The most reliable options are:
WaitForHostQuiet: Waits until the host stops sending data (ideal after sending keystrokes)WaitForCursor: Waits for the cursor to be in a ready stateWaitForString: Waits for a specific text string to appear (great for verifying navigation)
For your workflow, replacing autECLSession.autECLPS.Refresh() with autECLSession.autECLPS.WaitForHostQuiet(3000, 1000) will resolve the immediate error. This waits up to 3 seconds for the host to quiet down, checking every 1 second.
Step 2: Fix the GetText() call (critical for accurate item number reading)
Your current IBMItemNum = autECLSession.autECLPS.GetText() is missing required parameters. The GetText() method needs explicit coordinates to know which part of the screen to read. You must specify the starting row, column, and length of the item number field.
For example, if your item number lives at row 8, column 12, and is 6 characters long, the call should look like:
IBMItemNum = autECLSession.autECLPS.GetText(8, 12, 6)
Use PCOMM’s "View > Presentation Space" tool to get the exact coordinates for your PO screen layout.
Revised MatchItemNum Subroutine
Here’s the corrected version of your subroutine with these fixes (plus a missing Loop statement that would have caused infinite execution):
sub MatchItemNum(ItemNum,Price) Do While IBMItemNum <> 0 counter = counter + 1 If counter > 11 Then autECLSession.autECLPS.SendKeys "[PGDN]" 'page down since bottom of lines reached autECLSession.autECLPS.SendKeys "[tab]" autECLSession.autECLPS.SendKeys "[tab]" autECLSession.autECLPS.SendKeys "[tab]" autECLSession.autECLPS.SendKeys "[tab]" autECLSession.autECLPS.SendKeys "[tab]" autECLSession.autECLPS.SendKeys "[tab]" autECLSession.autECLPS.SendKeys "[tab]" autECLSession.autECLPS.SendKeys "[tab]" autECLSession.autECLPS.SendKeys "[tab]" autECLSession.autECLPS.SendKeys "[tab]" 'tab to return to first line of PO counter = 0 'reset counter End if ' Replace invalid Refresh() with host synchronization autECLSession.autECLPS.WaitForHostQuiet(3000, 1000) ' Update GetText with your actual screen coordinates IBMItemNum = autECLSession.autECLPS.GetText(8, 12, 6) If IBMItemNum = ItemNum Then 'If-Then statement once ItemNum is found autECLSession.autECLPS.SendKeys "[tab]" autECLSession.autECLPS.SendKeys "[tab]" autECLSession.autECLPS.SendKeys "[tab]" autECLSession.autECLPS.SendKeys Price autECLSession.autECLPS.SendKeys "[field+]" autECLSession.autECLPS.SendKeys "[enter]" autECLSession.autECLPS.SendKeys "Y" autECLSession.autECLPS.SendKeys "[enter]" IBMItemNum = 0 'exit condition for loop Else 'Tab five times to reach next line autECLSession.autECLPS.SendKeys "[tab]" autECLSession.autECLPS.SendKeys "[tab]" autECLSession.autECLPS.SendKeys "[tab]" autECLSession.autECLPS.SendKeys "[tab]" autECLSession.autECLPS.SendKeys "[tab]" End if Loop ' Added missing Loop to close the Do While block autECLSession.autECLPS.SendKeys "[F3]" end sub
Quick Additional Checks
- Add a session connection validation right after
SetConnectionByNameto catch connection issues early:If Not autECLSession.IsConnected Then MsgBox "Session failed to connect!" Exit Sub End If - Test your
GetText()coordinates independently to ensure you’re capturing the correct item number before relying on the loop logic.
内容的提问来源于stack exchange,提问作者Zhong Tian

