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

Problems with Macro execution 2

Status
Not open for further replies.

Xamonas

Programmer
Aug 31, 2006
6
GB
Reference thread1-1028846, I am having similar problems with macros failing to execute. I get a message box saying 'Macro failed to begin execution' and no other information.

Opening the macro editor and compiling the macro shows no errors at all. The problem persists however I try running the macro - from the Tools menu, from within the editor, from a keyboard or menu shortcut.

The problem does not appear to affect all macros, some will still run even when another refuses. It also affects some more than others. In some cases, the problem occurs every few times I attempt to execute the macro, in others, it happens once in a blue moon, others seem completely immune.

Exiting Extra and restarting it cures the problem every time (as far as I know), implying that this is NOT an issue with the macro per-se but with some internal workings of Extra. I am wondering if there is anything that Extra sets in the registry, or any internal Extra, system variable that might be causing this issue? Could an error in a previously executed macro be preventing others from starting.

FYI, the macro that I am having the most trouble with copies blocks of text from the screen and writes it to a text file on the C:\ drive.
 
Sounds like the Macro is not exiting correctly. Are all of your defined objects closed? For instance to you close the file you write to?

I think you'll have better luck diagnosing this if you note not the macro that gets the error, but the macro run previously.

calculus
 
Thanks calculus,

You've come to the same conclusion that I have. Trouble is, as far as I can see, I am closing all files correctly. Here's some more details:

1. As far as I can tell, there are 2 macros which seem to tread on each others toes. When I run either of them, there is a chance that the other will refuse to start if I run it later in the same session. Both macros copy screen details and write them to a file.

2. Usually, closing the Extra session and restarting Extra cures the issue. This morning however, I had to reboot my PC to sort things out!

3. Below is the code for the smaller of the 2 macros - any suggestions?

Code:
Global g_HostSettleTime%
Global g_szPassword$
Declare Sub SendScreen
global lines
Global Sess0 as object
Global System as object
Global Sessions as object



Sub Main()
   
' ******************************
' * Get the main system object *
' ******************************
    
    On Error Goto ErrProc
    
    Set System = CreateObject("EXTRA.System")	' Gets the system object
    If (System is Nothing) Then
	Msgbox "Could not create the EXTRA System object.  Stopping macro playback."
    	STOP
    End If
    Set Sessions = System.Sessions

    If (Sessions is Nothing) Then
	   Msgbox "Could not create the Sessions collection object.  Stopping macro playback."
	   STOP
    End If
    
' ************************************
' * Get the necessary Session Object *
' ************************************

    Set Sess0 = System.ActiveSession
    If (Sess0 is Nothing) Then
    	Msgbox "Could not create the Session object.  Stopping macro playback."
    	STOP
    End If
    If Not Sess0.Visible Then Sess0.Visible = TRUE
    Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

' *********************
' * Initial Variables *
' *********************

    g_HostSettleTime = 100    
    lines = 0
        
    reset

' ********************
' * Open Output File *
' ********************

    if (dir$("c:\CICS Screens",16) = "") then
        MkDir "c:\CICS Screens"
    end if
    
    Savefilename$ = "c:\CICS Screens\" + Format(now(),"yy-mm-dd hh.nn.ss") + ".txt" 
    
    Open Savefilename$ For Output As 1

' ****************
' * Grab Screens *
' ****************
    
    call SendScreen
    

' *************
' * Closedown *
' *************
 
CloseDown:
 
    close #1
    
    reset
    
    msgbox (lines + " lines written to " + Savefilename$)   

    Set Sess0 = Nothing
    Set Sessions = nothing
    Set System = nothing
 
    
    Exit Sub
    
    
ErrProc:

    msgbox ("There was an error!")
    
    resume closedown


End Sub


private sub SendScreen

    TopLine$ = "*&*&*&*TOP*&*&*&*"
    BottomLine$ = "*&*&*&*BOTTOM*&*&*&*"

    print #1, topline
    lines = lines + 1
    
    current_page$ = Sess0.Screen.GetString (1, 1, 24*80)

    for lin = 1 to 24
        thislin = mid$(current_page$, (80 * lin) - 79, 80)
        Print #1, thislin
        lines = lines + 1
    next lin
    
    print #1, BottomLine
    lines = lines + 1

end sub

 
PS. One more thing. I can run either macro as often as I like with no errors.

Surely, if I was leaving a file open, it would interfere with executing the same macro a second time just as much as it does with running a second, similar macro. What do you think?
 
Is there any reason you need to use Global variables?

Global data is shared across all loaded modules. If an attempt is made to load a module that has a global variable declared that has a different data type than an existing global variable of the same name, the module load will fail.

If you don't need to do this, replaced Global with Dim and try the macros again. This will eliminate the posibility that Global variables are mucking up the works.
 
Thanks a million Skie, I owe you a LOT of beer!

Serves me right for basing all of my screen-copy macros on someone else's and assuming they had got it right!!

I did a find/replace on Global/Dim and everything works fine now.

Thanks again,

XC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top