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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sendkeys Query

Status
Not open for further replies.

andy7172289

Technical User
Aug 16, 2016
19
GB
Hi all,

Below the line is some code I've written with the purpose to go between excel and an old program called TRUST. It works up till the point which I've highlighted in yellow. The idea is to basically eradicate the manual process of doing this through a macro which can just input the letters and paste the next new number in one by one.

Anyway - any ideas for a better way to do it would also be appreciated (I've explored sendmessage using API and Spy+++ but I can't get Visual Studio on my pc).

Thanks in Advance for any help with this.
Andy

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

Sub switchbetweentrustandexcel()


' This is a test macro to switch between TRUST and excel


Dim IDTRUST As Variant
Dim Path As String
Dim IDEXCEL As Worksheet

'........................................................................................................................

' Set the Path variable equal to the path of your program's installation
Path = "C:\Program Files (x86)\WinVVTN\WinVVTN\WinVVTN.exe"

IDTRUST = Shell("C:\Program Files (x86)\WinVVTN\WinVVTN.exe", vbNormalFocus)

MsgBox "Please log in to WinVV and leave it on the blank input screen. This is to enable a TRJG search."

Dim IDnotepad As Double ' to identify application with AppActivate

Workbooks("Automated Incident Number Correction in TRUST Macro.xlsm").Sheets("1").Activate


Range("B2").Select
ActiveCell.Copy

AppActivate ("SCR1 - WinVV Session 1")


'''''''''' Text from excel to paste in after some letters
[highlight #FCE94F]SendKeys "T"
[/highlight] Application.Wait Now + TimeValue("0:00:02")
SendKeys "R"
Application.Wait Now + TimeValue("0:00:02")
SendKeys "J"
Application.Wait Now + TimeValue("0:00:02")
SendKeys "G"
Application.Wait Now + TimeValue("0:00:02")
SendKeys " "
Wait Now + TimeValue("0:00:02")
SendKeys "^(V)"
Application.Wait Now + TimeValue("0:00:02")
SendKeys "{enter}"
Application.Wait Now + TimeValue("0:00:02")

Application.SendKeys "{TAB}"
Application.Wait Now + TimeValue("0:00:02")
Application.SendKeys "{TAB}"
Application.Wait Now + TimeValue("0:00:02")
Application.SendKeys "{TAB}"
Application.Wait Now + TimeValue("0:00:02")
Application.SendKeys "{TAB}"
Application.Wait Now + TimeValue("0:00:02")

Application.SendKeys "A"
Application.Wait Now + TimeValue("0:00:02")
Application.SendKeys "{Enter}"
Application.Wait Now + TimeValue("0:00:02")

Application.SendKeys "{F4}
 
If you are interacting with a window, you might try to script it with AutoHotKey.

Simi
 
Hi all,

Thanks for your help with this so far. It's working up to the point where I want to put in the 'enter' key (not return). I'm working on a laptop so the keyboard key doesn't exist, if that matters? I cannot use [highlight #FCE94F]application.sendkeys "~"[/highlight] or [highlight #FCE94F]application.sendkeys "{ENTER}"[/highlight]. The application even has a alternate method to put in enter (F10 and ctrl+A) but the function key cannot be used in sendkeys as it's not a windows O/S controlled feature, and the ctrl+A just send's the 'A' (code: [highlight #FCE94F]application.sendkeys "^(A)"[/highlight]), despite the same code working for ctrl+V for paste...

Does anyone know how to fix this new issue? I really do appreciate anyone taking the time looking into this, it's going to make the biggest difference if I can pull this off!
 
It's not clear what you've done so far to get past the highlighted line down to the Application.SendKeys "{ENTER}" line from your original post.
 
Apologies DjangMan. The solution to my first issue was to run the macro without the code screen open. I was using F8 to run bit by bit through the code. The issue was, I was trying to say 'look at this app', but instead it was sending the key to the code screen it had to keep checking back in to. So the code remains the same, however it's falling down at another part. Sorry for not clarifying - I hope that does?
 
Andy,

I’d guess that you have a terminal emulator that interfaces a mainframe computer. Perhaps it is emulating a 3270 terminal interfacing an IBM mainframe.

I found this on railforums.co.uk
TRUST and TOPS are old IBM mainframe systems, and only accessible through an emulator called WinVV created by British Rail for British Rail. It runs off a modified Telnet system which makes it difficult and rather cumbersome to use. Think of a more complicated version of Windows Command Line.

You might check out this:

A principle to be aware of with terminal emulators.
When you SendKeys to the mainframe, it processes asynchronously. You need to establish a way to determine that the mainframe has responded. Simply waiting a fixed duration is inadequate. The mainframe may respond much sooner or longer than your fixed wait time.

You would never drive your car with the determinatin that at each stop sign, you will wait for 5 seconds before crossing the intersection, without evaluating the traffic on the street. Likewise, you need feedback from the mainframe to determine that it is safe to process the next statement in your program.


Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Skip,

Thanks for showing me that stuff, I have already looked into that. I'm aware this isn't going to be the best, and it's a work around. It would just save an awful lot of time if I managed to pull it off.

By the looks of things I'm going to have to just leave this as something which is simply not automatable due to the age of the system.

Thanks everyone for your time :).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top