Why is variable scope so vexing?!  Argh!

Dear Friends
I used to think that if I declared a variable at the top of
the first frame of my main timeline (and outside of any function
bodies) that it would basically be considered "global" and could be
accessed at any further frame in the main timeline (and by any
child of the main timeline via prefixing enough "parent."s) but
this is apparently not the case (unless there's something funny
with uints where their values go to 0 from one frame to the next.)
Is there something I'm missing here? Why is it so hard to declare a
variable that can be easily seen throughout the main timeline (and
the rest of the app as well)?
And speaking of children seeing their parent's variables,
what is the easiest way to make a variable declared on the main
timeline accessible inside of a child? I don't want to have to
count ancestors and add "parent.parent.parent." etc. and "root."
doesn't seem to work... What's the magic prefix? Isn't there also a
way of setting a variable equal to "this" on the main timeline? I
don't know how it works, really.
More generally speaking, does anyone have a surefire tutorial
on variable scoping? I've read Moock and pored over the Help manual
and it all still feels a lot less intuitive than it ought to. How
do I master this subject?!
Thanks and Be Well,
Graham

graham - you're right in saying that a var on the main
timeline can be considered 'global' even without the use of a
'_global' keyword - and i remember in my early learning i
definitely thought the same thing as you are now. It's really a
matter of 'paths' as you mention, but one does need to 'point' to
the main in order to retrieve the value via root or a series of
parents - even when using class structures as is more common now
under 3, one still needs to point at the correct scope to access a
property.
sometimes though, a var can be 'reset' ... what i mean by
this is, say for instance you have declared a var on the first
frame, the playhead then navigates to a different frame wherein the
variable has been set to a different value, then at another time
the playhead returns to frame one (because one has a navigation
structure that does so) in this case the variable is 're-declared'
and set back to the default value! this type of situation often
occurs with a timeline based system.
class properties on the other hand, cannot be reset in this
manner, which is one of the many reasons why class based systems
are better for complex programming. personally, now-a-days my
programs so not usually contain anything on the main timeline, no
code or assets, instead all operations are achieved through code,
mainly within class files (as is the benefit of 3)
I'm sorry i don't know of any tuts i could point you to, just
stick with it - i think that over time it hierarchy structure and
path scopes become second nature - and at the rate you seem to be
advancing, it shouldn't take long ;)

Similar Messages

  • Variable Scope at package or interface level

    Hi,
    Can we set the ODI Project variable scope to package or interface level
    because in my project im using a last rundate refresh variable this variable value will be changed at the time of execution of each package.
    Thanxs
    Madhavi

    you can create it as "Not Persistent" and then its value exist per ODI session.
    In this way, several sessions can keep independent value to the same variable.

  • Why trantient variables won't participate in serialization

    why trantient variables won't participate in serialization?
    Reason Plz.
    Static variables are not an instance variables so they don't participate
    In which places transient ,statics are used
    Help me
    Byeeee

    why trantient variables won't participate in serialization?
    Reason Plz.
    Because the key word transient says that they are not supposed to be
    serialized .
    -Lets say you have a Timer as a part of the class then it shoud be
    declared as transient as Timer state need not be preserved but its
    a requirement that it starts a fresh evry time.

  • Javascript discussion: Variable scopes and functions

    Hi,
    I'm wondering how people proceed regarding variable scope, and calling
    functions and things. For instance, it's finally sunk in that almost
    always a variable should be declared with var to keep it local.
    But along similar lines, how should one deal with functions? That is,
    should every function be completely self contained -- i.e. must any
    variables outside the scope of the function be passed to the function,
    and the function may not alter any variables but those that are local to
    it? Or is that not necessary to be so strict?
    Functions also seem to be limited in that they can only return a single
    variable. But what if I want to create a function that alters a bunch of
    variables?
    So I guess that's two questions:
    (1) Should all functions be self-contained?
    (2) What if the function needs to return a whole bunch of variables?
    Thanks,
    Ariel

    Ariel:
    (Incidentally, I couldn't find any way of  marking answers correct when I visited the web forums a few days ago, so I gave up.)
    It's there...as long as you're logged in at least, and are the poster of the thread.
    What I want is to write code that I can easily come back to a few months later
    and make changes/add features -- so it's only me that sees the code, but
    after long intervals it can almost be as though someone else has written
    it! So I was wondering if I would be doing myself a favour by being more
    strict about make functions independent etc. Also, I was noticing that
    in the sample scripts that accompany InDesign (written by Olav Kvern?)
    the functions seem always to require all variables to be passed to it.
    Where it is not impractical to do so, you should make functions independent and reusable. But there are plenty of cases where it is impractical, or at least very annoying to do so.
    The sample scripts for InDesign are written to be in parallel between three different languages, and have a certain lowest-common-denominator effect. They also make use of some practices I would consider Not Very Good. I would not recommend them as an example for how to learn to write a large Javascript project.
    I'm not 100% sure what you mean by persistent session. Most of my
    scripts are run once and then quit. However, some do create a modeless
    dialog (ie where you can interface with the UI while running it), which
    is the only time I need to use #targetengine.
    Any script that specifies a #targetengine other than "main" is in a persistent session. It means that variables (and functions) will persist from script invokation to invokation. If you have two scripts that run in #targetengine session, for instance, because of their user interfaces, they can have conficting global variables. (Some people will suggest you should give each script its own #targetengine. I am not convinced this is a good idea, but my reasons against it are mostly speculation about performance and memory issues, which are things I will later tell you to not worry about.)
    But I think you've answered one of my questions when you say that the
    thing to avoid is the "v1" scope. Although I don't really see what the
    problem is in the context of InDesign scripting (unless someone else is
    going to using your script as function in one of theirs). Probably in
    Web design it's more of an issue, because a web page could be running
    several scripts at the same time?
    It's more of an issue in web browsers, certainly (which I have ~no experience writing complex Javascript for, by the way), but it matters in ID, too. See above. It also complicates code reuse across projects.
    Regarding functions altering variables: for example, I have a catalog
    script. myMasterPage is a variable that keeps track of which masterpage
    is being used. A function addPage() will add a page, but will need to
    update myMasterPage because many other functions in the script refer to
    that. However, addPage() also needs to update the total page count
    variable, the database-line-number-index-variable and several others,
    which are all used in most other functions. It seems laborious and
    unnecessary to pass them all to each function, then have the function
    alter them and return an array that would then need to be deciphered and
    applied back to the main variables. So in such a case I let the function
    alter these "global" (though not v1) variables. You're saying that's okay.
    Yes, that is OK. It's not a good idea to call that scope "global," though, since you'll promote confusion. You could call it...outer function scope, maybe? Not sure; that assumes addPage() is nested within some other function whose scope is containing myMasterPage.
    It is definitely true that you should not individually pass them to the function and return them as an array and reassign them to the outer function's variables.
    I think it is OK for addPage() to change them, yes.
    Another approach would be something like:
    (function() {
      var MPstate = {
        totalPages: 0,
        dbline: -1
      function addPage(state) {
        state.totalPages++;
        state.dbline=0;
        return state;
      MPstate = addPage(MPstate);
    I don't think this is a particularly good approach, though. It is clunky and also doesn't permit an easy way for addPage() to return success or failure.
    Of course it could instead do something like:
        return { success: true, state: state };
      var returnVal = addPage(MPstate);
      if (returnVal.success) { MPstate = returnVal.state; }
    but that's not very comforting either. Letting addPage() access it's parent functions variables works much much better, as you surmised.
    However, the down-side is that intuitively I feel this makes the script
    more "messy" -- less legible and professional. (On the other hand, I
    recall reading that passing a lot of variables to functions comes with a
    performance penalty.)
    I think that as long as you sufficiently clearly comment your code it is fine.
    Remember this sort of thing is part-and-parcel for a language that has classes and method functions inside those classes (e.g. Java, Python, ActionScript3, C++, etc.). It's totally reasonable for a class to define a bunch of variables that are scoped to that class and then implement a bunch of methods to modify those class variables. You should not sweat it.
    Passing lots of variables to functions does not incur any meaningful performance penalty at the level you should be worrying about. Premature optimization is almost always a bad idea. On the other hand, you should avoid doing so for a different reason -- it is hard to read and confusing to remember when the number of arguments to something is more than three or so. For instance, compare:
    addPage("iv", 3, "The rain in spain", 4, loremIpsumText);
    addPage({ name: "iv", insertAfter: 3, headingText: "The rain in spain",
      numberColumns: 4, bodyText: loremIpsumText});
    The latter is more verbose, but immensely more readable. And the order of parameters no longer matters.
    You should, in general, use Objects in this way when the number of parameters exceeds about three.
    I knew a function could return an array. I'll have to read up on it
    returing an object. (I mean, I guess I intuitively knew that too -- I'm
    sure I've had functions return textFrames or what-have-you),
    Remember that in Javascript, when we say Object we mean something like an associative array or dictionary in other languages. An arbitrary set of name/value pairs. This is confusing because it also means other kinds of objects, like DOM objects (textFrames, etc.), which are technically Javascript Objects too, because everything inherits from Object.prototype. But...that's not what I mean.
    So yes, read up on Objects. They are incredibly handy.

  • Cfm template updating cfc variable scope

    Don't know if anybody's run into this before, but I ran into a strange issue with the variable scope in a cfc.  Basically, I have some application settings stored in a database table, and then I have a cfc saved to application scope in which I store the contents of the table in a variable scope query.  Within the cfc, I have a getter function that preforms a query of queries to pull the data I need.  I then have an admin screen within the application to update the settings.
    This is (very generally) what my cfc looks like:
    <cfcomponent  name="settings.cfc">
         <cffunction name="init" returntype="settings">  
              <cfset setAppSettings() />  
              <cfreturn this />  
         </cffunction>  
         <cffunction name="setAppSettings">  
              <cfquery name="variables.qrySettings" datasource="#application.dsn#">  
                   SELECT *
                   FROM SETTINGS
              </cfquery>  
         </cffunction>  
         <cffunction name="getAppSettings" returntype="query">  
              <cfargument name="id" />
              <cfset var local = structNew() />  
              <cfquery name="local.qryResult" dbtype="query">  
                   SELECT *
                   FROM variables.qrySettings
                   WHERE ID = <cfqueryparam value="#arguments.id#" cfsqltype="cf_sql_numeric" />  
              </cfquery>  
              <cfreturn local.qryResult />  
         </cffunction>  
    </cfcomponent>
    In onApplicationStart in Application.cfc, I have this line:
    <cfset  
    application.objSettings = createObject("component","settings").init() />

    Sorry, accidentally posted before I was done...
    Basically, the problem is that I have an admin screen that updates the settings.  I call the getter function in a cfm template, and I save the result to a variable called variables.qrySettings (same name as in the cfc) like this - <cfset variables.qrySettings = application.objSettings.getAppSettings(url.id) />.  For some reason, this seems to overwrite variables.qrySettings in the cfc.  Any ideas????

  • Why local variables are stored on stack?

    Hi,
    Can anyone tell why local variables are stored on stack and objects on heap?
    Thanks
    Neha

    paulcw wrote:
    I'm pretty sure that Java doesn't store any objects on the stack.I wouldn't be so sure if I were you.
    Why wouldn't Java be open to possible optimizations? It's definately faster to keep an object on the stack than letting it go through the garbage collector.
    In fact the Java compiler from Sun has had this optimization in the pipeline for a long time. I'm sure it's due "anytime soon" now.
    So it's wrong to say that objects are always stored on the heap. They can be store on the stack if it can be proved that their lifetime is limited to that of a method call. This requires the compiler to perform a so called "escape analysis" which has been in place for a long time in Sun compilers.
    If you want to learn more, Google for "escape analysis".

  • Why prefix variables names with a colon?

    PROCEDURE calc_avg_sales
    BEGIN
    :sales.avg := :sales.month1 / :sales.total;
    EXCEPTION WHEN ZERO_DIVIDE THEN
    :sales_avg := 0;
    RAISE FORM_TRIGGER_FAILURE;
    WHEN OTHERS THEN NULL;
    END;
    Excerpt from Oracle PL/SQL Programming ISBN 0-596-00381-1 Pg. 106
    Why are the variable :sales.avg, :sales.month1, and, :sales.total not declared in the above snippet? Is it presumed that they have been? Why is a : (colon) placed in front of the variables?
    Why would you think that FORM_TRIGGER_FAILURE is raised rather than ZERO_DIVIDE?
    Within my production environment I have noticed that error messages are sometimes vague to the user and for the technical user, and, would like to make use of an error table which would help technical support troubleshoot the cause of the error, without giving unnecessary details to the end user. Ideally this would include details of the Java Exceptions raised (usually large stacks) within applications that form part of the software architecture. How would you go about using an error handling mechanism?
    Edited by: Jon80 on Jun 24, 2012 2:02 PM

    Hi,
    Jon80 wrote:
    PROCEDURE calc_avg_sales
    BEGIN
    :sales.avg := :sales.month1 / :sales.total;
    EXCEPTION WHEN ZERO DIVIDE THEN
    :sales_avg := 0;
    RAISE FORM_TRIGGER_FAILURE;
    WHEN OTHERS THEN NULL;
    END;
    Excerpt from Oracle PL/SQL Programming ISBN 0-596-00381-1 Pg. 106
    Why are the variable :sales.avg, :sales.month1, and, :sales.total not declared in the above snippet? Is it presumed that they have been? Why is a : (colon) placed in front of the variables?Variables that start with a colon act like global variables; they can be defined in a larger scope. The colon helps the compiler identify them as not necessarily being defined in the unit being compiled.
    Why would you think that FORM_TRIGGER_FAILURE is raised rather than ZERO_DIVIDE?Actually, I would expect PLS-00103 Encountered the symbol "DIVIDE" when expecting one of the following ..., because you have a space (ZERO DIVIDE) instead of an underscore (ZERO_DIVIDE). Cut and paste actual code when posting here.
    If you correct that, then ZERO_DIVIDE is raised in the procedure. An EXCEPTION handler keeps some errors that occur at run-time from being reported to the caller. In this case, the EXCEPTION handler is saying "Don't report ZERO_DIVIDE as an error. Instead, do this ...". In this example, part of what it is doing instead is raising a different error, and that's the only error that is reported to the caller.
    By the way, "WHEN OTHERS THEN NULL" is almost always a very bad thing to say.
    Within my production environment I have noticed that error messages are sometimes vague to the user and for the technical user, and, would like to make use of an error table which would help technical support troubleshoot the cause of the error, without giving unnecessary details to the end user. Ideally this would include details of the Java Exceptions raised (usually large stacks) within applications that form part of the software architecture. How would you go about using an error handling mechanism?One thing Oracle often does is print short, vague error messages on the screen, but write long, detailed messages in trace files on the database server. Programmers are instructed to look for a trace file when they see certain error messages. You might do something similar. Instead of (or in addition to) writing trace files, you could insert rows into an error-logging table.

  • Variable Scope??

    Hi guys I have this code public class TreeDraw extends JComponent {
        public Vector<NodeComponent> nodeComponents = new Vector<NodeComponent>();
        public Vector<EdgeComponent> edgeComponents = new Vector<EdgeComponent>();
        @Override
        public void paintComponent(Graphics g) {
            Graphics2D g2 = (Graphics2D) g;
        public void paintNode() {
            for (int i = 0; i < nodeComponents.size(); i++) {
                nodeComponents.elementAt(i).draw(g2);
        public void paintEdge() {
            for (int i = 0; i < edgeComponents.size(); i++) {
                edgeComponents.elementAt(i).draw(g2);
    }But I dont know why in my two methods paintEdge & paintNode when I say draw(g2) it cannot find the variable g2 ??
    Any hints as to why it is out of scope and what I could do to put it into scope? Sorry dealing with a noob!
    Cheers

    Sorry guys thanks but i just solved it duhh :S!!

  • Variable scope with loaded external SWF's?

    I’ve got an SWF, call it calcLite, that will be deployed both independently (ie: attached to an HTML doc) and also imported at run time (linked as an external asset via the loader class) to another SWF, let’s call it calcPro. That part is working fine.
    I’ve got a global variable, gRunMode:String that calcLite must declare and set when it’s running independently, but must inherit when attached to calcPro (which will declare and set gRunMode before attaching calcLite).
    Here’s where I am:
    At the root of calcPro:
    var gRunMode:String = “touchScreen”;
    At the root of calcLite:
    var gRunMode:String = “web”
    if (this.parent == this.stage) {
         gRunMode = MovieClip(this.parent.parent.parent).gRunMode;
    I’ve also tried creating function in the parent to return gRunMode:
    At the root of calcPro:
    var gRunMode:String = “touchScreen”;
    function getRunMode():String {
         return gRunMode;
    At the root of calcLite:
    var gRunMode:String = “web”
    if (this.parent == this.stage) {
         gRunMode = MovieClip(this.parent.parent.parent). getRunMode();
    I’ve also tried the second technique, renaming the global in calcPro to gRunModeExe incase there was a naming violation. In all cases I get “attempt to access prop of a null” error. The construct MovieClip(this.parent.parent.parent).function() works, I use it later in the program for a different function and it’s fine, just doesn’t work here.

    My bad, I wrote the post from memory at home. My actual code properly tested the stage (!=) and would have worked EXCEPT under the following condition:
    This is my second project in a row that involved an SWF that must operate independently and also function as a loaded child to a bigger project. What I keep forgetting is that loaded content begins to execute IMMEDIATELY!!!, it does not wait to be attached to the stage. Further, loaded content does not have access to stage assets until it’s been attached, so any premature attempts to access global variables and functions from loaded clip to stage fail. A good explanation of these issues can be found here (scroll to middle of page, post by senocular titled Access to stage and root): http://www.kirupa.com/forum/showthread.php?p=1955201
    The solution was simple enough. If calcLite is running as a child, stop in frame 1 (before any other processing) and wait for calcPro to push us to the next frame (which happens after attachment to the stage). If calcLite is running independently skip the stop and proceed as normal.
    As for this.parent.parent.parent vs. this.parent.parent vs this.parent, since gRunMode is global within the calcPro scope any of these would probably work (although I’ve only tested the first option). The first parent references the loader object, the second parent references the movie clip to which the loader object is attached, and the third parent finally references root.

  • Having Truble Reading and Echoing Using PHP in HTML. Possible Variable Scope Problem?

    Hey guys,
       Thanks for your always knowledgable help! Today I am working with displaying text from a text file in an HTML table using PHP. I can't get the data to display properly, I think it has something to do with the scope of the variables, but I am not sure. Here is the code I am struggeling with:
    <table width="357" border="1" cellspacing="0" cellpadding="0">
      <tr>
        <td width="165">Pizza 1</td>
        <td width="186"><? echo  $price['0']; ?></td>
      </tr>
      <tr>
        <td>Burger 1</td>
        <td><? echo $price['1']; ?></td>
      </tr>
      <tr>
        <td>Drink 1</td>
        <td><? echo $price['2']; ?></td>
      </tr>
    </table>
    In the above PHP (not shown) the array $price is filled properly (I tested by echoing each bit line by line) but by the time we get into the HTML it seems the array is empty or it is not liking how I am calling it. Does the scope of a PHP variable end with the closing "?>" tag? Am I missing something? Bellow is the full code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    body {
        background-color: #333;
        color: #FFF;
    </style>
    </head>
    <body>
    <?php
    $menu=fopen("prices.txt","r") or exit("Unable to open file!");
    $price=array();
    $priceposition=null;
    $tempstring;
    //This loop does all of the READING and populating of variables
    while(!feof($menu))
        //Check to see if this is the first pass, if not add one to the array possition
        if ($priceposition==null){
            $priceposition=0;
        else{
        $priceposition++;
        //populate the temparary string
        $tempstring = fgets($menu);
        //Populate the array if the temporary string is not a comment
        if(substr($tempstring,0,2) != "//"){
            $price['$priceposition']= $tempstring;
            echo $price['$priceposition'];
      //End of reading loop
    fclose($menu);
    ?>
    <table width="357" border="1" cellspacing="0" cellpadding="0">
      <tr>
        <td width="165">Pizza 1</td>
        <td width="186"><? echo  $price['0']; ?></td>
      </tr>
      <tr>
        <td>Burger 1</td>
        <td><? echo $price['1']; ?></td>
      </tr>
      <tr>
        <td>Drink 1</td>
        <td><? echo $price['2']; ?></td>
      </tr>
    </table>
    </body>
    </html>
    and you can run the code on my test server here: christianstest.info/phptest/readwritetesting/readtest.php
    thanks guys!

    MurraySummers wrote:
    Try changing this -
    fclose($menu);
    to this -
    fclose($menu);
    echo "<pre>";exit(print_r($price));
    and see what you get.
    Wow, what a great little peice of testing code, thanks! That showed me the problem right away! Is there any way to test your php line by line in Dreamweaver CS6? I am used to computer programing in Visual Studio and Eclipse where they have an option of running code line by line and seing how variables populate and change with each line of code execution. Or is thier a program that can do this for PHP?

  • Variable scope in plsql package

    When I run the following package, proc2 is always printing the value of i = 1 even though proc1 is incrementing the value of i correctly? Could any one explain to me what is the problem with this code?
    CREATE OR REPLACE PACKAGE test_pkg
    is
    PROCEDURE proc1 (p_fetch_limit in number := 200);
    PROCEDURE proc2 (rec_id out number);
    END test_pkg;
    CREATE OR REPLACE PACKAGE BODY test_pkg
    IS
    cursor test_cur
    IS
    select new_app,
    card_number,
    process_flag,
    process_date,
    seq_number
    from wm_opt_scan_temp
    where process_flag = 'N' and process_date IS null
    and new_app = 'Y'
    order by seq_number;
    type test_cur_type IS table of test_cur%rowtype;
    cur_rec test_cur_type;
    i number := 1;
    l_rec_id number := 0;
    -- PROC1 --
    PROCEDURE proc1 (p_fetch_limit in number := 200)
    IS
    BEGIN
    open test_cur;
    loop
    fetch test_cur bulk collect into cur_rec limit p_fetch_limit;
    exit WHEN cur_rec.count = 0;
    for i in 1..cur_rec.count
    loop
    DBMS_OUTPUT.put_line('proc1 - i<'||i||'> seq#<'||cur_rec(i).seq_number||'> card#<'||cur_rec(i).card_number||'>');
    l_rec_id := 0;
    proc2(l_rec_id);
    END loop;
    END loop;
    CLOSE test_cur;
    COMMIT;
    DBMS_OUTPUT.put_line('proc1 procedure finished...');
    END proc1;
    -- PROC2 --
    PROCEDURE proc2 (rec_id out number)
    IS
    BEGIN
    DBMS_OUTPUT.put_line('proc2 started - i<'||i||'> seq#<'||cur_rec(i).seq_number||'> card#<'||cur_rec(i).card_number||'>');
    END proc2;
    END test_pkg;
    output is:
    Connecting to the database Test.
    proc1 - i<1> seq#<7841> card#<40992814376>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<2> seq#<8041> card#<40992779256>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<3> seq#<8241> card#<40992745696>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<4> seq#<12681> card#<40992814376>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<5> seq#<12682> card#<40992814375>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<6> seq#<12683> card#<40992814378>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<7> seq#<12684> card#<40992814379>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<8> seq#<12685> card#<40992745756>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<9> seq#<12686> card#<40992745757>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<10> seq#<12689> card#<40992814377>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<11> seq#<12690> card#<40992745755>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<12> seq#<12691> card#<40992745767>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<13> seq#<12692> card#<40992745771>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<14> seq#<12693> card#<40992745612>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<15> seq#<12694> card#<40992145673>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<16> seq#<12695> card#<40992745611>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<17> seq#<12697> card#<40992745661>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<18> seq#<12698> card#<40992745689>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<19> seq#<12700> card#<40992745771>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 procedure finished...
    Process exited.
    Disconnecting from the database Test.

    Assign it to a separate global variable, and don't name it "i" so that the global variable is visible within the for loop.
    As for Java, consider the following:
    public class Foo {
    private int i;
    public void proc1() {
    for (int i=0;i<10;i++) {
    // do stuff
    public void proc2() {
    System.out.println("i = "+i);
    Same problem: two variables in different scopes, both named "i".

  • Variable scope within an interface and some questions

    I am creating a DataStorage interface with a member variable (can I call it a member variable when it is in an interface?) called dataObject. From what I remember, and what the compiler is telling me, the scope declarations "private," or "protected" can not be used on either methods or member variables in an interface.
    Now I have another class DataInput that implements DataStorage and I want to make the dataObject private and put in accessor methods to get to the dataObject. But I also remember reading something that said, during inheritance you can not make the scope of the method (and variable?) more narrow. Meaning if a method was defined as default in the parent class, the subclass can not override that method to give it private access all of a sudden.
    Now a couple of questions with this...does that rule only apply to subclassing (that is with extends) or does it also apply to implementing interfaces. Second question, I am pretty sure that rule applies to methods that are being overriden, but does it also apply to variables in an interface...because if that is the case, I can't re-declare the variable in the class that implements the interface to be private...and then there is no way to protect that variable.
    By the way I did re-declare the variable in the subclass (implementing class) and declared it as a private, and it works...but I'm still trying to figure out the general rule.

    well if the interface variables are implicitly public static final, how come I am able to re-declare the variable name within the class that implemented the interface.
    If for example in interface Car there is a variable color, how come in class Honda implements Car, I can redeclare the variable color, and give it public access. I thought final meant final, no redeclaring...but does that not hold for static variables?

  • Question about variable scope

    Suppose theres a class that mixes colors.
    It has an constructor and two methods:
    public class ColorMix {
    //This is just an example but I've tried this and colors
    mix and show up correctly.
    public ColorMix() {
    cmColor = MixColors();
    } //e_constr
    private void mixColors() {
    //do something
    Color1 = createColors();
    Color2 = createColors();
    //etc
    private Color createColors() {
    //create some color-values
    //r, g and b ...
    Color anColor = new Color (r, g, b) //finally create color
    return anColor; //and return that color
    public Color cmColor;
    } // e_class_ColorMix
    My question is: Howcome and how the variable
    'anColor' is referred from the createColors-method to
    the mixColors-method?!? I thought that anColor would
    be out of scope, since its created in the createColors
    I've understood it would be erased once createColors
    is done with?!?
    Or did MixColors make it to the 'anColor' before garbage
    collector?
    Thanks,
    Jani

    I think you are mixing up variables and objects. A variable (like "anColor" in your example) is not the same as an object. A variable is just a reference to an object that exists somewhere in memory.
    Objects are eligible for garbage collection if the running program does not hold any reference to the object anymore.
    Your createColors() method creates a new object of type Color and stores a reference to it in the variable anColor. Then it returns the value of the variable (which is the reference to the Color object) to the calling method: mixColors. There you have another variable (Color1) which will hold the reference to the object.
    So the variable anColor goes out of scope at the end of method createColors(), but the program still has a reference to the object, stored in variable Color1.
    The object is still referenced by the program and will therefore not be garbage collected.
    I'd suggest you read the Java Tutorial: http://java.sun.com/docs/books/tutorial/java/index.html
    Jesper

  • Variable Scope in OSB Proxy Services

    Hi,
            I want to understand the visibility (scope) of the variables that are created in the request pipe line and response pipe line . for example ,  can we access the variable in response pipe that we have created in request pipe line.
    Thank n regards
    Guru...

    Hi guru,
    in case of OSB the variables that we have declared are always global ,because the variables that we are declared either inside the request or response pipelines [or]  inside the pipeline pair  are avilable for entire proxy[means you can use any where in the proxy  even in outer error handler stage also .]
    but yes we can declare local and global variables in OSB in case of Split joins.
    thanks
    bala

  • Variable scope & memory allocation.

    Traditional wisdom normally says keep variables in the smalled scope you can (or atlest I think it does, feel free to correct me if I'm wrong from the offset).
    However memory allocation on J2ME is going to be slow. So...
              int noRects = readCard32();
              int pixel = readCard8();
              drawOnMe.draw( (pixel >>0 &7) * 36, (pixel >>3 &7) * 36,
                          (pixel >>6 &3) * 85, mx, my, w, h );
              for( int r = 0; r<noRects; r++ ) {
                  pixel = readCard8();
                  int lx = readCard8();
                  int ly = readCard8();
                  int lw = readCard8();
                  int lh = readCard8();
                  drawOnMe.draw( (pixel >>0 &7) * 36, (pixel >>3 &7) * 36,
                           (pixel >>6 &3) * 85, mx + lx, my + ly,
                           lw, lh );            
    // or
              int noRects = readCard32();
              int pixel = readCard8();
              drawOnMe.draw( (pixel >>0 &7) * 36, (pixel >>3 &7) * 36,
                          (pixel >>6 &3) * 85, mx, my, w, h );
              int lx;
              int ly;
              int lw;
              int lh;
              for( int r = 0; r<noRects; r++ ) { /* ... */ }Mike

    And as far as the difference - even though I'm not sure there is a performance increase, I'm sure that declaring them outside has no negative effects so I do it just in case.
    Plus, I remember reading somewhere that Java had some optimized access support for the first 4 (I think it's 4, and I think it also include the parameters) locals declared in a function, some kind of "fast register" thingie - so in functions that have tight inner loops I always declare the most "accessed" variables right at the top of the function. I don't know how much this holds true for KVMs, but again, it can't hurt.
    shmoove

Maybe you are looking for

  • Initial load of custom table from r3

    Hello all, I am pretty much new to crm, with the documentation i had i was able to create a site for my r3 system in crm. Initially i created a z table in my r3 system and crm system. i loaded some data into r3 ztable. i just want to replicate the da

  • Keep the styles drawer open in Pages 5?

    I searched a bit and didn't see anything on it. Please forgive if this has been answered. Is there a way to keep the styles drawer open as in previous versions? My workflow is to type in everything I want - as in a screenplay - and then use the arrow

  • 10053 - no trace file generated

    Hi, no 10053 trace file is generated in the diag directory. sql_trace = true trace_enabled = true i set ALTER SESSION SET TRACEFILE_IDENTIFIER = 'TEST'; ALTER SESSION SET EVENTS='10053 trace name context forever, level 1'; but there is no trace file

  • Error message of "404 - page not found" after downloading and installing Firefox 15

    Error message of "404 page not found" after downloading the latest version of Firefox.

  • Ascertain version of Oracle Home

    Hi I'm carrying out an audit of our Linux/Solaris Oracle estate and need a quick way to find out what version of the sofware is running in each Oracle Home. We have database and app server installations. OPatch is available on a small percentage of s