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

Invalid Procedure Call or Argument

Status
Not open for further replies.

Tommeck37

Vendor
Jan 2, 2015
83
PL
Hello Dear Experts,

I am trying to get connection to Attachmate Extra (mainframe) in order to send some key strokes.
However, there seems to be missing some detail in a setup as I get Run-Time Error 5 saying "Invalid Procedure Call or Argument"


Does have anyone any idea what is missing in the below macro so that the connection can be made?

In addition to the procedure, I have References ticked out:

- Microsoft Visual Basic for Applications
- Microsoft Excel 14.0 Object Library
- Ole Automation
- Microsoft Office 14.0 Object Library

Here is the code I am using
Sub test() Dim System As Object
Dim Session As Object
Dim Screen As Object

On Error GoTo Err_h:

Set System = CreateObject("Extra.System")
If System Is Nothing Then Err.Raise 99999, "test sub", "Could not create Extra system object."

Set Session = System.ActiveSession
If Session Is Nothing Then Err.Raise 99999, "test sub", "Extra has not been launched. Please start the application."

Set Screen = Session.Screen
With Screen
.Putstring "CRO", 1, 4
.WaitHostQuiet (milliseconds)
.SendKeys ("")
End With

Clean_Exit:
Set Screen = Nothing
Set Session = Nothing
Set System = Nothing
Exit Sub
Err_h:
If Err.Number <> 0 Then
MsgBox "Error " & Err.Number & Chr(10) & Err.Description & Chr(10), vbCritical, "Error"
End If
GoTo Clean_Exit
End Sub


Thank you for any directions in solving the problem

Regards

Tommeck37
 
Hi,

You never stated the statement that the error occurred pn!

I'd guess

Set System = CreateObject("Extra.Application")


 
Hello,

Thank you for very quick answer

Correct me if I am wrong.

I should replace "System" with "Application" for all statements?

Kind Regards
Tommeck37
 
No! You're creating an application object that you have named System.
 
Hi,

In that case, I will change the code to:

Sub test()
Dim System As Object
Dim Session As Object
Dim Screen As Object

On Error GoTo Err_h:

Set System = CreateObject("Extra.Application")
If System Is Nothing Then Err.Raise 99999, "test sub", "Could not create Extra system object."

Set Session = System.ActiveSession
If Session Is Nothing Then Err.Raise 99999, "test sub", "Extra has not been launched. Please start the application."

Set Screen = Session.Screen
With Screen
.Putstring "CRO", 1, 4
.WaitHostQuiet (1000)
.SendKeys ("<enter>")
End With

Clean_Exit:
Set Screen = Nothing
Set Session = Nothing
Set System = Nothing
Exit Sub
Err_h:
If Err.Number <> 0 Then
MsgBox "Error " & Err.Number & Chr(10) & Err.Description & Chr(10), vbCritical, "Error"
End If
GoTo Clean_Exit
End Sub

Will that be ok now?


PS. I will only be able to check the code with Attachmate on Monday once I get to the office.
Regards
Tommeck37
 
Hey,

I changed:

Set System = CreateObject("Extra.System")
to
Set System = CreateObject("Extra.Application")

And there is an error 429 ActiveX component can't create object.

I think this is because "Application" does not belong to Attachmate's object model. As far as I am aware this is "system" that is, in the highest position to which binding should be made.

Kind Regards
Tommeck37
 
This is how my code looks
Code:
Sub test()
    Dim Sessions As Object
    Dim System As Object
    Set System = CreateObject("EXTRA.System")
    Set Sessions = System.Sessions
    Set sess = System.activeSession
    Set screen = sess.screen

    With screen
        .putstring "CRO", 1, 14
        .WaitHostQuiet (50)
    End With
    
End Sub
 
Another attempt fails

Now the error is

Run-Time Error '91'
Object Variable or With block Variable not set

Kind Regards
Tommeck37
 
I've tried many codes which other people use successfully but not here.

Perhaps I should tick out something in Attachmate?

Kind Regards
Tommeck37
 
Hello,

This is the code

Sub test()
Dim System As Object
Dim Session As Object
Dim Screen As Object

On Error GoTo Err_h:

Set System = CreateObject("Extra.System")
If System Is Nothing Then Err.Raise 99999, "test sub", "Could not create Extra system object."

Set Session = System.ActiveSession
If Session Is Nothing Then Err.Raise 99999, "test sub", "Extra has not been launched. Please start the application."

Set Screen = Session.Screen
With Screen
.Putstring "CRO", 1, 4
.WaitHostQuiet (1000)
.SendKeys ("<enter>")
End With

Clean_Exit:
Set Screen = Nothing
Set Session = Nothing
Set System = Nothing
Exit Sub
Err_h:
If Err.Number <> 0 Then
MsgBox "Error " & Err.Number & Chr(10) & Err.Description & Chr(10), vbCritical, "Error"
End If
GoTo Clean_Exit
End Sub

The error that generates here is : "Invalid Procedure Call or Argument"

Of course I've tried your above code with error as stated above.

Kind Regards
Tommeck37
 
Tommeck37,
I wanted to see if I can duplicate your error.
just curious, do you have an active Attachmate session open? I get an "Error 5 Invalid procedure call or argument" when there is no session available.

btw, what version of Excel and Attachmate are you using?
your code does work on my Excel 2010/Attachmate Extreme 9.3. I did not do anything special with any settings in Attachmate nor Excel.

rem
 
Hi,

It seems to me the problem lies in applications' settings.

I am using excel 2010. Attachmate is open and active. I tried with only one session. I've tried with multiple sessions. I am using two monitors.
I tried one both monitors and I tried on one monitor excel and attachmate.

Maybe there is something with the file of attachmate I am starting application with.
Attachmate and excel are run via Citrix. Maybe here is something to do with the problem.

At least I am sure that the code is correct. This is some step forward with the problem.

Kind Regards
Tommeck37
 
An unrelated comment on your code:

The PutString() function communicates directly with the screen and requires no delay in your code.

However, SendKeys() does, since this communication is with the mainframe and is asynchronous which means that the mainframe's response could be 1 second, 1 minute, 1 hour; no one knows! So simply to wait a predetermined period of time is akin to deciding that you'll wait 15 seconds at each traffic light or stop sign before proceeding through an intersection! A better method is to use something like WaitForCursor after SendKeys, in a loop.
 
Hello,

Maybe the problem is with making the session active?

How do I make a session active? If I activate excel (macro initiator), is Attachmate active then?

Maybe the problem is that simple?

Kind Regards
Tommeck37
 
The active session is the one that you defined in your code. It is active even when your Excel is active and your code is running.
 
Hello,

I got a code that is supposed to bind Attachmate successfully in my office. (I do not know what was the matter with the previous one, version maybe)
However, I received it in notepad. I do not know how to execute it. Can this code be somehow input to Excel VBE so that it can be run as a regular Sub End sub procedure?

I have attached the file with the code

Thank you
Tommeck37
 
 http://files.engineering.com/getfile.aspx?folder=6b63d3b6-ec9e-4e9b-a3c3-b1c03291c3f3&file=Attachmate_code.txt
That's what I've tried to do.

However, how to execute the code then if this is Private Sub?
I have no idea about userforms and events etc.

Do I have to create a sort of button that would trigger a specific code?

Thank you
Tommeck37
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top