×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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
 

RE: SendKeys ("<Enter>") doesnt work straight away

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

RE: SendKeys ("<Enter>") doesnt work straight away

did you check HELP on putstring

RE: SendKeys ("<Enter>") doesnt work straight away



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,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: SendKeys ("<Enter>") doesnt work straight away

(OP)
Ok I'll use sendkeys from now on. Strange how putstring works once logged on or if Enter is pressed a few times.

RE: SendKeys ("<Enter>") doesnt work straight away




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

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: SendKeys ("<Enter>") doesnt work straight away

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close