I have some basic code that I am trying to implement in VBA.
But I am getting errors. The code is meant to send commands to a remote server using sendkeys command. Since there is difference in speed between VBA and the server, sendkeys does not work at all times. So a waitforstring s inserted in between. This is the Basic code:

wait for string waitString until waitTil seconds
Function WaitForString(sess, waitString, waitTil)
waitRet = 0
waitRet = sess.WaitUntilString(waitString, waitTil)
If waitRet = 0 Then
'waitString not found, terminate script
Beep
End
End If
End Function

Sub Main
Const TIME_OUT = 12

'Create all objects and init
Dim Session1 As Object
Set Session1 = GetSession


Session1.Sendkeys("username<Enter>")
WaitForString(Session1,"Password: ",TIME_OUT)

Session1.Sendkeys("password<Enter>")
WaitForString(Session1,"$ ",TIME_OUT)

Session1.Sendkeys("copy x.prn y.dat <Enter>")

WaitForString(Session1,"$",TIME_OUT)
Session1.Sendkeys("command<Enter>")


End Sub

Can someone help me ??