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 Chris Miller 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
 
Hello,

Could anyone try if the below code works for you?
I think I am facing not-VBA-type problem with connection.

Code:
'   MACRO NAME:    excel.ebm
'   DATE WRITTEN:  11/21/97, Attachmate Automation Support (ng)
'   DESCRIPTION:   For use with EXTRA! Personal Client 6.x (and derivatives).
'                  Also requires 32-bit Microsoft Excel to be installed.
'
'   NOTES:         This macro illustrates how an Excel spreadsheet can be accessed
'                  and manipulated from within an EXTRA! Basic macro. The macro does
'                  the following steps:
'                  1. Connect to the currently active EXTRA! session.
'                  2. Start Excel.
'                  3. Create an new .xls file (workbook) and save it.
'                  4. Copy the current screen in EXTRA! to the Excel worksheet.
'                  5. Save the worksheet.
'
'                  EXTRA! Basic and Excel VBA are extremely similar. Note that this
'                  macro will run perfectly if the body of it is copied to a Sub in
'                  an Excel module.
'
'
'                  ˆ Copyright 1989-1997, Attachmate Corporation. All Rights Reserved.
'
'                  This macro is provided as an example only. It is provided as-is,
'                  without warranty or support from Attachmate Corporation.
'
'==============================================================================

Sub Main()
    
    Dim sys As Object, sess As Object, xl As Object, wb As Object
    Dim iCount As Integer, iRows As Long, iCols As Long
    Dim sFile As String
    
    sFile = "C:\EXTRAScreenCopy.xls"
    
    
    'GET ACCESS TO THE TOP LEVEL E!PC OBJECT...
    Set sys = CreateObject("Extra.System")
    If sys Is Nothing Then
        MsgBox ("Could not create Extra.System...is E!PC installed on this machine?")
        Exit Sub
    End If
    
    'GET ACCESS TO THE CURRENTLY ACTIVE SESSION...
    Set sess = sys.ActiveSession
    If sess Is Nothing Then
        MsgBox ("No session available...stopping macro playback.")
        Exit Sub
    End If
        
    'START EXCEL...IT WILL NOT BE VISIBLE YET, BUT WILL STILL BE IN MEMORY....
    'THIS IS THE SAME AS STARTING EXCEL WITH NO CURRENT WORKBOOK
    Set xl = CreateObject("Excel.Application")
    If xl Is Nothing Then
        MsgBox ("Could not create Excel.Application...is Excel installed on this machine?")
        Exit Sub
    End If
        
    
    'CREATE A NEW WORKBOOK...THIS IS JUST LIKE CHOOSING 'FILE-NEW...'
    Set wb = xl.Workbooks.Add
    If wb Is Nothing Then
        MsgBox ("Add method of Excel Workbooks object failed.")
        xl.Quit
        Exit Sub
    End If
        
    
    'SAVE THE NEW WORKBOOK JUST CREATED...
    'AN ERROR WILL OCCUR IF THIS FILE CURRENTLY EXISTS AND THE USER CHOOSES
    'NOT TO REPLACE THE EXISTING OR CHOOSES CANCEL...
    'AN ERROR WILL ALSO OCCUR IF THE SPECIFIED .XLS IS CURRENTLY OPEN,
    'SO CLOSE IT BEFORE RUNNING THIS MACRO....
    On Error GoTo error_exit
    wb.SaveAs (sFile)
        
    iRows = sess.Screen.Rows
    iCols = sess.Screen.Cols
        
    'COPY THE CURRENT SCREEN TO THE WORKSHEET...
    'IT'S LIKELY TO LOOK BEST IF A NON-PORPORTIONAL FONT IS USED.
    For iCount = 1 To iRows
        wb.Worksheets("sheet1").Cells(iCount, 1).Value = sess.Screen.GetString(iCount, 1, iCols)
        wb.Worksheets("sheet1").Cells(iCount, 1).Font.Name = "Courier New"
    Next iCount
        
    'SAVE THE CHANGES TO THE WORKBOOK THEN QUIT EXCEL...
    wb.Save

error_exit:
    
    xl.Quit
    If Err Then
        MsgBox sFile + " was not replaced."
    Else
        MsgBox "Created  " + sFile
    End If
    
    Exit Sub
                            
End Sub


Thank you
Tommeck37
 
Hello,

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
 
Hello,

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:
Sub Main()
Num = Application.InputBox("Enter nostro Number")
Num1 = Application.InputBox("Enter what to change into")
Num2 = Application.InputBox("Enter what to change")


        Dim Sys As Object, Sess As Object, Screen As Object
    Set Sys = CreateObject("EXTRA.System")


' Assumes an open session
    Set Sess = Sys.ActiveSession
        Set Screen = Sess.Screen
        

        
With Screen
        .PutString "CRO", 1, 4
       .WaitHostQuiet (100)
       .SendKeys ("<enter>")
       .PutString "8038813", 11, 27
       .MoveTo 13, 27
       .PutString Num2, 13, 27
       .SendKeys ("<enter>")
           
    End With
    

    
With Screen
        Screen.MoveTo 5, 54
        .PutString Num1, 5, 54
       .WaitHostQuiet (100)
       .SendKeys ("<enter>")
       .PutString "y", 16, 27
       .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 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
 
I see no loop.

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!
 
Yeah, it works. The app went in and did the job.

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
 
Here is the block I would like to loop until machine will be able to go, until attachmate will stop it

Code:
With Screen
        Screen.MoveTo 5, 54
        .PutString Num1, 5, 54
       .WaitHostQuiet (100)
       .SendKeys ("<enter>")
       .PutString "y", 16, 27
       .SendKeys ("<enter>")
       .WaitHostQuiet (100)
    End With
 
Well that's not really the makings of a loop. A loop is when you repeat the same things with different data. In this example you are merely doing two things one time.

Now if you had a source, lets say your Input Box...
Code:
'
   With Screen
     Do
        Num = Application.InputBox("Enter nostro Number")
        If Num = "" Then Exit Do
        Num1 = Application.InputBox("Enter what to change into")
        Num2 = Application.InputBox("Enter what to change")
     
        .PutString Num1, 5, 54
        .SendKeys ("<enter>")
        Do Until .waitforcursor(r, c)
            DoEvents
        Loop
        
        .PutString "y", 16, 27
        .SendKeys ("<enter>")
        Do Until .waitforcursor(r, c)
            DoEvents
        Loop
        
      Loop
    End With
...but I have no idea what Num and Num2 are being used for???
 
...but then the user has to be sitting there entering data and waiting for the mainframe to respond, which may be okay in some circumstances.

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.
 
No, No.

The above loop repeats the first block which is not needed

I will try to explain more in details

This part:

Code:
Sub Main()
Num = Application.InputBox("Enter nostro Number")
Num1 = Application.InputBox("Enter what to change into")
Num2 = Application.InputBox("Enter what to change")


        Dim Sys As Object, Sess As Object, Screen As Object
    Set Sys = CreateObject("EXTRA.System")


' Assumes an open session
    Set Sess = Sys.ActiveSession
        Set Screen = Sess.Screen
        

        
With Screen
        .PutString "CRO", 1, 4
       .SendKeys ("<enter>")
       .WaitHostQuiet (100)
       .PutString Num, 11, 27
       .MoveTo 13, 27
       .PutString Num2, 13, 27
       .SendKeys ("<enter>")
       .WaitHostQuiet (200)
    End With

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:
With Screen
       
        .PutString Num1, 5, 54
       .SendKeys ("<enter>")
       .WaitHostQuiet (100)
       .PutString "y", 16, 27
       .SendKeys ("<enter>")
       .WaitHostQuiet (100)
    End With

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
 
I did NOTHING with your first block containing CRO!!! I don't understand how your screen works, ie what is being entered and what system responses etc.

What do you mean by "confirms by pressing 'enter'?"

What is the confirmation that the system returns?

 

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
 
You PUT text on the screen without any SendKeys, cuz SendKeys does not PUT anything ON the screen. SendKeys talks to the system with whatever is sent, sends the system off ASYNCHRONOUSLY to do whatever you told it to do and then returns some response after ??? Period of time.

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!
 
I put "Y" on the screen then SendKey "Enter" and after this system goes on to next screen
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


 
Of course :)

It asked me for Num Num1 and Num2 multiple times


What do you think of this

Code:
Do While Session.GetString, 5, 54 = ""
With Screen
       
        .PutString Num1, 5, 54
       .SendKeys ("<enter>")
       .WaitHostQuiet (100)
       .PutString "y", 16, 27
       .SendKeys ("<enter>")
       .WaitHostQuiet (100)
    End With 
Loop

I cannot check it now as I am out of office
 
Again, What do you think this does not do that you just asked for?

Code:
'
   With Screen
     Do
        Num = Application.InputBox("Enter nostro Number")
        If Num = "" Then Exit Do
        Num1 = Application.InputBox("Enter what to change into")
        Num2 = Application.InputBox("Enter what to change")
     
        .PutString Num1, 5, 54
        .SendKeys ("<enter>")
        Do Until .waitforcursor(r, c)
            DoEvents
        Loop
        
        .PutString "y", 16, 27
        .SendKeys ("<enter>")
        Do Until .waitforcursor(r, c)
            DoEvents
        Loop
        
      Loop
    End With f
 
Hello

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:
Do until sess.screen.getstring (5, 54 , 8) = ""
but it does not work

This is the code that loops endlessly

Code:
Sub Main()
Num = Application.InputBox("Enter nostro Number")
Num1 = Application.InputBox("Enter what to change into")
Num2 = Application.InputBox("Enter what to change")


        Dim Sys As Object, Sess As Object, Screen As Object
    Set Sys = CreateObject("EXTRA.System")


' Assumes an open session
    Set Sess = Sys.ActiveSession
        Set Screen = Sess.Screen
        

        
With Screen
        .PutString "CRO", 1, 4
       .SendKeys ("<enter>")
       .WaitHostQuiet (100)
       .PutString Num, 11, 27
       .MoveTo 13, 27
       .PutString Num2, 13, 27
       .SendKeys ("<enter>")
       .WaitHostQuiet (200)
    End With
    

  Do  
With Screen
       
        .PutString Num1, 5, 54
       .SendKeys ("<enter>")
       .WaitHostQuiet (100)
       .PutString "y", 16, 27
       .SendKeys ("<enter>")
       .WaitHostQuiet (100)
    End With
Loop
   
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

Kind Regards
Tommeck37
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top