Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Want to thank those people who have made this forum such a valuable place to visit each day..."

Geography

Where in the world do Tek-Tips members come from?
Xamonas (Programmer)
31 Aug 06 10:05
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.
calculus (Programmer)
31 Aug 06 15:07
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
Xamonas (Programmer)
1 Sep 06 5:32
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

Xamonas (Programmer)
1 Sep 06 5:43
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?
Helpful Member!(2)  Skie (Programmer)
7 Sep 06 18:15
Is there any reason you need to use Global variables?

Quote:

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.
Xamonas (Programmer)
8 Sep 06 5:02
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

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close