Re-initiate Vectors in Loop

import java.util.Vector;
public class testClass {
   private Vector basket = new Vector();
   private Vector vowels = new Vector();
   testClass(){
       basket.add("apple");
       basket.add("orange");
       basket.add("starfruit");
       basket.add("strawberry");
       basket.add("peanut");
       basket.add("walnut");
       vowels.add("a");
       vowels.add("e");
       vowels.add("i");
       vowels.add("o");
       vowels.add("u");
   public void findVowels(){
       for (int i = 0; i < vowels.size(); i++) {
           Vector basket = this.basket; //resets local variable basket (hopefully)
           System.out.println("This is the list for letter "  +vowels.get(i));+
+           for (int j = 0; j < basket.size(); j++) {
               if (listOfItems.get(j).toString().contains(vowels.get(i).toString())) {
                   System.out.println(baskets.get(j));
                   basket.remove(j); //will this line remove from the local copy or the global copy?
           System.out.println("");
   }Hello everyone. Based on the code above, I'm trying to extract elements which contains vowels a, e, i, o and u in order. The result of the class above is below:
This is the list for letter a
apple
starfruit
peanut
This is the list for letter e
orange
This is the list for letter i
This is the list for letter o
This is the list for letter u
walnutMy question is, why doesn't this line ( Vector basket = this.basket; ) reset basket for subsequent loops?
Thanks in advance.

OK, the first statement creates a new Vector. But the effect of the second statement is to make the local variable once again refer to the basket referred to by the instance variable. Since nothing now refers to the newly created Vector it has effectively disappeared. So, once again, removing things from the basket will be permenent.
What you need to do is create a new basket and then add the contents of the other one to it.
Vector basket = new Vector(this.basket); // this creates and adds the contents in one step
System.out.println(// etc(See the [Vector constructor documentation|http://java.sun.com/javase/6/docs/api/java/util/Vector.html#Vector(java.util.Collection)])

Similar Messages

  • Vectors : Converting to double[ ] array

    Hello,
    I have a vector which I know consists of double values only. I am trying to create an array of double from this vector but am having some difficulty.
    Firstly if I try this :
    double[] high = (double[])datavector.high.toArray(new double[0]);JBuilder reports :
    'Cannot find method toArray(double[])'
    But if I try this :
    Double[] high = (Double[])datavector.high.toArray(new Double[0]);It works.
    So from this I assume 'Double' is not equal to 'double'
    The trouble is I require 'double[ ]' and NOT 'Double [ ]'.
    Casting Double as (double) does not work... so how do I get double[] from my original vector ?
    Many thanks
    Kerry

    double[] d = new double[v.size()];
              int i = 0;
              for(Iterator<Double> it = v.iterator(); it.hasNext();)
                   d[i++] = (double)it.next();
              just declare the double array to be the size of the vector, then loop thru and populate the array one at a time
    ~Tim

  • Moving through a vector

    Help
    I have retrieved the data below from a database and stored into a vector. (each row is stored into an array and in turn each row is stored into a vector). Now I have to show this data quarterly (add january, feb and mar into one quarter and so on.. I am having problems moving through this vector. Any help is appreciated.
    Sue
    Year Period Labor Force Employment Unemployment Unemployment Rate
    1998 January 3,423 3,249 174 5.10
    1998 February 3,379 3,199 180 5.30
    1998 March 3,390 3,225 165 4.90
    1998 April 3,398 3,244 154 4.50
    1998 May 3,455 3,326 129 3.70
    1998 June 3,564 3,403 161 4.50
    1998 July 3,617 3,479 138 3.80
    1998 August 3,629 3,489 140 3.90
    1998 September 3,546 3,410 136 3.80
    1998 October 3,574 3,409 165 4.60
    1998 November 3,561 3,368 193 5.40
    1998 December 3,476 3,298 178 5.10
    1998 Annual Average 3,501 3,342 159 4.50

    Here's is some pseudocode that might help. Of course, I did this quickly so, there might be a few syntax errors, etc. but you should be able to get the general idea. This might not be the most efficient way either, but it's the first thing I thought of.
        Vector data; //your vector of arrays
        Vector quarterData = new Vector(); //vector of vectors for storing data totals for all 4 quarters
        for (int q = 0 ; q < data.size(); q +=3 )
            int laborTotal = 0;
            int empTotal = 0;
            int unempTotal = 0;
            int unempRateTotal = 0;
            int unempRateAvg = 0;
            int startindex = q;
            int stopindex = q + 3;
            Vector thisQuarterData = new Vector(); //vector of totals for this quarter (will be added to Vector quarterData)
            //loop through each array for this quarter
            while ( startindex < stopindex )
                //access appropriate arrays in Vector data using the startindex as index
                //add values to quarterTotals
                //i.e. go through array and add to totals
                startindex++;
            unempRateAvg = unempRateTotal/3; //find quarter average
            //add totals to this quarters data vector
            thisQuarterData.add(laborTotal);
            thisQuarterData.add(empTotal);
            thisQuarterData.add(unempTotal);
            thisQuarterData.add(unempRateAvg);
            quarterData.add(thisQuarterData);
        }You will then have all of your quarterly data in the Vector quarterData which you can then loop through and output.
    Hope this helps,
    --Nicole                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Question about Java Vectors

    Hello guys,
    If I have a vector that contains an infinite amount of words that have 25 or less letters,
    how do I tell java to give me the number of 1, 2, 3, 4, 5 , 6, etc lettered words in the vector?
    the Vector is called v and it can only contain letters A through Z;
    i figure that I need a loop: so
    Vector v;
    for (int i = 0; i <= 25; i++){
    I just don't know how to complete the counter
    Please help
    Thanks
    Edited by: bondjr on Apr 3, 2008 5:08 PM

    bondjr wrote:
    Hello guys,
    If I have a vector that contains an infinite amount of words that have 25 or less letters, I think you mean an indefinite amount of words, or an arbitrary number of words.
    how do I tell java to give me the number of 1, 2, 3, 4, 5 , 6, etc lettered words in the vector?Loop through the vector, and increment one or more counters. It's not clear whether you want to get all counts in one pass, or just get a single count, e.g., all five-letter words.
    the Vector is called v and it can only contain letters A through Z;
    i figure that I need a loop: so
    Vector v;
    for (int i = 0; i <= 25; i++){
    }I don't think you need the loop. You can get the length of each string with .length().
    I just don't know how to complete the counterAre you counting just words of a single given length (e.g., all five-letter words) or all lengths (e.g., all single-letter words, all two-letter words, etc.)?

  • Performance problems with jdk 1.5 on Linux plattform

    Performance problems with jdk 1.5 on Linux plattform
    (not tested on Windows, might be the same)
    After refactoring using the new features from java 1.5 I lost
    performance significantly:
    public Vector<unit> units;
    The new code:
    for (unit u: units) u.accumulate();
    runs more than 30% slower than the old code:
    for (int i = 0; i < units.size(); i++) units.elementAt(i).accumulate();
    I expected the opposite.
    Is there any information available that helps?

    Here's the complete benchmark code I used:package test;
    import java.text.NumberFormat;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.LinkedList;
    import java.util.Vector;
    public class IterationPerformanceTest {
         private int m_size;
         public IterationPerformanceTest(int size) {
              m_size = size;
         public long getArrayForLoopDuration() {
              Integer[] testArray = new Integer[m_size];
              for (int item = 0; item < m_size; item++) {
                   testArray[item] = new Integer(item);
              StringBuilder builder = new StringBuilder();
              long start = System.nanoTime();
              for (int index = 0; index < m_size; index++) {
                   builder.append(testArray[index]);
              long end = System.nanoTime();
              System.out.println(builder.length());
              return end - start;
         public long getArrayForEachDuration() {
              Integer[] testArray = new Integer[m_size];
              for (int item = 0; item < m_size; item++) {
                   testArray[item] = new Integer(item);
              StringBuilder builder = new StringBuilder();
              long start = System.nanoTime();
              for (Integer item : testArray) {
                   builder.append(item);
              long end = System.nanoTime();
              System.out.println(builder.length());
              return end - start;
         public long getArrayListForLoopDuration() {
              ArrayList<Integer> testList = new ArrayList<Integer>();
              for (int item = 0; item < m_size; item++) {
                   testList.add(item);
              StringBuilder builder = new StringBuilder();
              long start = System.nanoTime();
              for (int index = 0; index < m_size; index++) {
                   builder.append(testList.get(index));
              long end = System.nanoTime();
              System.out.println(builder.length());
              return end - start;
         public long getArrayListForEachDuration() {
              ArrayList<Integer> testList = new ArrayList<Integer>();
              for (int item = 0; item < m_size; item++) {
                   testList.add(item);
              StringBuilder builder = new StringBuilder();
              long start = System.nanoTime();
              for (Integer item : testList) {
                   builder.append(item);
              long end = System.nanoTime();
              System.out.println(builder.length());
              return end - start;
         public long getArrayListIteratorDuration() {
              ArrayList<Integer> testList = new ArrayList<Integer>();
              for (int item = 0; item < m_size; item++) {
                   testList.add(item);
              StringBuilder builder = new StringBuilder();
              long start = System.nanoTime();
              Iterator<Integer> iterator = testList.iterator();
              while(iterator.hasNext()) {
                   builder.append(iterator.next());
              long end = System.nanoTime();
              System.out.println(builder.length());
              return end - start;
         public long getLinkedListForLoopDuration() {
              LinkedList<Integer> testList = new LinkedList<Integer>();
              for (int item = 0; item < m_size; item++) {
                   testList.add(item);
              StringBuilder builder = new StringBuilder();
              long start = System.nanoTime();
              for (int index = 0; index < m_size; index++) {
                   builder.append(testList.get(index));
              long end = System.nanoTime();
              System.out.println(builder.length());
              return end - start;
         public long getLinkedListForEachDuration() {
              LinkedList<Integer> testList = new LinkedList<Integer>();
              for (int item = 0; item < m_size; item++) {
                   testList.add(item);
              StringBuilder builder = new StringBuilder();
              long start = System.nanoTime();
              for (Integer item : testList) {
                   builder.append(item);
              long end = System.nanoTime();
              System.out.println(builder.length());
              return end - start;
         public long getLinkedListIteratorDuration() {
              LinkedList<Integer> testList = new LinkedList<Integer>();
              for (int item = 0; item < m_size; item++) {
                   testList.add(item);
              StringBuilder builder = new StringBuilder();
              long start = System.nanoTime();
              Iterator<Integer> iterator = testList.iterator();
              while(iterator.hasNext()) {
                   builder.append(iterator.next());
              long end = System.nanoTime();
              System.out.println(builder.length());
              return end - start;
         public long getVectorForLoopDuration() {
              Vector<Integer> testVector = new Vector<Integer>();
              for (int item = 0; item < m_size; item++) {
                   testVector.add(item);
              StringBuilder builder = new StringBuilder();
              long start = System.nanoTime();
              for (int index = 0; index < m_size; index++) {
                   builder.append(testVector.get(index));
              long end = System.nanoTime();
              System.out.println(builder.length());
              return end - start;
         public long getVectorForEachDuration() {
              Vector<Integer> testVector = new Vector<Integer>();
              for (int item = 0; item < m_size; item++) {
                   testVector.add(item);
              StringBuilder builder = new StringBuilder();
              long start = System.nanoTime();
              for (Integer item : testVector) {
                   builder.append(item);
              long end = System.nanoTime();
              System.out.println(builder.length());
              return end - start;
         public long getVectorIteratorDuration() {
              Vector<Integer> testVector = new Vector<Integer>();
              for (int item = 0; item < m_size; item++) {
                   testVector.add(item);
              StringBuilder builder = new StringBuilder();
              long start = System.nanoTime();
              Iterator<Integer> iterator = testVector.iterator();
              while(iterator.hasNext()) {
                   builder.append(iterator.next());
              long end = System.nanoTime();
              System.out.println(builder.length());
              return end - start;
          * @param args
         public static void main(String[] args) {
              IterationPerformanceTest test = new IterationPerformanceTest(1000000);
              System.out.println("\n\nRESULTS:");
              long arrayForLoop = test.getArrayForLoopDuration();
              long arrayForEach = test.getArrayForEachDuration();
              long arrayListForLoop = test.getArrayListForLoopDuration();
              long arrayListForEach = test.getArrayListForEachDuration();
              long arrayListIterator = test.getArrayListIteratorDuration();
    //          long linkedListForLoop = test.getLinkedListForLoopDuration();
              long linkedListForEach = test.getLinkedListForEachDuration();
              long linkedListIterator = test.getLinkedListIteratorDuration();
              long vectorForLoop = test.getVectorForLoopDuration();
              long vectorForEach = test.getVectorForEachDuration();
              long vectorIterator = test.getVectorIteratorDuration();
              System.out.println("Array      for-loop: " + getPercentage(arrayForLoop, arrayForLoop) + "% ("+getDuration(arrayForLoop)+" sec)");
              System.out.println("Array      for-each: " + getPercentage(arrayForLoop, arrayForEach) + "% ("+getDuration(arrayForEach)+" sec)");
              System.out.println("ArrayList  for-loop: " + getPercentage(arrayForLoop, arrayListForLoop) + "% ("+getDuration(arrayListForLoop)+" sec)");
              System.out.println("ArrayList  for-each: " + getPercentage(arrayForLoop, arrayListForEach) + "% ("+getDuration(arrayListForEach)+" sec)");
              System.out.println("ArrayList  iterator: " + getPercentage(arrayForLoop, arrayListIterator) + "% ("+getDuration(arrayListIterator)+" sec)");
    //          System.out.println("LinkedList for-loop: " + getPercentage(arrayForLoop, linkedListForLoop) + "% ("+getDuration(linkedListForLoop)+" sec)");
              System.out.println("LinkedList for-each: " + getPercentage(arrayForLoop, linkedListForEach) + "% ("+getDuration(linkedListForEach)+" sec)");
              System.out.println("LinkedList iterator: " + getPercentage(arrayForLoop, linkedListIterator) + "% ("+getDuration(linkedListIterator)+" sec)");
              System.out.println("Vector     for-loop: " + getPercentage(arrayForLoop, vectorForLoop) + "% ("+getDuration(vectorForLoop)+" sec)");
              System.out.println("Vector     for-each: " + getPercentage(arrayForLoop, vectorForEach) + "% ("+getDuration(vectorForEach)+" sec)");
              System.out.println("Vector     iterator: " + getPercentage(arrayForLoop, vectorIterator) + "% ("+getDuration(vectorIterator)+" sec)");
         private static NumberFormat percentageFormat = NumberFormat.getInstance();
         static {
              percentageFormat.setMinimumIntegerDigits(3);
              percentageFormat.setMaximumIntegerDigits(3);
              percentageFormat.setMinimumFractionDigits(2);
              percentageFormat.setMaximumFractionDigits(2);
         private static String getPercentage(long base, long value) {
              double result = (double) value / (double) base;
              return percentageFormat.format(result * 100.0);
         private static NumberFormat durationFormat = NumberFormat.getInstance();
         static {
              durationFormat.setMinimumIntegerDigits(1);
              durationFormat.setMaximumIntegerDigits(1);
              durationFormat.setMinimumFractionDigits(4);
              durationFormat.setMaximumFractionDigits(4);
         private static String getDuration(long nanos) {
              double result = (double)nanos / (double)1000000000;
              return durationFormat.format(result);
    }

  • Performance problems with new Java Tiger style recommendations

    Performance problems with jdk 1.5 on Linux plattform
    (not tested on Windows, might be the same)
    using the new style recommendations.
    I need fast Vector loops for high speed mathematical calculations, some
    hints about the fastest way to program that loop would be also great!
    After refactoring using the new features from java 1.5 (as recommended from
    SUN) I lost performance significantly:
    using a vector:
    public Vector<unit> units;
    The new code (recommended from SUN for Java Tiger for redesign):
    for (unit u: units) u.accumulate();
    runs more than 30% slower than the old code:
    for (int i = 0; i < units.size(); i++) units.elementAt(i).accumulate();
    I expected the opposite.
    Is there any information available that helps?
    The following additional information I got from Mr. Shankar Unni:
    I got some fairly anomalous results comparing ArrayList and Vector: for the
    1.5-style loops, ArrayList was faster then Vector, but for a loop with get()
    calls, Vector was faster. Vector was even faster than that using
    elementAt(), which was a surprise:
    For a million summing iterations over a 100-element array:
    vector elementAt loop took 3446 ms.
    vector get loop took 3796 ms.
    vector iterator loop took 5469 ms.
    arraylist get loop took 4136 ms.
    arraylist iterator loop took 4668 ms.

    If your topic doesn't change, please stay in your original post.

  • Nokia Lumia 920 potential battery drain issue?

    Can you Nokia confirm this? http://reach.jdbpocketware.com/topic/128305-to-nokia-ref-lumia-920/
    The issue illustrated in detail:
    Nature of Windows Phone buttons
    Pressing either the power button or the camera button will cause the device screen to turn on, even when the proximity sensor detects proximity.
    [IMAGE http://i.imgur.com/M2to9.png]
    The lockscreen behavior
    Upon power on, screen lights up and shows the lockscreen (or camera), which runs a timeout to auto power off the device if screen is not touched in X seconds. 
    But if screen is touched, the timeout counter is restarted, so continuous touching could lead into a loop, the "death loop" which won't let the device to power off (standby) and will consume battery life.
    [IMAGE http://i.imgur.com/2HNdV.png]
    New touchscreen technology
    The Nokia Lumia 920 comes with a touchscreen that reacts to touch from pretty much any material such as metal or clothes. This can be dangerous.
    [IMAGE http://i.imgur.com/4tbyY.png]
    So here is a theory 
    When the phone is inside a pocket or bag it can be touched by other objects. These objects can press buttons and can touch/rub the screen. This will initiate the "death loop" for who knows how much time, could be minutes or hours, depends on how active the user is since body movement will produce friction between objects/clothes and touchscreen:
    [IMAGE http://i.imgur.com/XMT0y.png]
    The "death loop" will drain battery and battery is precious.
    Solution?
    Should be simple: screen must not power on if the proximity sensor detects proximity. Current version of Windows Phone does not take care of this. The big question is: will Windows Phone 8 take care of this? Is the Lumia 920 a potential battery drainer?

    I don't understand why we have to spend our valuable time in the forums for days and nights to FIND HOW TO FIX THAT CRAB!! NOKIA company did not handout these devices FOR CHARITY.All of us had paid around a thousand dollars to buy this Phone. They have got to work overtime to fix it and publish a solution otherwise recall the devices back.

  • How to Troubleshoot the Connection Pool Exception?

    Dear Oracle Gurus, very good afternoon to you.
    I'm looking forward for some tips/troubleshoting guide to escape from the below exception, that occres very frequently to one of application that 100+ users will login from different locations & work on and update the data and save their work, where all in sudden they can't acces the application and it gets down.
    Most of the times in the server log I observed below.
    weblogic.jdbc.extensions.PoolLimitSQLException: weblogic.common.resourcepool.ResourceLimitException: No resources currently available in pool RemoteDesktop.main to allocate to applications, please increase the size of the pool and retry..
    Please help me on, how to overcome this kind of exception.
    In Weblogi c server I see below kind of Warnings.
    If you set the buffer size to zero in a servlet, it would fail to respond and would initiate an infinite loop in the server. WebLogic Server would ultimately display a Errors:
    ExecuteThread: '157' for queue: 'weblogic.kernel.Default' has been busy for "633" seconds working on the request "Http Request: : ../updates/process_manager.jsp", which is more than the configured time (StuckThreadMaxTime) of "600" seconds.
    I searched over google for this kind of error, See otherusers posted the same kind of errors but didn't have any positive replies to troubleshoot this issue.
    I also got Oracle Dev link on Weblogic version upgrade product where they fixed similar kind of error it seems. Which is shown below.
    http://docs.oracle.com/cd/E13222_01/wls/docs61/notes/bugfixes2.html -- BUG # CR106186
    details:
    "Suspend Checker Thread" prio=10 tid=0x23eb90 nid=0xfec runnable
    <May 14, 2003 10:53:34 AM PDT> <Warning> <WebLogicServer> <000337>
    <ExecuteThread: '10' for queue: 'default' has been busy for "1,181" seconds working on the request "Http Request: servlet_uri", which is more than the configured time (StuckThreadMaxTime) of "600" seconds.>
    This problem was solved with a code fix.
    Looking forward for some help, Thank you inadvance.
    FYI..
    I'm using oracle thin driver JDBC connection/Weblogic 8.1
    Edited by: user1072948 on Apr 26, 2012 11:55 AM

    I agree that looking into the number of connections that you have open when you see
    weblogic.jdbc.extensions.PoolLimitSQLException: weblogic.common.resourcepool.ResourceLimitException: No resources currently available in pool RemoteDesktop.main to allocate to applications, please increase the size of the pool and retry..
    would be a good idea; but I would suggest that you don't increase without thinking about the consequences. I would look more closely at what the connections to the database are doing, for instance, how long are the connection being left open for? What are the queries that are being run? Should you expect to see all the connections in the connection pool being used? What is the current connection pool limit? Are you simply going to increase the number of connections to find that they are also waiting? What is the load on the database at the time?
    It's the other error that you say you see
    ExecuteThread: '157' for queue: 'weblogic.kernel.Default' has been busy for "633" seconds working on the request "Http Request: : ../updates/process_manager.jsp", which is more than the configured time (StuckThreadMaxTime) of "600" seconds.
    What does this JSP do? Why would this be busy for so long? Is it related to the previous exception that you have? I'd ask you delevelopment team to look into this.
    In short, it sounds like you have load issues on your server(s) and a careful tuning of the system after a full analysis (thread dumps, heap profiling, connection pool monitoring and code review) would probably be beneficial. It may be that restricting the thread pool may help, it may be that increasing the connection pool would help. I'd not plump for a quick fix here.

  • Capture Last ten Shots (Shift Registers)?

    Situation: -
    I am continuously acquiring data on 4 channels of the DAQ card using conditional triggering. Each loop captures 2000 samples, which are stored in 2-D waveform arrays containing each scan of each channel. The data is continually updated on a waveform graph for the user to monitor. After a period of "test time" or when you press a button, the loop will end and the last loop of waveform data gets passed to the analysis VI where all the calcs are performed (I only perform calcs/analysis on static data once test time has completed).
    Problem: -
    I now want to average the last 5-10 points prior to the while loop ending (as the injection needle will jump around slightly shot to shot). I can enable indexing on the while loop and then select the points I require afterwards (i.e. the last 5-10 or whatever), but this takes up a hell of alot of memory and the processor starts caching to disk too often. Can you imagine just how many points are stored in memory (2000 samples/channel, 4 channels per scan, sampling at 80KHz, for 10mins).
    There is no need to store all these points. Each time the loop iterates, the buffer is cleared so the program runs quickly and smoothly. All I need to do is store the last 5-10 waveform array's and pass these on to the next VI, not the whole XXXXXX amount of arrays/point.
    I may try and use a sequence, so that the first sequence uses disable indexing and ends after the "Test time" has elapsed. This then continues into the next sequence and proceeds to capture a further 5-10 shots with indexing enabled, before passing to analysis VI. This still doesn't really capture the last 5-10 iterations, it captures the next 5-10 iterations, but it would do.
    Ideally, I want the while loop to execute with indexing disabled, and at a certain point in time (comparing the "Test Time" with the "sample rate"), the while loop changes to 'indexing enabled' which will build up an array of waveform data until the loop ends (about 5-10 iterations later).
    Any Ideas. If you've got time on your hands..........

    You can use a shift register. This will just maintain the last "n" amounts of data sets. I've attached a really simple example to illustrate this.
    This may work for you needs however there is an issue that the shift registers are in essence being used the whole time so you will have more memory interaction than you may want ... which depending on your performance requirements may not be desirable.
    If that is the case then it may be best to slightly modifiy the approach you're using. Indexing continually instead of in the main loop. Set up a condition/case upon which within the main loop you initiate a sub loop that then starts logging the data you require for averaging.
    Hope this helps,
    Kamran
    Attachments:
    ShiftRegister.vi ‏36 KB

  • Scalar distance across columns

    I need to calculate the scalar (Euclidean) distance between two vectors, each dimension represented by columns in a table. I have a procedure that does it the slow and painful way: loop over all vector pairs/loop over all columns/look up the individual cell values/sum over all the differences. It appears to me though, that there should be a more straightforward way to do this using the:
    SELECT * FROM TST INTO vREF_DATA WHERE REGNO=1;
    SELECT * FROM TST INTO vCMP_DATA WHERE REGNO=2;
    syntax in PL/SQL, then loop over the variables/column elements to sum the differences. However, I can't figure out how to keep the pointers for each variable in sync.
    E.g.: coord1(1,2,3), coord2(2,3,1), differences(1,1,2), sum=4.
    I can do this in Perl using hashes/arrays, but not in PL/SQL. What is the right frame/syntax to do this? If it were a couple of hundred rows, I'd do it in Perl, but with millions of rows and hundreds of columns, it gets real tedious, not to mention easily out-of-sync with the database contents.
    I'd appreciate any suggestions!

    Michiel:
    Glad that it works for you. So, you want a fishing lesson :-).
    First, the full documentation for the DBMS_SQL package can be found here .
    Essentially, DBMS_SQL is an industrial strength version of EXECUTE IMMEDIATE (well, properly, EXECUTE IMMEDIATE is a highly simplified version of DBMS_SQL, since DBMS_SQL came first). It has many advantages over EXECUTE IMMEDIATE because it allows you full control over virtually everything to do with the query. So, you can relatively easily create bind variables on the fly to create statements with an unknown number of binds. It also allows you to find the columns from any arbitrary query through DBMS_SQL.Describe_Columns.
    You never actually see any values returned, because I never actually return any. Since you wanted your output in another table, I decided to build one big insert statement, rather than iterate through all the rows, calculate the distance, and then insert one row at a time. It seemed more efficient to me. I also decided to "hard code", through a bind variable, each of the column values from the ref_id, rather than try to dynamically build a join, which seemd simpler to me.
    1. DBMS_SQL.Describe_Columns returns a table of records, one record for each column, that gives information much like that in the xxx_tab_columns views. If some id columns may be numeric, you can test the col_type field in the table of records and put a dummy VARCHAR variable into the character columns. Just be aware that the col_type field returns a numeric version of the column_type, not a string. If you look at the text from user_tab_cols:
    SELECT text
    FROM dba_views
    WHERE view_name = 'USER_TAB_COLS'You can see where Oracle DECODES the numeric type to the NUMBER, VARCHAR2 etc. Essentially, NUMBER is 1 and VARCHAR2 is 2.
    2. I replaced the FOR scale_rec IN ... LOOP block with another DBMS_SQL built query to pull the AVG and VARIANCE from the table, it is commented in the code below.
    3. You cannot really put a threshold on the computation of the distance, since the distance is not really known to the query until it is fully executed (i.e. at the time of inserting). However, you could modify the insert query to filter values with distances greater than 3. I will leave that modification as a exercise for the fiherman, but the end sql statement would look something like:
    INSERT INTO diag
    SELECT src, id, dist
    FROM (SELECT :src_id src, id,
            SQRT(ABS((POWER((:sc2 - :mean2)/:var2, 2) - POWER((col1 - :mean2)/:var2, 2))+
                     (POWER((:sc3 - :mean3)/:var3, 2) - POWER((col2 - :mean3)/:var3, 2))+
                     (POWER((:sc4 - :mean4)/:var4, 2) - POWER((col3 - :mean4)/:var4, 2)))) dist
          FROM t
          WHERE id <> :src_id)
    WHERE dist <= 3Now here is a heavily commented version taking into account the proper formula.
    CREATE or replace PROCEDURE euclidean_distance (p_src_tab IN VARCHAR2) AS
       -- Associative Array for scaling factors
       TYPE scale_cols_tp IS TABLE OF NUMBER INDEX BY VARCHAR2(30);
       mean_cols scale_cols_tp; -- Will hold average of columns
       var_cols scale_cols_tp;  -- Will hold variance of columns
       -- Array to hold column values for the reference id
       TYPE src_cols_tp IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
       src_cols src_cols_tp;
       l_dummyn NUMBER;  -- Dummy Number for Define Column
       l_ignore NUMBER;  -- Receives rows processed from queries
       l_sqlstr VARCHAR2(32767);  -- For sql statements
       src_cur  NUMBER;  -- Reference ID Cursor handle
       src_tab  DBMS_SQL.Desc_Tab;  -- Table of Records describing passed table
       src_col_cnt NUMBER;   -- Number of columns in passed table
       ins_cur  NUMBER;  -- Insert Cursor handle
       mv_cur  NUMBER;  -- Cursor handle for Mean and Variance of table
       l_col_pos NUMBER; -- Index into src_tab
       l_res_pos NUMBER; -- Column position in mv_cur
       l_x1     VARCHAR2(10);  -- Dynamic bind variable for source column values
       l_x2     VARCHAR2(30);  -- Column name from source columns
       l_meani  VARCHAR2(10);  -- Dynamic bind variable for mean of table
       l_vari   VARCHAR2(10);  -- Dynamic bind variable for variance of table
    BEGIN
       -- Get a "handle" for a cursor, and parse the query
       src_cur := DBMS_SQL.Open_Cursor;
       DBMS_SQL.Parse(src_cur, 'SELECT * FROM '||p_src_tab||' WHERE id = :src_id',DBMS_SQL.Native);
       -- Describe the table to get number of columns, their names and their types
       DBMS_SQL.Describe_Columns(src_cur, src_col_cnt, src_tab);
       -- I now have a table of records (src_tab) showing similar info
       -- to that shown in xxx_tab_columns, one record per column
       -- and the number of columns in the table (actually the number of records
       -- in src_tab) is in src_col_cnt
       -- Define the column types for src_cur.  This just tell DBMS_SQL that
       -- the column at position i (based on the column list in the select)
       -- is of the passed data type.  It is not setting a variable to
       -- receive the column value.
       -- I am assuming all inluding ID are NUMBER.
       -- If id may be alpha can test src_tab(i).col_type to check data type
       FOR i IN 1 .. src_col_cnt LOOP
          DBMS_SQL.DEFINE_COLUMN(src_cur, i, l_dummyn);
       END LOOP;
    -- This section replaces the FOR scale_rec IN LOOP
       -- Get mean and variance for passed table
       -- Build the sql statement
       l_sqlstr := 'SELECT ';
       FOR i IN 2 .. src_col_cnt LOOP
          l_sqlstr := l_sqlstr||'AVG('||src_tab(i).col_name||'),'||
                'VARIANCE('||src_tab(i).col_name||'),';
       END LOOP;
       -- l_sqlstr is now:
       -- SELECT AVG(col1), VARIANCE(col1),AVG(col2), VARIANCE(col2),
       --        AVG(col3), VARIANCE(col3),
       -- So trim the trailing , and add FROM
       l_sqlstr := RTRIM(l_sqlstr,',');
       l_sqlstr := l_sqlstr||' FROM '||p_src_tab;
       -- Set up the cursor
       mv_cur := DBMS_SQL.OPEN_CURSOR;
       DBMS_SQL.Parse(mv_cur, l_sqlstr, DBMS_SQL.Native);
       -- Getting 2 results (AVG and VARIANCE) for each column
       -- and we know that they are all numeric
       -- but need to ignore the id column so
       FOR i In 1 .. (src_col_cnt - 1) * 2 LOOP
          DBMS_SQL.DEFINE_COLUMN(mv_cur, i, l_dummyn);
       END LOOP;
       -- Now Run the query and assign columns into associative array
       l_ignore := DBMS_SQL.EXECUTE_AND_FETCH(mv_cur);
       l_col_pos := 2;  -- start in Record 2 of src_tab
       l_res_pos := 1;  -- start in Column 1 of result set
       WHILE l_col_pos <= src_col_cnt LOOP
          DBMS_SQL.COLUMN_VALUE(mv_cur, l_res_pos, mean_cols(src_tab(l_col_pos).col_name));
          DBMS_SQL.COLUMN_VALUE(mv_cur, l_res_pos + 1, var_cols(src_tab(l_col_pos).col_name));
          l_col_pos := l_col_pos + 1;
          l_res_pos := l_res_pos + 2;
       END LOOP;
       -- I end up with two associative arrays, both indexed by column name
       -- mean_cols values are the average for each column
       -- var_cols values are the variance for each column
       -- We're done with this query so
       DBMS_SQL.Close_Cursor(mv_cur);
    -- END replacement FOR scale_rec IN LOOP
       -- Build the insert statement
       -- I took the ABSolute value of the SUM of L(i) because with
       -- my data I was getting negative values which blew the SQRT
       l_sqlstr := 'INSERT INTO diag SELECT :src_id, id, SQRT(ABS(';
       FOR i IN 2 .. src_col_cnt LOOP
          -- Dynamically create bind variables to hold "fixed" values
          -- (i.e. reference values, mean, and variance
          -- and plug the correct column names for the target columns
          l_x1 := ':sc'||i; -- For i = 2 gives :sc2
          l_x2 := src_tab(i).col_name; -- For i = 2 gives COL1
          l_meani := ':mean'||i; -- For i = 2 gives :mean2
          l_vari := ':var'||i; -- For i = 2 gives :var2
          -- Append this column formula to sql statement
          l_sqlstr := l_sqlstr ||'(POWER(('||l_x1||' - '||l_meani||
                      ')/'||l_vari||', 2) - POWER(('||l_x2||' - '||
                      l_meani||')/'||l_vari||', 2)) + ';
       END LOOP;
       -- Here, l_sqlstr is:
       -- INSERT INTO diag
       -- SELECT :src_id, id, SQRT(ABS((POWER((:sc2 - :mean2)/:var2, 2) -
       --                               POWER((col1 - :mean2)/:var2, 2))+
       --                              (POWER((:sc3 - :mean3)/:var3, 2) -
       --                               POWER((col2 - :mean3)/:var3, 2))+
       --                              (POWER((:sc4 - :mean4)/:var4, 2) -
       --                               POWER((col3 - :mean4)/:var4, 2))+
       -- so get rid of the trailing + and space
       l_sqlstr := RTRIM(l_sqlstr,'+ ');
       -- Now close the open bracket from SQRT and ABS and add FROM and WHERE
       l_sqlstr := l_sqlstr||')) FROM '||p_src_tab||' WHERE id <> :src_id';
       -- Now we have a valid insert statement so
       -- Prepare and parse the insert cursor
       ins_cur := DBMS_SQL.Open_Cursor;
       DBMS_SQL.Parse(ins_cur, l_sqlstr, DBMS_SQL.Native);
       -- bind in the mean and variance which are fixed for this set of columns
       FOR i IN 2 .. src_col_cnt LOOP
          DBMS_SQL.Bind_Variable(ins_cur,':mean'||i, mean_cols(src_tab(i).col_name));
          DBMS_SQL.Bind_Variable(ins_cur,':var'||i, var_cols(src_tab(i).col_name));
          -- for i = 2, These two calls resolve as:
          -- DBMS_SQL.Bind_Variable(ins_cur,:mean2, mean_cols(COL1));
          -- DBMS_SQL.Bind_Variable(ins_cur,:var2, var_cols(COL1));
          -- which means bind the value found in mean_cols('COL1') to
          -- the bind variable :mean2 and the value found in var_cols('COL1') to 
          -- the bind variable :var2
       END LOOP;
       -- Get the reference IDs
       FOR intrest_rec IN (SELECT ref_id FROM query) LOOP
          -- For each reference ID bind into the source query
          DBMS_SQL.Bind_Variable(src_cur,':src_id', intrest_rec.ref_id);
          -- So, here, on the first iteration, we are about to execute
          -- the statement
          -- SELECT * FROM t WHERE id = 1     
          l_ignore := DBMS_SQL.Execute_And_Fetch(src_cur);
          -- Get the column values from each source row and
          -- bind that value (e.g. 1 in my sample) to variable :src_id
          DBMS_SQL.Bind_Variable(ins_cur,':src_id', intrest_rec.ref_id);
          FOR i IN 2 .. src_col_cnt LOOP
             -- Retrieve the value of each column of the source row
             -- into the table of NUMBERS
             DBMS_SQL.COLUMN_VALUE(src_cur, i, src_cols(i));
             -- Then bind it into the insert cursor
             DBMS_SQL.Bind_Variable(ins_cur,':sc'||i, src_cols(i));
          END LOOP;
          -- execute the insert statement
          l_ignore := DBMS_SQL.EXECUTE(ins_cur);
       END LOOP;
       COMMIT;
       DBMS_SQL.Close_Cursor(src_cur);
       DBMS_SQL.Close_Cursor(ins_cur);
    END;If you still have questions, I will be around until Thursday, then back January 4.
    John

  • OLE Integration with Excel --- Urgent

    Hello,
    i want to draw two charts on Excel sheet based on some data in SAP. in the excel sheet first i have to display the data and then draw the chart for that. now i am able to draw first chart but not able to draw the second chart because i think the area where i have drawn my first chart is active and not able to print the data related to second chart. can any one tell me, how to activate the sheet after drawing first graph.
    Thanks a lot in advance...
    Mohan

    Mohan,
    Try this....
    You can activate using ...CALL METHOD OF gs_activesheet 'Activate' .
    Report ZTEST.
    INCLUDE ole2incl .
    DATA: gs_excel TYPE ole2_object ,
    gs_wbooklist TYPE ole2_object ,
    gs_application TYPE ole2_object ,
    gs_wbook TYPE ole2_object ,
    gs_activesheet TYPE ole2_object ,
    gs_sheets TYPE ole2_object ,
    gs_newsheet TYPE ole2_object ,
    gs_cell1 TYPE ole2_object ,
    gs_cell2 TYPE ole2_object ,
    gs_cells TYPE ole2_object ,
    gs_range TYPE ole2_object ,
    gs_font TYPE ole2_object ,
    gs_interior TYPE ole2_object ,
    gs_columns TYPE ole2_object ,
    gs_charts TYPE ole2_object ,
    gs_chart TYPE ole2_object ,
    gs_charttitle TYPE ole2_object ,
    gs_charttitlechar TYPE ole2_object ,
    gs_chartobjects TYPE ole2_object .
    DATA gv_sheet_name(20) TYPE c .
    DATA gv_outer_index LIKE sy-index .
    DATA gv_intex(2) TYPE c .
    DATA gv_line_cntr TYPE i . "line counter
    DATA gv_linno TYPE i . "line number
    DATA gv_colno TYPE i . "column number
    DATA gv_value TYPE i . "data
    PARAMETERS: p_sheets TYPE i .
    *Step 2 Initiate the do-loop and OLE automation base objects.
    *Code Part C.2 Looping and initializing, adding new worksheets
    START-OF-SELECTION .
    DO p_sheets TIMES .
    *--Forming sheet name
    gv_intex = sy-index .
    gv_outer_index = sy-index .
    CONCATENATE 'Excel Sheet #' gv_intex INTO gv_sheet_name .
    *--For the first loop, Excel is initiated and one new sheet is added
    IF sy-index = 1 .
    CREATE OBJECT gs_excel 'EXCEL.APPLICATION' .
    SET PROPERTY OF gs_excel 'Visible' = 1 .
    GET PROPERTY OF gs_excel 'Workbooks' = gs_wbooklist .
    GET PROPERTY OF gs_wbooklist 'Application' = gs_application .
    SET PROPERTY OF gs_application 'SheetsInNewWorkbook' = 1 .
    CALL METHOD OF gs_wbooklist 'Add' = gs_wbook .
    GET PROPERTY OF gs_application 'ActiveSheet' = gs_activesheet .
    SET PROPERTY OF gs_activesheet 'Name' = gv_sheet_name .
    *--For the rest of loops, other sheets are added
    ELSE .
    GET PROPERTY OF gs_wbook 'Sheets' = gs_sheets .
    CALL METHOD OF gs_sheets 'Add' = gs_newsheet .
    SET PROPERTY OF gs_newsheet 'Name' = gv_sheet_name .
    ENDIF .
    gv_line_cntr = 1 . "line counter
    *Step3 Write the title and format it.
    *--Title
    *--Selecting cell area to be merged.
    CALL METHOD OF gs_excel 'Cells' = gs_cell1
    EXPORTING
    #1 = 1
    #2 = 1.
    CALL METHOD OF gs_excel 'Cells' = gs_cell2
    EXPORTING
    #1 = 1
    #2 = 4.
    CALL METHOD OF gs_excel 'Range' = gs_cells
    EXPORTING
    #1 = gs_cell1
    #2 = gs_cell2.
    CALL METHOD OF gs_cells 'Select' .
    *--Merging
    CALL METHOD OF gs_cells 'Merge' .
    *--Setting title data
    CALL METHOD OF gs_excel 'Cells' = gs_cell1
    EXPORTING
    #1 = gv_line_cntr
    #2 = 1.
    SET PROPERTY OF gs_cell1 'Value' = 'TITLE' .
    *Code Part C.3 Writing and formatting the title
    *--Formatting the title
    GET PROPERTY OF gs_cell1 'Font' = gs_font .
    SET PROPERTY OF gs_font 'Underline' = 2 .
    SET PROPERTY OF gs_font 'Bold' = 1 .
    SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
    GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
    SET PROPERTY OF gs_interior 'ColorIndex' = 15 .
    SET PROPERTY OF gs_interior 'Pattern' = -4124 .
    SET PROPERTY OF gs_interior 'PatternColorIndex' = -4105 .
    *Step 4 Write some additional data for the title area and format them.
    gv_line_cntr = gv_line_cntr + 1 .
    *--Writing some additional data for the title
    CALL METHOD OF gs_excel 'Cells' = gs_cell1
    EXPORTING
    #1 = gv_line_cntr
    #2 = 1.
    SET PROPERTY OF gs_cell1 'Value' = 'Sheet No' .
    CALL METHOD OF gs_excel 'Cells' = gs_cell1
    EXPORTING
    #1 = gv_line_cntr
    #2 = 5.
    SET PROPERTY OF gs_cell1 'Value' = ':' .
    CALL METHOD OF gs_excel 'Cells' = gs_cell1
    EXPORTING
    #1 = gv_line_cntr
    #2 = 6.
    SET PROPERTY OF gs_cell1 'Value' = gv_intex .
    *--Formatting the area of additional data 1
    CALL METHOD OF gs_excel 'Cells' = gs_cell1
    EXPORTING
    #1 = 1
    #2 = 1.
    CALL METHOD OF gs_excel 'Cells' = gs_cell2
    EXPORTING
    #1 = gv_line_cntr
    #2 = 5.
    CALL METHOD OF gs_excel 'Range' = gs_cells
    EXPORTING
    #1 = gs_cell1
    #2 = gs_cell2.
    CALL METHOD OF gs_cells 'Select' .
    GET PROPERTY OF gs_cells 'Font' = gs_font .
    SET PROPERTY OF gs_font 'Bold' = 1 .
    *--Formatting the area of additional data 2
    CALL METHOD OF gs_excel 'Cells' = gs_cell1
    EXPORTING
    #1 = 1
    #2 = 5.
    CALL METHOD OF gs_excel 'Cells' = gs_cell2
    EXPORTING
    #1 = gv_line_cntr
    #2 = 5.
    CALL METHOD OF gs_excel 'Range' = gs_cells
    EXPORTING
    #1 = gs_cell1
    #2 = gs_cell2.
    CALL METHOD OF gs_cells 'Select' .
    GET PROPERTY OF gs_cells 'Columns' = gs_columns .
    CALL METHOD OF gs_columns 'AutoFit' .
    *--Bordering title data area
    CALL METHOD OF gs_excel 'Cells' = gs_cell1
    EXPORTING
    #1 = 1
    #2 = 1.
    CALL METHOD OF gs_excel 'Cells' = gs_cell2
    EXPORTING
    #1 = gv_line_cntr
    #2 = 6.
    CALL METHOD OF gs_excel 'Range' = gs_cells
    EXPORTING
    #1 = gs_cell1
    #2 = gs_cell2.
    CALL METHOD OF gs_cells 'Select' .
    CALL METHOD OF gs_cells 'BorderAround'
    EXPORTING
    #1 = 1 "continuous line
    #2 = 4. "thick
    *Code Part C.4 Some additional writing to the title area, formatting
    *and bordering around the title area
    *Step 5 Put axis labels to the data area.
    *Code Part C.5 Axis Labels
    *--Putting axis labels
    gv_colno = 2 .
    gv_line_cntr = gv_line_cntr + 5 .
    gv_linno = gv_line_cntr - 1 .
    CALL METHOD OF gs_excel 'Cells' = gs_cell1
    EXPORTING
    #1 = gv_linno
    #2 = 1.
    SET PROPERTY OF gs_cell1 'Value' = 'X' .
    CALL METHOD OF gs_excel 'Cells' = gs_cell1
    EXPORTING
    #1 = gv_line_cntr
    #2 = 1.
    SET PROPERTY OF gs_cell1 'Value' = 'Y' .
    *Step 6 Generate some data.
    *Code Part C.6 Generating Data
    *--Generating some data
    DO 3 TIMES .
    gv_value = gv_outer_index * sy-index * 10 .
    CALL METHOD OF gs_excel 'Cells' = gs_cell1
    EXPORTING
    #1 = gv_linno
    #2 = gv_colno.
    SET PROPERTY OF gs_cell1 'Value' = sy-index .
    CALL METHOD OF gs_excel 'Cells' = gs_cell1
    EXPORTING
    #1 = gv_line_cntr
    #2 = gv_colno.
    SET PROPERTY OF gs_cell1 'Value' = gv_value .
    gv_colno = gv_colno + 1 .
    ENDDO .
    *Step 7 Set source data area for the chart.
    *Code Part C.7 Setting source data area for the chart
    *--Source data area
    gv_colno = gv_colno - 1 .
    CALL METHOD OF gs_excel 'Cells' = gs_cell1
    EXPORTING
    #1 = gv_linno
    #2 = 1.
    CALL METHOD OF gs_excel 'Cells' = gs_cell2
    EXPORTING
    #1 = gv_line_cntr
    #2 = gv_colno.
    CALL METHOD OF gs_excel 'Range' = gs_cells
    EXPORTING
    #1 = gs_cell1
    #2 = gs_cell2.
    CALL METHOD OF gs_cells 'Select' .
    *Step8 Draw the chart
    *Code Part C.8 Draw the chart
    GET PROPERTY OF gs_application 'Charts' = gs_charts .
    CALL METHOD OF gs_charts 'Add' = gs_chart .
    CALL METHOD OF gs_chart 'Activate' .
    SET PROPERTY OF gs_chart 'ChartType' = '51' . "Vertical bar graph
    CALL METHOD OF gs_chart 'SetSourceData'
    EXPORTING
    #1 = gs_cells
    #2 = 1.
    SET PROPERTY OF gs_chart 'HasTitle' = 1 .
    GET PROPERTY OF gs_chart 'ChartTitle' = gs_charttitle .
    GET PROPERTY OF gs_charttitle 'Characters' = gs_charttitlechar .
    SET PROPERTY OF gs_charttitlechar 'Text' = 'Sample Graph' .
    *Step 9 Locate the chart onto the current worksheet.
    *Code Part C.9 Locating the chart onto the current worksheet
    *--Locate the chart onto the current worksheet
    *--Activate current sheet
    CALL METHOD OF gs_excel 'WorkSheets' = gs_activesheet
    EXPORTING
    #1 = gv_sheet_name.
    CALL METHOD OF gs_activesheet 'Activate' .
    CALL METHOD OF gs_chart 'Location'
    EXPORTING
    #1 = 2
    #2 = gv_sheet_name.
    *Step 10 Reposition the chart to a proper place and finish the do-loop.
    *Code Part C.10 Repositioning the chart to a proper place and end of
    *the do-loop counting sheet number
    *--Reposition the chart on the worksheet (cut&paste)
    CALL METHOD OF gs_activesheet 'ChartObjects' = gs_chartobjects .
    CALL METHOD OF gs_chartobjects 'Select' .
    CALL METHOD OF gs_chartobjects 'Cut' .
    *--Select new area
    gv_line_cntr = gv_line_cntr + 2 .
    CALL METHOD OF gs_excel 'Cells' = gs_cell1
    EXPORTING
    #1 = gv_line_cntr
    #2 = 1.
    CALL METHOD OF gs_excel 'Cells' = gs_cell2
    EXPORTING
    #1 = gv_line_cntr
    #2 = 1.
    CALL METHOD OF gs_excel 'Range' = gs_cells
    EXPORTING
    #1 = gs_cell1
    #2 = gs_cell2.
    CALL METHOD OF gs_cells 'Select' .
    CALL METHOD OF gs_activesheet 'Paste' .
    ENDDO .
    *Step 11 Free OLE objects to deallocate memory.
    *Code Part C.11 Deallocating the memory
    *--Deallocating memory
    FREE: gs_excel, gs_wbooklist, gs_application, gs_wbook,
    gs_activesheet,gs_sheets, gs_newsheet, gs_cell1,
    gs_cell2, gs_cells, gs_range, gs_font, gs_interior,
    gs_columns, gs_charts, gs_chart, gs_charttitle,
    gs_charttitlechar, gs_chartobjects .

  • Using Extract to create AVI produces flickering

    I have an application where I would like to view the image live on the screen but then at will be able to record an AVI for a period of time. I have used a buffer setup to minimize resources (as this is a part of a bigger control system). My problem is when I initiate the avi loop, I create a file and then continue with the recording, what happens is there will be flickering at the begining and then it quits. Attached is an example of what I an trying to do.
    Attachments:
    AVI_Example.vi ‏106 KB

    Terry,
    Your biggest problem is that you are using the loop index to select which frame to display. The vision acquisition is going to run much faster than the AVI creation, so you won't be able to keep up with it. Whenever the acquisition laps the AVI creation, you will get a jump in the image. If instead you use Status to get the last valid frame, you can always be displaying the current image.
    There are a couple of solutions. If you are doing short enough loops that you can keep them all the images in memory at the same time, you can just set up a large buffer and stop acquisition after the desired time, then write the buffers to the AVI at your leisure.
    If you need to store images over a long period of time, you are going to end up losing images.
    In this case, you should use Status to find out what the last valid frame is, and write it to the AVI. You probably will want to figure out how long the AVI takes, and select images that are equally spaced. You could use the skipcount when setting up the buffer so that the acquisition becomes slower than the AVI.
    Bruce
    Bruce Ammons
    Ammons Engineering

  • Quick and Dirty Tree Mapping

    Hi, i'm trying to do a quick and simple mapping for categories.
    Something like...
    Vector v = new Vector();
    v = PatriotmemDB.getFAQCategories();
    FAQCategoryObj catObj = null;
    String catname = null;
    int catid = 0;
    int parent = 0;
    int counter = 0;
    int prev = 0;
    Vector catTree = new Vector();
    for(int j=0;j<v.size();j++) {
    catObj = (FAQCategoryObj)v.elementAt(j);
    parent = catObj.getCatID();
    if(parent == counter) {
    if(counter == prev) {
    catTree.elementAt(counter).add(catObj);
    } else {
    catTree.elementAt(counter) = new Vector();
    catTree.elementAt(counter).add(catObj);
    } else {
    counter++;
    I know this will give an error but basically break out each parent in separate Vectors so that when i loop through them i can test and show in a select list. My table retuns below...
    categoryid catname catdesc imglink order parent
    1 DRAM DRAM NULL 0 0
    2 Solid State Drives Solid State Drives NULL 0 0
    3 USB Flash Drives USB Flash Drives NULL 0 0
    4 Peripherals Peripherals NULL 0 0
    5 Torqx Torqx NULL 0 2
    6 Zephyr Zephyr NULL 0 2
    7 Xporter XT Boost Xporter XT Boost NULL 0 3
    8 Xporter Razzo Xporter Razzo NULL 0 3
    Where the parent is the last column.
    Thanks for your help

    OK, so you have a tree, and you want to product these kind of weird vector slices of the tree, presumably as input to something else.
    How is the tree implemented? It looks like a vector of some class, in which the tree structure is implicit in the relationship of some fields of the class, but not an actual tree (composed of nodes, with directed edges between the nodes, no cycles, and a single node is identified as root). Right?
    If so, I can imagine one way to do it would be to create a Map<Integer, Vector<TheClass>> Loop through the vector, looking at each class, get the parent reference (which I take to be an integer from your example), and then look up in the map the vector identified for that integer. (If it doesn't exist, create it and add it to the map.) Then add the given class to that vector. When you're done, take the values set from the map.
    If you have an actual explicit formal tree, then I'd suggest writing a simple recursive function to span it.
    By the way, Vector is kind of long in the tooth. The more canonical List implementations these days are ArrayList or LinkedList.

  • Please help me locate motherboard documentation and diagram

    I have purchased a Lenovo IdeaCentre K320-30192GU. For some strange reason, none of the manuals and none of the info on the Lenovo support site make any reference whatsoever to the motherboard. After a long session with the tech person at Lenovo support I was told that no information could be given to me that wasn't already on that site. (I have never owned a computer for which this information was not available.)  I would like to know the motherboard's ID and a documentation source. Some posts made reference to an app that would identify the processor, but this is not what I want. Any help would be very much appreciated.

    Nevermind, I thought(hoped) there were going to be some videos, but I think it may mean:
    the text from the disclosure triangles.  I feel dumb, oh well...
    ES2 Tutorial:  Creating Sounds
    ES2 Sound Design from Scratch, Filter Settings, Digiwaves 
    Creating Fat ES2 Sounds with Oscillator Detuning and Unison Mode
    Creating Detuned Monophonic Sounds and Effects with the ES2
    Creating Clean Single-Oscillator Bass Sounds with the ES2
    Creating Distorted Analog Basses with the ES2
    Using FM Intensity and Frequency to Create ES2 Sounds
    Controlling ES2 FM Intensity with an Envelope and FM Scaling
    Using FM Drive and Filter FM to Change the Color of ES2 Sounds
    Creating FM Sounds with Digiwaves in the ES2
    Creating FM Sounds with Wavetables in the ES2
    Creating Distorted ES2 FM Sounds with Monophonic Unison
    Creating FM Sounds with Unusual Spectra in the ES2
    Setting Pulse Width Modulations with Oscillator 2 in the ES2
    Creating ES2 String Sounds with Pulse Width Modulation
    Creating Sounds with Ring Modulation in the ES2
    Creating Sounds with Oscillator Synchronization in the ES2
    Getting Started with Vector Synthesis in the ES2
    Using the Planar Pad for Vector Synthesis in the ES2
    Using Vector Synthesis Loops in the ES2
    Creating ES2 Bass Drum Sounds with a Self-Oscillating Filter and the Vector Envelope
    Creating Percussive ES2 Synthesizer and Bass Sounds with Two Filter Decay Phases

  • Navigation Blur Effect

    I am using a movie clip prototype (see below) to blur my
    navigation when the user rolls over it. It works, but i would like
    for it to just blur once, then go back to being clear, all while
    the mouse is over it. Any suggestions?
    Thank you :0)

    the main problems with the previous code were:
    1. you were (trying to) repeatedly calling blurMC (with
    myNavMC.onEnterFrame) and that's not necessary. blurMC creates a
    loop to gradually (actually pretty quickly) blur the movieclip.
    2. the loop in blurMC never ends. for each movieclip to which
    it's applied it initiates an onEnterFrame loop that never
    terminates.
    3. the loop blurMC started was applied to the movieclip
    itself. if the movieclip already had an onEnterFrame loop defined,
    blurMC would replace that loop breaking your code elsewhere.
    (though this worked to your advantage with your original code where
    myNavMC.onEnterFrame would have caused the flash player to go into
    an endless loop and crash if it weren't replaced.)

Maybe you are looking for

  • Slow down Database after upgrading to 10.2.0.5

    Hi I am having performance problems after upgrading to 10.2.0.5 At the beginning I thought the problem was sga too smalle ( ini: 598M , now 1408M ) but even after recreating the database with the new value the problem remains. I am sending reports so

  • When to use WEb Dynpro application and Portal application in NW dev studio

    I would like to know what is the difference between webdynpro application  and EP Application using PDK. Are they comaparable  ...Which one has an edge over the other specific to any applications. I want develop an application related to e-commerce u

  • MSI GE60 2OE, upgraded to windows 8.1, now back at 8.0

    Bought my son a laptop and added all the games and what not that he likes, as well I updated the OS to Windows 8.1.  All of this went well, and the laptop worked fine, but I ran in to an issue that I just couldn't live with. At home I have a WHS2011

  • How to make sure all the apex pages open up in new tab (or) new windows ?

    - Lets say I create an Apex application in 4.0.2 with 10 pages. - Now I wanted to check if there is some property in the Apex Admin or some settings which control this: 1) anything you click on application, either a page,field- it needs to open in a

  • Excess stock in SAP.

    Hi , For operational purpose ,we are maintaining excess stock process, below is the formula for the same, Opening stock- (Backlog order +current month order (n)+N+1 order . Can we get this type of report from SAP ? Regards,   Vijesh