X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 09 Feb 2007 10:02 AM by  anon
global variable
 3 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
09 Feb 2007 10:02 AM
    Dear all, How can I create a global variable with IDL 6.3? (In matlab I use a command "global" Thank you!

    Deleted User



    New Member


    Posts:
    New Member


    --
    09 Feb 2007 10:02 AM
    You can create your own system variable with DEFSYSV. Regards, SF

    Deleted User



    New Member


    Posts:
    New Member


    --
    09 Feb 2007 10:02 AM
    Look at IDL's Online Help for the index topic "COMMON statement". If the first PRO or FUNCTION in a .pro file (the first one that needs global variables, that is) has a statement like: COMMON myglobals, mySharedIntArray, mySharedwidgetID, mySharedString then all other PRO's or FUNCTION's that are compiled afterward can have an identical statement (or even an abbreviated version, like "COMMON myglobals") in their code, and those PRO's or FUNCTION's compiled afterward will all have access to reading or modifying the values stored by any in: 'mySharedIntArray', 'mySharedWidgetID' or 'mySharedString'. James Jones

    Deleted User



    New Member


    Posts:
    New Member


    --
    09 Feb 2007 10:02 AM
    I had this same question. After some trial and errors, and reading about the common block, I made this short piece of code to demonstrate the use of global variables:
    
    pro mysub
       COMMON SHARE, x, y, z ; "SHARE" is just a word I made up.  You can call it anything
       print, 'goodbye'
       print, x
    end
    
    pro GlobalVariables
       COMMON SHARE, x,y,z ; You must reuse the word "SHARE" here.  You can change the x,y,z to anything you like
       print, 'hello'
       x=2
       mysub
    end
    
    Save this as "GlobalVariables.pro", not as "mysub.pro". When yo run it, your output should be: hello goodbye 2
    You are not authorized to post a reply.