Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MoveTo command for cursor not working

Status
Not open for further replies.

DwMcC

Programmer
Oct 22, 2012
7
0
0
US
I'm having trouble with the MoveTo where the cursor is not moving to the selection as anticipated. The entire macro is very long so I've included only the specific sub where the issue is occuring. All other aspects of the code are working as anticipated and desired with the exception of the cursor moving down to the coordinates specified before the enter key is pressed.
The specific code in question is:
SCR.MoveTo z,4 'where "z" is the 'For line count'
I also see the MoveTo not working as anticipated in other Attachmate macros from predecessors.
for instance I found a case select (see below) where MoveTo is also not working.
Select Case UCase(rptDate$)
Case "UNSETTLED"
SCR.MoveTo 10,29
Case "CURRENT DAY"
SCR.MoveTo 11,29
Case "PRIOR DAY"
SCR.MoveTo 12,29
Case "2 DAYS PRIOR"
SCR.MoveTo 13,29
End Select
Call PressEnter


Is anyone aware of any code changes or have alternatives available to the MoveTo that might get me moving in the right direction here?
Otherwise I will have to devise some sort of Case select that obtains the value of z and then presses the tab key the appropriate number of times which just seems cumbersome and illogical.

Here is my code for this sub:
(sorry had to remove indents so this wouldn't look ugly when pasting)
Sub i3964
Do
' sess.screen.GetString(x is row number, is cursor start position, is number of characters over)
' remember "...rw" is declared globally so previous row # in Excel is not overwritten
'*********START Capture********
Dim x as Integer
Dim strTempa as String
Dim strTempb as String
Dim strTempc as String
Dim strTempd as String
Dim strTempe as String
For x = 8 to 21 'total rows to capture
If strTempa = " " Then 'there is no description thus we have a blank line
Else
strTempa = sess.screen.GetString(x, 04, 21)
strTempb = sess.screen.GetString(x, 26, 06)
strTempc = sess.screen.GetString(x, 34, 06)
strTempd = sess.screen.GetString(x, 41, 12)
strTempe = sess.screen.GetString(x, 57, 22)
'write it to a specified row in the spreadsheet
With i3964sumSht
.Cells(tusumrw, "A").Value = strTempa
.Cells(tusumrw, "B").Value = strTempb
.Cells(tusumrw, "C").Value = strTempc
.Cells(tusumrw, "D").Value = strTempd
.Cells(tusumrw, "E").Value = strTempe
End With
tusumrw = tusumrw + 1
End If
next x
'*********END Capture*********
'Now check for exit point
If SCR.Search("< TOTAL TRANS >") = "< TOTAL TRANS >" Then Exit Do
Call PressF8 ' Advance the page if total trans was not found
Loop
'Now gather the summary page(s)
Call PressClear
Call PressClear
SCR.SendKeys("IXTU4417<Enter>") 'Temporary for Testing
'SCR.SendKeys("IXTU3964<Enter>") 'Actual for Production
SCR.SendKeys("<Tab><Enter>")
SCR.SendKeys("<Tab>") 'arrives at first green line
Do
Dim strdtlPlan as String
Dim strdtlRun as String
Dim strdtlTran as String
Dim strdtlInPt as String
Dim strdtlLnIt as String
Dim strdtlCnt as String
Dim strdtlAmt as String
Dim LnChk As String
Dim z as Integer
For z = 8 to 21
LnChk = sess.screen.GetString(z, 04, 21)
If LnChk = " " Then Exit Do 'we reached the last entry and can exit
SCR.MoveTo z,4 'Move the cursor to the 'z' line so we can action that line with the enter key
SCR.SendKeys("<Enter>") 'open line detail
Call PressF6 'scroll to the right
Do
'*********START Capture********
For x = 8 to 21
strdtlPlan = sess.screen.GetString(5, 59, 22)
strdtlRun = sess.screen.GetString(5, 09, 06)
strdtlTran = sess.screen.GetString(5, 26, 06)
strdtlInPt = sess.screen.GetString(6, 45, 25)
strdtlLnIt = sess.screen.GetString(x, 03, 25)
strdtlCnt = sess.screen.GetString(x, 45, 06)
strdtlAmt = sess.screen.GetString(x, 56, 23)
With i3964dtlSht
.Cells(tudtlrw, "A").Value = "IXTU"
.Cells(tudtlrw, "B").Value = strdtlPlan
.Cells(tudtlrw, "C").Value = strdtlRun
.Cells(tudtlrw, "D").Value = strdtlTran
.Cells(tudtlrw, "E").Value = strdtlInPt
.Cells(tudtlrw, "F").Value = strdtlLnIt
.Cells(tudtlrw, "G").Value = strdtlCnt
.Cells(tudtlrw, "H").Value = strdtlAmt
End With
tudtlrw = tudtlrw + 1
Next x
If SCR.Search("ALL PLANS PRESENT") = "ALL PLANS PRESENT" Then Exit Do
Call PressF6 'scroll to the right
Loop
Call PressF2
Next z
Loop
End Sub
 
hi,
the cursor is not moving to the selection as anticipated.
So what does than mean?

1. The cursor never moved?
2. The cursor moved to some other place, where xxx was the value contained in rptDate$ and rr,cc is where it moved?

You might TRIM the values...
Code:
Select Case [b][highlight]Trim(UCase(rptDate$))[/highlight][/b]
  Case "UNSETTLED"
    SCR.MoveTo 10,29
  Case "CURRENT DAY"
    SCR.MoveTo 11,29
  Case "PRIOR DAY"
    SCR.MoveTo 12,29
  Case "2 DAYS PRIOR"
    SCR.MoveTo 13,29
End Select



Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I have tried the Trim trick previously, but it didn't return a satisfactory result.
In my routine I'm attempting to move the cursor to the line being evaluated in the For statement:
Dim z as Integer
For z = 8 to 21
LnChk = sess.screen.GetString(z, 04, 21)
If LnChk = " " Then Exit Do 'we reached the last entry and can exit
SCR.MoveTo z,4 'Move the cursor to the 'z' line so we can action that line with the enter key
SCR.SendKeys("<Enter>") 'open line detail
Call PressF6 'scroll to the right
I just can't come up with a logical reason why the cursor is not moving to the line number being evaluated (z). It remains in the default cursor position upon page load at the top of the screen.
The cursor must move to the line being evaluated in the For as pressing enter with the cursor in the default position returns an incorrect page.

If you bring that sentence in for a fitting, I can have it shortened by Wednesday!
 
So you're telling me that the string variable rptDate$ can have one of these actual literal values...
[tt]
UNSETTLED
CURRENT DAY
PRIOR DAY
2 DAYS PRIOR
[/tt]

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
[spineyes]Skip, you seem to fixated on the Case Select when it actually had nothing to do with this question and was only an alternative example of the same issue appearing in other example code (may I recommend decaffeinated?[shocked]), but to address the Case Select, yes the literal values are passed in that example. Deploying the same solution I describe below also resolved the case select code's issue. It was a simple case of Time(ing). (Time? I don't have Time for Time! ...who said that? ...smart person that one!)
Remy, I appreciate the line of thought to debug at the lowest common denominator, but it turned out not to be a code syntax issue (thankfully!). The good news is that I was able to debug the issue by just inserting breaks and watching it run repeatedly until my eyeballs hurt [bigglasses]. It turns out that the script is executing faster than the screen can respond. So the loop was moving forward without the cursor having moved.
I resolved this by including a screen waiting period.
Here is the Sub I included:
Sub WaitScreen
Dim Counter As Integer
Dim CounterMax As Integer
Dim WaitTime As Integer
CounterMax = 1000
WaitTime = 30

S0.Screen.WaitHostQuiet(150)
Counter = 1
Do Until S0.Screen.OIA.XStatus = 0 or Counter >= CounterMax
S0.Screen.WaitHostQuiet(WaitTime)
Counter = Counter + 1
Loop
End Sub

I executed the Sub with a call statement : 'Call WaitScreen'

I injected the new function as follows: (again had to remove indents and other formatting for reasonable display here)...

Call WaitScreen 'adding screen response time
LnChk = sess.screen.GetString(z, 04, 21)
If LnChk = " " Then Exit Do 'we reached the last entry and can exit
SCR.MoveTo z, 4 'Move the cursor to the 'z' line so we can action that line with the enter key
Call WaitScreen 'This allows time for the cursor to do the move to the z line
SCR.SendKeys("<Enter>") 'open line detail
Call WaitScreen 'adding screen response time
Call PressF6 'scroll to the right
Call WaitScreen 'adding screen response time

The MoveTo command is now executing given the extra time allotted. I did see another method of this where the wait was determinate on the specific coordinate and I might try that in the future. For now this generic interval appears to be sufficient.

If anyone has other examples they would like to share to inject timing delays please feel free to post them; otherwise I guess we can close out this thread.

If you bring that sentence in for a fitting, I can have it shortened by Wednesday!
 
Timing Delays...

Should NOT use a fixed time value to wait.

Move the cursor away from the screen rest coordinates before issueing a command.

In a loop, WaitForCursor at the screen rest coordinates, similar to...
Code:
    scr.MoveRelative 1, 1, 1
    scr.SendKeys ("<enter>")
    Do Until (scr.WaitForCursor([b]KeyRow(sScr, 1), KeyCol(sScr, 1)[/b]))
        DoEvents
    Loop


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top