PDA

View Full Version : Emulation question



georgiboy
03-15-2012, 11:29 PM
Hi all

I work in a warehouse environment where we use a system that seems to run through telnet, i have been writing code for the system for years now with the use of sendkeys to turn pages and reading the cursor location to decipher if pages have loaded or not. This code that i write according to telnet is vba but it has a few differences like MsgBox("Hello") would not work it would need to be Print "Hello".

My question is: When i turn pages i have to make the code wait 1 second per page using the line of code: "EMWaitCursor 1,5,1" Now this will wait 1 second because the cursor never hits that location and the cursor does not move on page changes. Does anyone know of a way i can make it wait half a second or less as EMWaitCursor 0.5,5,1 will not work?

Will it have to be some code that will read a line off each page to prove that the page has changed before it pages again?

Maybe Excel could do the above for me if i knew how to make it talk to telnet, then it could pull the information into Excel. At current the telnet vba pushes data to a text file on the C drive then Excel pulls it out and manipulates it.

Any help will be appreciated

Many thanks for looking

Kenneth Hobs
03-16-2012, 05:34 AM
SendKeys() should be avoided when possible for those reasons. Howsoever, it is probably your only option. Of course timing and focus are the two issues with SendKeys() as-well-as the need for UAC to be off.

Rather than a time wait method, I use a loop looking for a window's handle and then set the focus. If you have a unique window that you can loop and wait for, that is the best approach. To spy on the windows, try this free api spy program: http://patorjk.com/blog/software/

Example for Notepad: http://vbaexpress.com/forum/showthread.php?t=26601

georgiboy
03-16-2012, 06:37 AM
Hi Ken, thanks for your reply.

Unfortunately it is against my company policy to run .exe files on our system.

I have no problem finding the window as the vba is run from the telnet app itself, as for writing to the text file this is all good too. The problem i have is just being limited to a 1 second pause when the next page load time is probably around 0.001 second so it seams painful having to wait a second when the code is reading 600 pages of data from telnet thus making the whole process quite slow.

I will have to work on making the code prove that that the page has changed before it reads data then calls next page thus eliminating the wait command all together. To do this i need to be sure that there will be no duplicate data on the next page on the same line otherwise it will think that the page has not changed and get stuck in a loop.

I am reading data in a loop with an "EMReadScreen,1,1,30" "EMReadScreen,x,y,(character ammount)" and storing it to a variable then appending it to the text file. I will try to find an example of the code to explain.

Many thanks for your help

georgiboy
03-16-2012, 06:48 AM
Here is the code in question...
Sub ReapDataFromGDS()
Emulation "TELNET"
SysHide "Timer"
Dim read$, scrtxt$, dup$

FileWrite "C:\Count book.txt", ""

Do
EMWaitCursor 1, 5, 1 ' here is the painful wait line
EMReadScreen scrtxt, 10, 1, 1
If scrtxt = " There are" Then ' this line pops up when you are at the bottom of the data, not always in same place though
GoTo jumpstation01
End If
For n = 10 To 18
EMReadScreen read, 75, n, 4
If read = dup Then ' this is the failsafe check for the end of data
GoTo jumpstation01
End If
FileAppend read
dup = read
Next n
EMSendKey "<F8>" ' this is the button press that pages down
Loop

jumpstation01:
Print "Will now open spreadie."
Reply = Shell("C:\Program Files\Microsoft Office\Office11\excel.exe C:\Countbookdoc.xls", 1)
End Sub

Many thanks

Kenneth Hobs
03-16-2012, 07:01 AM
Have you tried, EMFocus?

georgiboy
03-16-2012, 07:22 AM
Would that tell me if the page has changed if say i hit the F8 key, each page only holds a certain amount of lines say 10. I would have to read all 10 lines using the for next loop then push F8.

The screen does not have to be in focus because i can run 3 different pieces of vba in 3 different instances of telnet all at the same time. I just need to know if the page has changed or not. Hmmm I'm thinking its just too much hard work as it is quite an old system.

Cheers

Kenneth Hobs
03-16-2012, 07:30 AM
Yes, read the content and make the decision.

If the window has the same caption and class name then the API method would not help. You might be able to install the api spy program on a stick and bypass IT limitations.

Most discussions about Telnet and Excel do not reveal much. Most don't have Telnet so we can't help much. I doubt that there are any Telnet forums but you might check. The vendor's site sometimes have a limited forum but most don't provide much help in that way.

georgiboy
03-16-2012, 08:22 AM
Many thanks for your help, I shall try the above stick idea when I return to work

Cheers