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!

SendKeys ("<Enter>") doesnt work straight away 1

Status
Not open for further replies.

MazzaB

Technical User
Feb 2, 2012
11
GB
I have written numerous macros to get data from Attachmate to Excel which work great.

What I am struggling with is that after Attachmate is opened a simple logon script wont work unless Enter is pressed manually from the keyboard a number of times.

The username string is sent to Attachmate ok, then the first Sess0.Screen.SendKeys ("<Enter>") works ok, the password string is then sent to Attachmate ok but then the 2nd Sess0.Screen.SendKeys ("<Enter>") simply doesnt work.
I have tried a Sess0.Screen.WaitHostQuiet (1000)before sending the Enter but it still doesnt work.
If the user has logged in and out manually and then runs the macro it works fine, if the user manually presses enter a number of times when Attachmate is first opened it works fine.
If I step through the code the Enter command appears to execute but nothing happens in Attachmate.

Has anyone else come across this ?

Code:
Sub Logon()
Dim sendCommand As String
Dim Sessions, System As Object, Sess0 As Object

Set System = CreateObject("EXTRA.System")
Set Sessions = System.Sessions
Set Sess0 = System.ActiveSession
Dim enter As String


    With Worksheets("Passwords")
    
    sendCommand = .Cells(1, 2).Value
            If sendCommand = "" Then
            MsgBox "USER ID field (B1) in Passwords sheet is blank"
            End If
            Sess0.Screen.PutString sendCommand
Sess0.Screen.WaitHostQuiet (1000)
           
   Sess0.Screen.SendKeys ("<Enter>")
            
            
Sess0.Screen.WaitHostQuiet (1000)
               Do
           DoEvents
Loop Until Sess0.Screen.Col = 11
   


    sendCommand = .Cells(2, 2).Value
            If sendCommand = "" Then
            MsgBox "Password field (B2) in Passwords sheet is blank"
            End If
                        Do
   DoEvents
Loop Until Sess0.Screen.Col = 11
            Sess0.Screen.PutString sendCommand
           Sess0.Screen.WaitHostQuiet (1000)
Sess0.Screen.SendKeys ("<Enter>")
            Do
   DoEvents
Loop Until Sess0.Screen.Col = 54

Sess0.Screen.SendKeys ("yes")
  Sess0.Screen.SendKeys ("<Enter>")

            
End With
End Sub
 
For some reason Sess0.Screen.SendKeys (sendCommand & "<Enter>") works but
Sess0.Screen.PutString sendCommand
Sess0.Screen.SendKeys ("<Enter>")
doesnt !
 


PutString is not for sending commands. Rather, it is for placing a, er, uh, hmmm, ... a STRING at a particular place on your screen.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Ok I'll use sendkeys from now on. Strange how putstring works once logged on or if Enter is pressed a few times.
 



Hmmmm. Strange how I can loosen a screw with a pen knife, one I start it with a screw driver!!!!

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
after evoking the sendkeys, the cursor moves to the end of the string whereas evoking putstring the cursor remains where it was.
if your cursor is not in a field that can contain data, the sendkeys will not work; you should receive an error of some sort whereas the putstring will actually place strings but will lob off some of the data.

you really need to step through your code as this will show you what is happenning.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top