在IBM反射主机中,我试图运行一个VBA宏,用于遍历不同的屏幕,并填充所需的信息(在预定义的模板类型的屏幕中),以便在系统中创建订单。
在此过程中,我试图使用"Session.MoveCursor“和"Session.CursorRow”、"Session.CursorColumn“函数将光标移动到所需的位置,然后读取光标位置信息(在主屏幕上写入数据之前验证位置)。
代码:
Dim currRowPos as Integer
Dim currColPos as Integer
Session.MoveCursor targetRowPos, targetColPos ' move cursor position
DoEvents ' custom logic to wait or inlcude delay 1 sec or more, mentioned only single code statement here
currRowPos = Session.CursorRow 'get cursor current row position
currColPos = Session.CursorColumn 'get cursor current column position
'check current cursor position and write data onto HOST screen
If targetRowPos = currRowPos And targetColPos = currColPos Then
Session.TransmitANSI "xyz" 'write xyz on HOST screen
End If我试图写一些信息到主机在所需的光标位置,并遍历到下一个屏幕。在适当的程序中,我来回地填写多个项目的信息(一次一个)。
有时,我面临的问题是执行上述逻辑(代码),光标仍然处于旧位置(而不是在所需的新行、列位置),程序开始以旧位置而不是期望的/目标位置写入数据,从而导致编程错误(例如,'Session.CursorRow‘和'Session.CursorColumn’正在输出新的所需的光标位置,当光标实时地在主机屏幕上的旧位置时)。
如果有人以前遇到过这个问题和/或有任何解决方案,请你分享同样的。谢谢。
从下面的注释粘贴代码
这里是vba程序代码中使用的延迟函数。
Public Sub DelayScript(Seconds As Integer)
Dim PauseTime, START
PauseTime = Seconds
START = Timer ' Set start time.
Do While Timer < START + PauseTime
DoEvents ' Yield to other processes.
Loop
End SubIBM主机编程参考:http://docs.attachmate.com/reflection/14.x/prog-ref/ibm/
发布于 2016-08-23 21:20:20
如果我正确理解您的问题,底层连接中的延迟会干扰代码的计时。通常,您应该使用DoEvents或定时代码,而不是使用Wait*方法,让反射来处理您的时间安排。我猜你更需要这样的东西:
With Session
.MoveCursor targetRowPos, targetColPos
'10 second timeout.
.WaitForEvent rcEnterPos, "10", "", targetRowPos, targetColPos
'Verify that you didn't time out.
If targetRowPos = .CursorRow And targetColPos = .CursorColumn Then
Session.TransmitANSI "xyz" 'write xyz on HOST screen
End If
End With另外(假设它是一个字段),您可以在rcEnterField上而不是rcEnterPos上等待。见这里的文件。
https://stackoverflow.com/questions/39110600
复制相似问题