Accessing static variables

class Array{
static int m = 10; // how to access this variable in main()?
public static void main(String [] args) {
int m = 45;
System.out.print(m );
return ;
}

One problem is you are doing stuff in main that should not be done in main.
Main is always only for kicking a program off and ensuring it cleans up nice when done, that is it. Sooner you figure this out and get into good habits the better.
Second, you have two m variables, which one do expect to get accessed? But still, getting out of main before doing your computations will make your problem much easier to see and fix, so do that first.
JSG

Similar Messages

  • Why Inner class cannot access static variables

    Why is it that inner class can use only static final variables of the outerclass, and not ordinary static variables of the outer class. "Yes the JLS sepcifies that only final static variables can be used inside an inner class, esp a non blank final variable". But why this restriction.
    Thanks.

    so what are final static variables treated as if they
    are not variables. So if the final static value is
    not loaded when the class is loaded how will the
    class know about the value.??The actual value wil be substituted for the name of a static final value at compile time. That's why you can use them in switch statements where you can't use any variable variable.
    This is something to watch out for, by the way, because if you use a public static final value from one class in another the actual value will be compiled into the using class, so if you change the value where it's defined the class using it will have the old value until it's recompiled.

  • Slow performance when multiple threads access static variable

    Originally, I was trying to keep track of the number of function calls for a specific function that was called across many threads. I initially implemented this by incrementing a static variable, and noticed some pretty horrible performance. Does anyone have an ideas?
    (I know this code is "incorrect" since increments are not atomic, even with a volatile keyword)
    Essentially, I'm running two threads that try to increment a variable a billion times each. The first time through, they increment a shared static variable. As expected, the result is wrong 1339999601 instead of 2 billion, but the funny thing is it takes about 14 seconds. Now, the second time through, they increment a local variable and add it to the static variable at the end. This runs correctly (assuming the final increment doesn't interleave which is highly unprobable) and runs in about a second.
    Why the performance hit? I'm not even using volatile (just for refernce if I make the variable volatile runtime hits about 30 seconds)
    Again I realize this code is incorrect, this is purely an interesting side-expirement.
    package gui;
    public class SlowExample implements Runnable
         public static void main(String[] args)
              SlowExample se1 = new SlowExample(1, true);
              SlowExample se2 = new SlowExample(2, true);
              Thread t1 = new Thread(se1);
              Thread t2 = new Thread(se2);
              try
                   long time = System.nanoTime();
                   t1.start();
                   t2.start();
                   t1.join();
                   t2.join();
                   time = System.nanoTime() - time;
                   System.out.println(count + " - " + time/1000000000.0);
                   Thread.sleep(100);
              catch (InterruptedException e)
                   e.printStackTrace();
              count = 0;
              se1 = new SlowExample(1, false);
              se2 = new SlowExample(2, false);
              t1 = new Thread(se1);
              t2 = new Thread(se2);
              try
                   long time = System.nanoTime();
                   t1.start();
                   t2.start();
                   t1.join();
                   t2.join();
                   time = System.nanoTime() - time;
                   System.out.println(count + " - " + time/1000000000.0);
              catch (InterruptedException e)
                   e.printStackTrace();
               * Results:
               * 1339999601 - 14.25520115
               * 2000000000 - 1.102497384
         private static int count = 0;
         public int ID;
         boolean loopType;
         public SlowExample(int ID, boolean loopType)
              this.ID = ID;
              this.loopType = loopType;
         public void run()
              if (loopType)
                   //billion times
                   for (int a=0;a<1000000000;a++)
                        count++;
              else
                   int count1 = 0;
                   //billion times
                   for (int a=0;a<1000000000;a++)
                        count1++;
                   count += count1;
    }

    Peter__Lawrey wrote:
    Your computer has different types of memory
    - registers
    - level 1 cache
    - level 2 cache
    - main memory.
    - non CPU local main memory (if you have multiple CPUs with their own memory banks)
    These memory types have different speeds. Depending on how you use a variable affects which memory it is placed in.Plus you have the hotspot compiler kicking in sometime during the run. In other words for some time the VM is interpreting the code and then all of a sudden its compiled and executing the code compiled. Reliable micro benchmarking in java is not easy. See [Robust Java benchmarking, Part 1: Issues|http://www.ibm.com/developerworks/java/library/j-benchmark1.html]

  • How to access static variable from a Thread class

    Kindly help me.......
    here's the code.....
    class Thread1 extends Thread
    int j=0;
    myClass2 mc = new myClass2();
         public void run()
              for( int a=0;a<6;a++)
                        {try
                             { Thread.sleep(5000);
                             catch(Exception e){System.out.println("Interrupted Exception");}
                             j++;
    mc.change1(i);
    } System.out.println("Thread1 executes "+j+" times");
    class Thread2 extends Thread
    int k=0;
         myClass2 mc1 = new myClass2();
         public void run()
              for( int a=0;a<6;a++)
                        {try
                             { Thread.sleep(5000);
                             catch(Exception e){System.out.println("Interrupted Exception");}
                             k++;
    mc1.change2(i);
    }System.out.println("Thread2 executes "+k+" times");
    class myClass2
    static int i=5;
    public synchronized void change1(int s)
    s=6;
    System.out.println("New value of i:"+s);
    public synchronized void change2(int s)
    s=7;
    System.out.println("New value of i:"+s);
         public static void main(String args[])
    Thread1 b1 = new Thread1();
    Thread2 b2 = new Thread2();
         b1.start();
    b2.start();
    I am unable to pass the variable i in my method call in Thread1: mc.change1(i); and similarly in Thread2:mc.change2(i);

    You can declare your i variable in myClass2 as public static and then simply call there
        mc.change1( myClass2.i ) ;

  • Accessing static variable using GWT remote servlet

    Hi all,
    Using GWT, I'm trying to call two methods which exist in a
    RemoteService from my entrypoint class.
    I have two methods within my remoteService servlet, method A and
    method B.
    Method A returns an int and sets an arraylist.
    Method B returns the arraylist, myList.
    I'm assuming that a single callback is associated with a single
    servlet method? Is it possible to access the arraylist, which has been
    set from calling method A, using the callback?
    e.g.
    //client code:
                   MyServiceAsync myService = (MyServiceAsync)
    GWT.create(MyService.class);
                   AsyncCallback callback = new AsyncCallback(){
                      public void onSuccess(Object result) {
                      public void onFailure(Throwable caught) {
                  myService.foo(callback);
    // servlet code
    public class MyServiceImpl extends RemoteServiceServlet implements
    MyService{
           public static List myList = new ArrayList();
           public int A(){
                   setB();
                   return 10;
           public void setB(){
                   // this adds five elements to a static arraylist, myList
           public List getB(){
                   return myList;
    }

    Ok, frist solution (the better one) is that You can create a class that will both contain the int and the list. E.g.
    public class MyObject implements Serializable {
    private int value;
    private List<Object> list;
    //getters and settersThen You can set the values You're interested in the RemotServiceServlet and simply return this object - aync callbacks can return various types of objects (not only primitives) but under two conditions:
    1) The object must implement the Serializable interface
    2) The object must have public no argument constructor or no constructor at all.
    Then in your client class You'll have:
    MyServiceAsync myService = (MyServiceAsync) GWT.create(MyService.class);
    AsyncCallback<MyObject> callback = new AsyncCallback<MyObject>(){
    public void onSuccess(MyObject result) {
      result.getList();
      result.getInt();
    public void onFailure(Throwable caught) {
    myService.A(callback);
    };The second solution is to invoke a method B callback in the result of A's callback:
    MyServiceAsync myService = (MyServiceAsync) GWT.create(MyService.class);
    AsyncCallback aCallback = new AsyncCallback(){
    public void onSuccess(Object result) {
       //here You get the in value
       AsyncCallback bCallback = new AsyncCallback(){
        public void onSuccess(Object result) {
         //here You get the list
        public void onFailure(Throwable caught) {
        myService.B(bCallback);
    public void onFailure(Throwable caught) {
    myService.A(aCallback);Hope this is clear and will help You. (Remember also the use generics!)

  • Accessing static variable from subclass

    Hi,
    this question is probably fairly common but I can't seem to find the answer around: Can somebody please explain the rationale behind the following behavior ?
    public abstract class SuperClass {
        static String mess;
    public class SubClass extends SuperClass {
        static {
            mess = "Hello world!";
        static String getMess() {
            return mess;
    public class mymain {
        public static final void main(String[] args) {
            System.out.println(SubClass.getMess());
    }gives "Hello world!" as expected whereas
    public abstract class SuperClass {
        static String mess;
        static String getMess() {
            return mess;
    public class SubClass extends SuperClass {
        static {
            mess = "Hello world!";
    public class mymain {
        public static final void main(String[] args) {
            System.out.println(SubClass.getMess());
    }gives "null". It looks like the initialization block is not executed. Why?
    Thanks for your insight,
    Chris

    >
    You're essentially claiming you need to override some static methods.No, there is indeed misunderstanding here. What I need to do is implement the methods with the signature given, I'm not overriding existing methods, in fact I'm not even deriving from any existing class. I only have to create the entry points in my code as defined, then publish them to the DB, and Oracle is going to use them (I think they can be called callbacks, also again not 100% sure).
    Then it happens that in my particular case it's natural to have a master containing all the code and then subclasses that only define a few specific parameters that are to be used by the static (and instance) methods. Hence the final design. Currently my code looks like the following and seems to work (fingers crossed):
    class ParseFileCLL extends ParseFile {
        // Name of the row type.
        private final static String rowType = "CLLROW";
        // Here I initialize static fields of the ParseFile master class.
        static {
            fileType = "CLL";
            fileStruct = new FileStruct(34);
        // Type methods implementing ODCITable interface.
        static public BigDecimal ODCITablePrepare(STRUCT[] sctx, STRUCT tfinfo, String sysName)
                throws SQLException {
            // prepareContext is a static helper method defined in the master class.
            return prepareContext(funcType, rowType, rowSetType, tfinfo);
    // Other ODCI methods are only accessed directly in the master class, NOT in the subclass. Or else... WEIRD BUGS!
    // In other words:
    //  publish ParseFile.ODCITableStart() -> ok
    //  publish ParseFileCLL.ODCITableStart() -> crash
    }Not surprising. Java has plenty of undefined or inconsistently-defined behavior. The JLS is by no means perfect.
    >
    Well I kind of admire your composure about this, but it seems to me that if it's indeed the case, the meaning of it would be that the code could work in JVM 1.5.0.15 and not in 1.5.0.16, or worse run ok on Windows and not on Linux, which is if I understand correctly precisely the kind of behavior that Java was meant to cure, at least at its inception.
    I think there might be other elements to the story though.
    Thanks,
    Chris

  • Static variable/method

    Hi!!
    need help here..how can i access static variable and methods
    in a class?
    tnx.

    tnx for the reply..I want to access the treeData under the
    hierarchicalCollectionView property of advanceDatagrid.
    what i did is
    private var myGrid:AdvancedDataGrid = new AdvancedDataGrid();
    myGrid.hierarchicalCollectionView.treeData;
    and i got this error
    1119: Access of possibly undefined property treeData through
    a reference with static type
    mx.collections:IHierarchicalCollectionView. advancedgrid/src
    well!! im sure treeData is existing i run debug and its
    there. So it came up that it might be a static variable of method.
    I tried to do some experiments and i found out static methods and
    variables are not accessible outside the class.
    tnx.

  • Non-static variable cant accessed from the static context..your suggestion

    Once again stuck in my own thinking, As per my knowledge there is a general error in java.
    i.e. 'Non-static variable cant accessed from static context....'
    Now the thing is that, When we are declaring any variables(non-static) and trying to access it within the same method, Its working perfectly fine.
    i.e.
    public class trial{
    ���������� public static void main(String ar[]){      ////static context
    ������������ int counter=0; ///Non static variable
    ������������ for(;counter<10;) {
    �������������� counter++;
    �������������� System.out.println("Value of counter = " + counter) ; ///working fine
    �������������� }
    ���������� }
    Now the question is that if we are trying to declare a variable out-side the method (Non-static) , Then we defenately face the error' Non-static varialble can't accessed from the static context', BUT here within the static context we declared the non-static variable and accessed it perfectly.
    Please give your valuable suggestions.
    Thanks,
    Jeff

    Once again stuck in my own thinking, As per my
    knowledge there is a general error in java.
    i.e. 'Non-static variable cant accessed from static
    context....'
    Now the thing is that, When we are declaring any
    variables(non-static) and trying to access it within
    the same method, Its working perfectly fine.
    i.e.
    public class trial{
    ���������� public static void
    main(String ar[]){      ////static context
    ������������ int counter=0; ///Non
    static variable
    ������������ for(;counter<10;) {
    �������������� counter++;
    ��������������
    System.out.println("Value
    of counter = " + counter) ; ///working fine
    �������������� }
    ���������� }
    w the question is that if we are trying to declare a
    variable out-side the method (Non-static) , Then we
    defenately face the error' Non-static varialble can't
    accessed from the static context', BUT here within
    the static context we declared the non-static
    variable and accessed it perfectly.
    Please give your valuable suggestions.
    Thanks,
    JeffHi,
    You are declaring a variable inside a static method,
    that means you are opening a static scope... i.e. static block internally...
    whatever the variable you declare inside a static block... will be static by default, even if you didn't add static while declaring...
    But if you put ... it will be considered as redundant by compiler.
    More over, static context does not get "this" pointer...
    that's the reason we refer to any non-static variables declared outside of any methods... by creating an object... this gives "this" pointer to static method controller.

  • Concurrent access to a static variable

    I think that I need a static lock to protect a static variable. However, the code below seems to be running fine on a 24-CPU machine.
    public class test {
    public static void main(String[] args)
      new Thread(new myclass()).start();
      new Thread(new myclass()).start();
    class myclass implements Runnable {
    private static int msgid;
    private Object lock = new Object();
    public void run()
       synchronized(lock) {
       int i=200000;
       while(i-- >0) {
       msgid = msgid+1;
       System.out.println("Thread " + Thread.currentThread().getName() + "value => "
    + msgid);
    }This testcode is roughly based on my actual program. I have a code (written by someone else) which protects the static msgid with an instance-level lock. IMHO , this shouldn't stop the multithreaded access to the msgId because two threads will have two different instances of the lock. However, I can't reproduce this on a 24-CPU machine. I know the MT-related bugs are hard to reproduce. So I just thought of confirming it with the experts. In my opinion, lock object should be :
    private static Object lock = new Object();
    Anyone against this thought?

    Yes I see the code and I can see the "msgid" can be updated by both threads randomly behaved as per CPU time slicing for each thread.
    like ThreadOne msgId-->10
    ThreadTwo msgId-->11
    ThreadTwo msgId--->12
    ThreadOne msgId -->13
    etc..
    What do you want to achieve if you use a common resource to lock in order to prevent the msgId to be incremented by two thread at the same time but rather by one thread at a time?
    Regards,
    Alan Mehio

  • Accessing substitution variables in static uploaded javascript file

    Hi there,
    I just created variables and a pageinit function in my page header and try to access these variables (Flow_Id, Page_Id etc) within a js-file I uploaded into workspace static files.
    I try to use them within an URL ( e.g. "f?p="+ Flow_Id + ":100:" + Session_Id ), but they are -undefined- and thus lead to a 404-Page!
    Here is the code:
    onload="pageinit()"             //in page html body attribute
    //and the following code in the html header
    <script type="text/javascript">
    <!--
    var Flow_Id; // application id
    var Page_Id; // page id
    var Session_Id; // session id
    var Request; // request value
    function pageinit(){
    Flow_Id = html_GetElement('pFlowId').value; // application id
    Page_Id = html_GetElement('pFlowStepId').value; // page id
    Session_Id = html_GetElement('pInstance').value; // session id
    Request = html_GetElement('pRequest').value; // request value
    //-->
    </script>Can someone please point me to the right direction!?
    Thank you very much.
    Regards
    Johnny

    Hi Paul,
    I tried with IE 8 now and could at least find out now, which lines of code are responsible for the error:
    addmenu(menu=[                    
    "mainmenu",                    
    69,                         
    153,                         
    1,                         
    style1,                         
    1,                         
    "left",                         
    1,                          
    0,                         
    ,"Home","f?p=" + $v('pFlowId') + ":100:" + $v('pInstance'),,"",1 // "Description Text", "URL", "Alternate URL", "Status", "Separator Bar"
    ,"Tab2","show-menu=list01","tab2.html","",1
    ,"Tab3","f?p=300:1:","tab3.html","",1
    ,"Tab4","show-menu=list04","tab4.html","",1
    ])It must be the way I try to create the first URL (for Home) I already mentioned, because if I hard-code the URL, it works without errors.
    I could hard-code the URL, but then I always get a new session-id. So, at least I need to find a way of accessing the current session-id here.
    As mentioned before, I also tried to set global variables within a javacript function in the page header and assigning the current values for the session and app-id and reference these variables within the js-file I uploaded to the static files. But that did not work either. These variables were undefined.
    I guess they were undefined because at the time when the function was processed the variable might not have been set yet.
    But I followed exactly the solution Carl Backstrom mentioned in some of his posts some years ago. God bless him.
    I am not a javascript expert, so maybe you got a hint for me!?
    Thanks again for your support.
    Johnny

  • Static variable access

    Hi everyone,
    Just a quick question:
    In the following piece of code, why does the compiler NOT complain about non-static methods accessing a static field?
    public class Plane {
       static String s = "-";
       public static void main (String[] args){
           new Plane().s1();
           System.out.println(s);
       void s1(){
           try{
               s2();
           catch(Exception e){
               s += "c";
       void s2() throws Exception{
           s3();
           s += "2";
           s3();
           s += "2b";
       void s3() throws Exception{
           throw new Exception();
    }

    Can anybody explain a little more about what happens
    when static classes are compiled, or point me in the
    direction of some reading material please?
    I would like to know the difference between static
    variables and standard variables at compile time. I
    am confused because I would have thought that if
    there is a declaration in the code then the compiler
    knows that that object will exist.
    ThanksWhen the class loader loads the class, that's when static instances are created and when static blocks of code are executed. A java Class is actually an Object like any other, so you can think of static variables as instance variables for the Class object, and static blocks of code are somewhat like constructors for the Class object (in the sense that the code is executed when the class is loaded by the class loader).
    Individual instances of the object share the class' static variables, but non-static variables are only available to the instances. So the class 'instance' (which was loaded by the class loader) can't access non-static variables because non-static variables don't exist until you create an instance of the class.

  • Loading the final static variables at run time.. Please help

    Hello, fellow developers & Gurus,
    Please help me figure out the best way to do this:
    I need to load all my constants at run time. These are the public static final instance variables. The variables values are in the DataBase. How do I go about loading them.

    Your original question was diffeent, but your further posts show what you really want to do:
    1) all constants in 1 class
    2) available readonly for other classes
    3) updatable during runtime by changing in the database
    Did I understand you right?
    Then smiths' approach solves point 2):
    Instead, make the variables available through a method
    call - that way you avoid the whole final variable
    versus read-only attributes problem.
    //GLOBAL VARIABLES EXPOSED AS PUBLIC PROPERTIES
    public final class GlobalProperties
    public static int getTableSize();
    public static int getRowSize();
    Each "constant" should be a private static variable, and these methods simply return their values.
    The variables are initialized in a static initializer by accessing the db. Ok.
    You habe a table with one row containing as columns all the constants.
    A method readConstants() does a "select constant1, constant2, ... from const_table" and sets all the variables.
    The static initializer calls this method.
    Right?
    Ok, then you simply call readConstants() everytime you want to synchronize with the actual content of const_table.
    Was it this?

  • Using Static Variable against Context Attribute for Holding IWDView

    Dear Friends,
    I have a method which is in another DC which has a parameter of the type IWDView. In my view, I will have an action which will call the method in another component by passing the value for the view parameter. Here, I can achieve this in 2 types. One is - I declare a static variable and assign the wdDoModifyView's view as parameter value and I can pass this variable as parameter whenever calling that method or the second way - create an attribute and assign the same wdDoModifyView's view parameter as its value. Whenever I call this method, I can pass this attribute as parameter. What is the difference between these two types of holding the value since I am storing the same value i.e., wdDoModifyView's view parameter. But when I trigger the action from different user sessions, the first type of code (using static variable) prints the same value in both the sessions for view.hashCode() and View.toString(), but the same is printing the different values when I pass the attribute which holds the view parameter.
    Clarification on this is highly appreciated
    The problem I face is when I use static variable to get the view instance and export the data using the UI element's id, the data belonging to different user sessions is mixed up where as when I use Context Attribute, the same problem doesn't arise. I want to know the reason why it is so. Is there any other place or way where I can get the current view instance of each session instead of wdDoModifyView?

    Hi Sujai ,
    As you have specified the problem that we face when we use  static attributes, when end users are using the application .
    Static means i  have n number of objects but the static variable value will remain same every where.
    when it is context attribute for every object i.e nth object you have a nth context attribute i mean nth copy of the context attribute.
    so every user has a unique Iview parameter , when context is used and
    when static is used  , assume you have userA , his iview is set this intially  and u have another user B , when he is using  , since the variable is static and when you access this variable you will get the value of userA.
    Regards
    Govardan Raj

  • Why can't I access the variables in my threads?

    hello.
    another question about threads..
    ==========================
    I have an inner class that implements Runnable (i.e. a thread) and has a variable in it. I want to be able to access that variable from outside the thread class so that I can set or retrieve the variable.
    here is the code for the program
    class myClass
         public static void main(String[] args)
              myClass c = new myClass();
         myClass()
              Thread t = new Thread(new myThread());
              t.number = 1;
              t.start();
         class myThread implements Runnable
              int number = 0;
              public void run()
         }//end myThread
    }//end myClassthe line
    t.number = 1;
    where I try to set the number variable to 1 gives me an error (in the MyClass constructor)
    This is my error
    AccessThreadVars.java:11: cannot find symbol
    symbol  : variable number
    location: class java.lang.Thread
              t.number = 1;
                        ^
    1 errorif I put a method in myThread, and then try to call that method from myClass (via t.MethodName()) it gives me that same error telling me it can't find it..
    what am I doing wrong? how can I get access my thread's variables and methods??

    1. Type names should start with an uppercase letter
    2. t is defined as a Thread, not as a myThread
    (which, may I insist, should be "MyThread"), so the
    compiler has no means of detecting that "number" is
    an accessible field of the object... which wouldn't be accessible anyway, cause you're trying to get attributes from your Runnable after wrapping it inside a Thread.
    Why don't you do something like :
    MyThread t = new MyThread();
    t.number = 1;
    new Thread(myThread).start();?
    I bet you don't use Thread's own methods anyway...

  • How to give different value to a static variable???

    Hi all:
    Is there any solution to set different values to a static variable???I had try two ways but all have errors!
    1.Way_1
    protected String tmp=null;
    protected void initSituation(int sayorpress)
    if (sayorpress==0)
    tmp = "string1";
    else if (sayorpress==1)
    tmp = "string2";
    protected static String RESOURCE_STRING = tmp; <---error
    Error:non-static variable tmp cannot be referenced from a static context
    2.Way_2
    protected void initSituation(int sayorpress)
    if (sayorpress==0)
    protected static String RESOURCE_STRING = "string1"; <---error
    else if (sayorpress==1)
    protected static String RESOURCE_STRING = "string2"; <---error
    Error:illegal start of expression at
    not an expression statement at
    Thank you very mich!!!

    Try this:
    protected static String RESOURCE_STRING = null;
    protected void initSituation(int sayorpress)
    if (sayorpress==0)
    yourClass.RESOURCE_STRING = "string1";
    else if (sayorpress==1)
    yourClass.RESOURCE_STRING = "string2";
    You cannot declare a static variable inside a method. But you can access a static variable thorugh your class.

Maybe you are looking for

  • CP60-615DX Touchpad and external mouse no longer work after WIndows 7 SP1 update

    Let me start by saying I am in the IT field, though clearly far from being great at it. I was updating a CP60-615DX at work with Win 7 x64 SP1. It installed with no errors or anything I'd consider abnormal. Once it was finished, the touchpad no long

  • BD87 just shows 279 idocs instead of all 589

    Hi, I have the following issue: I have created 589 idocs using custom ABAP program via SE38, at least that number was shown by SAP. But, when I try to see full list of these 589 idocs via BD87 - I only see 279... I wonder is there some limitations th

  • My screen is stuck on Accessorize test

    Accessorize Test Please plug FW LCD  ID   : 4 FWPWR  : 0 Screen is stuck

  • Giving Password to a ssh command in a script

    Hi   I wanna know how to give password to a ssh command in a script... that is my command iniside script is q=`ssh 172.16.1.2 /usr/sbin/alternatives --config java </root/Desktop/2.txt 2>&1 | grep jdk1.6.0_05` when i execute the script file and when t

  • IPhoto for the iPad tutorial

    I have a new iPad 4.  I downloade iPhoto and was wondering if anyone knew of a good tutorial. I understand that there is a journal function, but for the life of me I cannot seem to get it.  Mark