Invalid Procedure Call or Argument
Invalid Procedure Call or Argument
(OP)
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
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
RE: Invalid Procedure Call or Argument
You never stated the statement that the error occurred pn!
I'd guess
Set System = CreateObject("Extra.Application")
RE: Invalid Procedure Call or Argument
Thank you for very quick answer
Correct me if I am wrong.
I should replace "System" with "Application" for all statements?
Kind Regards
Tommeck37
RE: Invalid Procedure Call or Argument
RE: Invalid Procedure Call or Argument
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
RE: Invalid Procedure Call or Argument
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
RE: Invalid Procedure Call or Argument
CODE
RE: Invalid Procedure Call or Argument
Now the error is
Run-Time Error '91'
Object Variable or With block Variable not set
Kind Regards
Tommeck37
RE: Invalid Procedure Call or Argument
Perhaps I should tick out something in Attachmate?
Kind Regards
Tommeck37
RE: Invalid Procedure Call or Argument
RE: Invalid Procedure Call or Argument
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
RE: Invalid Procedure Call or Argument
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
RE: Invalid Procedure Call or Argument
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
RE: Invalid Procedure Call or Argument
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.
RE: Invalid Procedure Call or Argument
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
RE: Invalid Procedure Call or Argument
RE: Invalid Procedure Call or Argument
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
RE: Invalid Procedure Call or Argument
RE: Invalid Procedure Call or Argument
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
RE: Invalid Procedure Call or Argument
RE: Invalid Procedure Call or Argument
Could anyone try if the below code works for you?
I think I am facing not-VBA-type problem with connection.
CODE --> VBA
Thank you
Tommeck37
RE: Invalid Procedure Call or Argument
RE: Invalid Procedure Call or Argument
It seems that it is not the code that causes problem.
I've tried many codes which work successfully on other machines but not on mine. Therefore I must conclude that there is missing some sort of setup in attachmate that makes it unavailable for excel to obtain connection through CREATEOBJECT function.
I posted the above code to double confirm if another code works fine on another machine rather than mine, which gets me to the above conclusion.
Do you know perhaps if there is anything I should check with Attachmate (Options, preferences etc) that could be not switched on to be able to bind connections with excel VBA?
Kind Regards,
Tommeck37
RE: Invalid Procedure Call or Argument
did you check Citrix?
RE: Invalid Procedure Call or Argument
I finally moved with the problem forward. It turned out that this version of system accepts different object names.
I copied sample codes from producer's website and binding was ok.
Now I cannot move on with the code
CODE --> vba
The application should go into session "CRO" then enter what I input in InputBox (account number) then two line below another input from InputBox and press enter and repeat that with a loop.
Oddly, the application only goes into CRO and stops.
Would you have any idea how to make it move all the way into account given in InputBox.
Kind Regards
Tommeck37
RE: Invalid Procedure Call or Argument
Furthermore you're entering CRO, waiting 100 ms for what, (nothing has happened yet, you just put some characters on the screen), THEN you SendKeys ASYNCHRONOUSLY to the mainframe with no idea when the mainframe will respond. HERE is where you need to wait UNTIL THE MAINFRAME RESPONDS WITH THE CRO STUFF, before you Put anothing on the screen!
RE: Invalid Procedure Call or Argument
What kind of loop should be ok? The thing is to loop until the app will be able to enter specific account entry while pressing "enter". Items end when after enter key there is no entry on the screen visible.
Do Loop? But how to apply to the entire "With" block?
Kind Regards
Tommeck37
RE: Invalid Procedure Call or Argument
RE: Invalid Procedure Call or Argument
CODE --> vba
RE: Invalid Procedure Call or Argument
Now if you had a source, lets say your Input Box...
CODE
RE: Invalid Procedure Call or Argument
In my experience, that data has either been entered into a spreadsheet or imported, and that list is used to populate the screen in a loop.
RE: Invalid Procedure Call or Argument
The above loop repeats the first block which is not needed
I will try to explain more in details
This part:
CODE --> vba
enters session "CRO", then opens account number (given in Input Num) goes line below to enter reference number (Num2) and presses enter to go into account view. Then code
CODE --> vba
Replaces reference in line 5, 54 with what I input in InputBox (Num1), confirms by pressing "enter" confirm with writing letter "Y" in line 16, 27 and then it should go up again to line 5, 54 replace reference with Num1, "enter" and confirm by writing y in line 16, 27 and so on and so on until it will not be possible to do it because system will stop it. I would then trigger some sort of MsgBox like "changing reference is finished"
All in all, the loop is needed for the entire second bloc which changes reference presses enter and writes "Y" and presses enter to go on to next reference which will be changed again.
Cheers
Tommeck37
RE: Invalid Procedure Call or Argument
What do you mean by "confirms by pressing 'enter'?"
What is the confirmation that the system returns?
RE: Invalid Procedure Call or Argument
I did not express myself correctly
By pressing enter I meant sending key to the screen
it goes like this
puts string from Num1 to line 5, 54, sends enter then sends keys "Y" to the screen and then sends "enter" again - this process I would like to repeat as long as system will allow.
System response to my last "enter in this loop' is that it goes on to next screen with next reference (which I'd like to change into different one, and then anothe screen and another etc)
All in all, this is going from screen to next screen and replacing existing reference with reference given in InputBox
RE: Invalid Procedure Call or Argument
So do you PUT "Y" on the screen or do you SendKeys "Y" then wait for a response and then SendKey ENTER and wait for a response?
Then you go to the next screen with a reference "I'd like to change". Well how do you want to change the reference without an InputBox IN THE LOOP?
Every system I've worked with over the past 30 years, has a specific area on the screen for the system to tell you what's happeneing. Simple getting another screen ODBC data is not enough. SOMEWHERE it must say something like MORE and DONE!
RE: Invalid Procedure Call or Argument
Then I would like to go back to line 5, 54 and do the same that is put string of numbers which come from InputBox, sendkey "enter" put "Y" on the screen and go on to next screen by SendingKey "Enter"
The code I have so far is good as it does the job well but only once. All is needed is to make it repeat that phase on and on
RE: Invalid Procedure Call or Argument
RE: Invalid Procedure Call or Argument
It asked me for Num Num1 and Num2 multiple times
What do you think of this
CODE --> vba
I cannot check it now as I am out of office
RE: Invalid Procedure Call or Argument
CODE
RE: Invalid Procedure Call or Argument
I tried the above but this asks many times to enter Num, Num1 and Num2 which multiplies the workload
I managed to figure out a loop like the below but this is not enough. Missing is the condition to stop looping because this code loops endlessly and therefore I have to kill (by task manager) excel in order to stop it :)
What condition can I put to loop in order to stop it? I've tried with
CODE --> vba
This is the code that loops endlessly
CODE --> vba
Kind Regards
Tommeck37
RE: Invalid Procedure Call or Argument
RE: Invalid Procedure Call or Argument
RE: Invalid Procedure Call or Argument
What you're saying is that you program has to SOMEHOW determine when it "sees" the original screen again? Well YOU have to tell me how that recognition will occur, or somehow logically describe that condition, that can then be translated into VB code. I can't tell you how your screen/system operates. It is TOTALLY foreign to the experiences I've seen in 30 years in the aerospace industry in 4 different companies.
RE: Invalid Procedure Call or Argument
1. Vba enters Session CRO from list of sessions
2. On the screen of CRO it enters account number (nostro number) and the reference (in the line below)
3. then opens a screen where the loop does its job. It goes and goes until screens run out and it kicks it out back to point 2 where you normally enter account number and reference below the line.
I would guess that the loop could have a condition that if it sees the initial screen of the CRO it should stop
Yes, there is some piece of info at the bottom of screen when the session is kicked out to initial screen of CRO when the Loop still tries to enter values that was entering inside of session CRO.
The screen shows some sort of info like wrong data or something like that. Generally, initial screen is open of CRO and vba still tries to putstring values on 5, 54 lines while there is no space for such input.
Kind Regards
Tommeck37
RE: Invalid Procedure Call or Argument
I need to know how this system operates, and yes, it is VERY important about the "some piece of info at the bottom of screen" that seems to you as some insignificant throw away, hardly worth mentioning, just in passing, when I've asked more than once for this kind of information. SOP for loops!
So would you care to let the cat out of the bag: what's going on with the message area?
RE: Invalid Procedure Call or Argument
I will get you every detail of that information but only tomorrow as I have left the office for today.
Kind Regards
Tommeck37
RE: Invalid Procedure Call or Argument
So I am back with the information
System shows precisely this message: *** CRO 001 : WRONG OPERATION ***
whereas CRO 001 is the name of the session
below that line, there is a small clock colon and number: "00.1" at the end of line localization of cursor 11/27
That's what is visible when the macro still tries to loop
Kind Regards
Tommeck37
RE: Invalid Procedure Call or Argument
What about when you need to hit the ENTER key to get another screen?
And what about when you need not hit ENTER to get another screen?
Are thee no messages in those circumstances?
RE: Invalid Procedure Call or Argument
or when it sees the first screen. surely, there's something on the first screen that is unique. for example, maybe the first screen says "ENTER HERE" at position 2,2. Then all you need to do is to look for that narrative
RE: Invalid Procedure Call or Argument
I finally reached the expected result.
What I did was to give a condition for a loop to check content of screen when all job is done by a loop and session is kicked out to initial screen.
this is the code that works peferctly
CODE --> VBA
The only missing thing in this application is an outcome for "Cancel" button in InputBox
Is there a way to just let the application finish executing code and showing a simmple message like "Nothing was done"??
Kind Regards
Tommeck37