A better way to execute a series of external commands?

Hi,
Consider the code snippet...
Process proc1 = rt.exec("Some external command");
Vector vecOutput = outputGobbler.getOutput() ;
String[] strAlterCmds = new String[vecOutput.size()];
for ( int k = 0 ; k < vecOutput.size() ; k++ )
strAlterCmds[k] = new String();
strAlterCmds[k] = "cmd.exe /c blah.... " +(String) vecOutput.elementAt( k )+ " ;
Process proc2 = rt.exec(strAlterCmds[k], null);
StreamGobbler errorG = new
StreamGobbler( proc2.getErrorStream(), "Error") ;
StreamGobbler outputG = new
StreamGobbler( proc2.getInputStream(), "Output") ;
errorG.start() ;
outputG.start() ;
int exitVal1 = proc2.waitFor();
The second part of the execution is taking AGES and I am not sure forking a new process for runtime execution is the best alternative here.
I would be glad if someone can point me to a smarter solution.
In short: I intend to execute a series of commands using RTE depending on the values I get in the loop.
Thanks.

Jared,
Thank you for responding to my posted message. Rendezvous is a new concept to me, maybe
it's the solution to my problem. I have been trying to read the on line manual and
example VIs from National Instruments website. I still have a hard time to understand
the concept.
One of the example I saw is using rendezvous to run some sub VIs. But in my case, I have
only one VI that is a while loop. Inside the while loop, there are a few tasks running
simultaneously. I don't know whether it will serve my purpose.
Guangde Wang
Jared O'Mara wrote:
> Guangde,
>
> Referring to your 2nd method, use rendezvous (under advanced>>synchronize
> on function palette) to synchronize two processes. There are good examples
> that come with labview. basically, you cre
ate a rendezvous, giving it a
> size. Using the wait on rendezvous vi, a function will not continue until
> all rendezvous have reached that point. Using this method, you can synchronize
> your 2 while loops.
>
> Jared
>
> Guangde Wang wrote:
> >I tried two ways to control the tempo of my program.>>One is to use the
> While Loop's counter and a wait. The drawback of this>method is the cycle
> length is dependent on the measuring load. So if the>program runs for days,
> it will be significent off the real time.>>The other way is to use the difference
> of the Tick Count. It provides>accurate timing but the problem is the sychronization
> of the clock cycle>and the While Loop cycle. I can try to put a little bit
> wait but still>can not sychronize them very well. So after a while, there
> will be two>measures get together.>>I don't know whether there are some better
> ways to control the program>or whether we have some ways to improve either
> or both of the above
two>methods to make them work better. Please let me
> know if you have any>suggestion.>>Thank you in advance,>>Guangde Wang>

Similar Messages

  • Can some one tell me a better way...

    Hi All..
    I work on a web application. I create user ids for people logging into my application. here I have a small problem.. This is what I am currently doing...
    When I create a new user, I assign a new user id to the user and store all hi info.
    All our user ids are stored in User_ID table and user info in User_Info table.
    First I get the max user id from the User_Id table.
    int iuserid = select max(User_ID) from User_ID;
    Then I add ' 1 ' to this and assign it to new user.
    iuserid = iuserid+1;
    insert into User_id values(iuserid, <ssn> );
    Then I store all user info in User_info table..
    insert into User_info(iuserid, <first_name>, <last_name>,...);
    Both these SQLs are executed as a transaction.
    The problem that I have...
    It works fine in a normal environment and in my testing.
    But when the load inceases, before I insert into the User_info, another user tries to get the max User_id from User_ID table, then it conflicts..
    I have seen occurences of User_Info storing the info of a different user against the User_id when many people are accessing the app at the same time.
    Can some one tell me a better way to handle this scenario..
    Appreciate all you help..
    TIA..
    CK

    Hi,
    assuming that the requirement for user_id is only for uniqueness (primary key requirement) not continuosly.
    perhaps can try this,
    1) create a table to keep the max id for each table's key.
    e.g.
    create table key_id_lookup
    key_name char(n),
    current_value number(m)
    where n & m is the size of the field
    2) for each creation of entry in the user_id table, lookup the value in the key_id_table and increment it after retrieval.
    e.g. current_id = select current_value from key_id_lookup where key_name = 'user_id_key';
    current_id+=1;
    update key_id_lookup set current_value = current_id where key_name = 'user_id_key';
    something similar to use of sequence if your database support it.
    3) continue with the creation of record in other tables. now obtain the time stamp of creation and append with the current_id obtained. e.g. timestamp = 132456872; size of m is 5, user_id = 132456872 x 100000 + current_id;
    this should give you a unique key at creation time.
    There should be other better ways of resolving this(like locking the table for the update operation but affect performance, etc), depending on the feature supported by the database in use.
    Hope this can help as last resort if other options not available.

  • A better way to activate an LOV

    I want to allow users to activate the LOVs and run queries from them without having to press the enter query button, then move their cursor to the appropriate text box, then press Ctrl+L, then press the execute query button. Is there some way to fire an LOV from a button press or some simpler way than I have right now?

    Thats really a good way.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Steven Lietuvnikas ([email protected]):
    i follow what you're saying but i think i found a better way to do it
    i made a button that says search on it and the whenbuttonpressed trigger is simply enter_query
    this then moves the focus to the first item in the record block
    i then made a whennewiteminstance trigger on the first item in the record block that says:
    DECLARE
    DUMMY BOOLEAN;
    BEGIN
    If (:system.Mode = 'ENTER-QUERY') Then
    DUMMY := SHOW_LOV('LOV_PERSONS',15,10);
    EXECUTE_QUERY;
    END IF;
    END;
    this works good<HR></BLOCKQUOTE>
    null

  • A better way to poll

    When my Start button is clicked it changes a member variable from false to true.
    Here is a simplified version of my code:
    public class gdvdhomevideo
       private boolean blnBegin;
       public static void main(String[] args)
          while(blnBegin == false){}
          //perform operations
       public void actionPerformed(ActionEvent e)
          String command = e.getActionCommand();
          if(command.equals("Start"))
             blnBegin = true;
    }So when the user clicks start it exits the while loop and the program starts performing other functions. The problem is that this approach is 100% CPU intensive and I know that there must be a better way?

    1) Code executed in the main() is NOT running on the event thread. Don't do any GUI code from the main thread... You know, stuff like showing windows, attaching event listeners etc.. You need to wrap all that stuff in a Runnable and pass that Runnable to SwingUtilities.invokeLater().
    2) Assuming the stuff you're doing in the main() is actually thread safe and doesn't touch the GUI, you can simply startup a new Thread and put your code in there. (see below)
    3) You class name is named badly. Please check out sun's java coding conventions. It is very nice to have coding conventions. Use them! ;-)
    4) if you want to setup your program as a loop rather than simply relying on user actions to fire events, then I'd suggest you use a timer that notifies on the event thread every X where X is a non-zero polling interval. I think there's a class is called SwingTimer that does this sort of thing for you.
    What you're attempting to do is non-trivial.. so.. ummm.. have fun..
    public class gdvdhomevideo
       private boolean blnBegin;
       public static void main(String[] args) throws Exception
            SwingUtilities.invokeLater( new Runnable() {
                  public void run() {
                       //setup stuff in here.
       public void actionPerformed(ActionEvent e)
          String command = e.getActionCommand();
          if(command.equals("Start"))
             new Thread(new Runnable() {
                public void run() {
                     //perform operations but don't touch the GUI.
              }.start();
    }

  • A better way to run .FMX from hyperlink

    Dear all,
    I am finding ways to execute .FMX from hyperlink in HTML. I tried to create a shortcut file (.LNK) that runs the .FMX and then using a hyperlink to refer that shortcut file. However, the browser prompts me for whether to run or to save the file every time. How can I suppress the dialog or is there any better way to do so?
    Regards,
    Derek.

    How you created a shortcut file(.LNK)
    How to call a form within a form using Hyperlink
    I am new to Java and could anybody help.

  • A better way to do this ?

    where does the sql stuff excute in the following stored procedure, directly in the database or it goes through the oracle VM first ?
    CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "CustomExport" AS
    import javax.sql.Connection;
    import oracle.jdbc.OracleDriver;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    public class CustomExport
    public void do() throws SQLException{
    OracleDriver oracle = new OracleDriver();
    DriverManager.registerDriver(oracle);
    Connection conn = oracle.defaultConnection();
    PreparedStatement st = conn.prepareStatement("select from table where col=?");
    st.setString(1,"value");
    ResultSet rs = st.execute();
    and is there a better way to read and parse an xml document with PL/SQL.what i've read about is the ability to parse an XML file to load its data directly into a database table.What i was looking for was just a way to parse XML without having to load any data into tables so i did it with java.
    CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "CustomParser" AS
    import javax.xml.prasers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;
    import org.xml.sax.Attributes;
    import org.xml.sax.InputSource;
    import org.xml.sax.SAXException;
    import org.xml.sax.helpers.DefaultHandler;
    public class CustomParser
    private static CustomParseHandler handler = new CustomParseHandler();
    public static void parseXMLFile(String fileName) throws FileNotFoundException,IOException,SAXException
    SAXParserFactory saxFactory = SAXParserFactory.newInstance();
    SAXParser parser=saxFactory.newSAXParser();
    parser.parse(new FileInputStream(fileName)),handler);
    private class CustomParseHandler extends DefaultHandler{
    StringBuffer buff;
    public CustomParseHandler()
    this.buff = new StringBuffer();
    public void startElement (String uri, String localName,
    String qName, Attributes attributes)
    throws SAXException
    buff.append("<").append(qName).append(">");
    public void endElement (String uri, String localName, String qName)
    throws SAXException
    buff.append("</").append(qName).append(">").append(newLine);
    public void characters (char ch[], int start, int length)
    throws SAXException
    String fieldName = new String(ch,start,length);
    if(fieldName==null || "".equals(fieldName.trim()))
    return;
    public void clearBuffer(){
    buff.delete(0, buff.length());
    public String getXMLString(){
    return buff.toString();
    }

    PLSQL does not go through Java to access the database. The actual access to the database is via the same mechanism for both, so in some sense, both perform about the same. However, PLSQL datatypes have the same representation as database datatypes so there is no conversion. Java datatypes have different representations than database datatypes so there is a conversion cost associated with moving data between Java and the database.
    If your processing is simple and you are moving a lot of data, PLSQL is likely the better choice. If your processing is more complex and you are moving less data, Java is likely the better choice. There are other things such as portability you should consider, but the amount of data and complexity of the code are the first considerations.
    Douglas

  • Must be a better way...

    Hello Flash Community!
    Thanks in advance for any help/advice.
    So, what I'm looking for here is some high level advice as far as a better way to do things. I feel like so often with programming I'm just breaking my neck to get things working when I know there is a better way (presumably based in OOP) to go about things. I just need someone to look at what I've done and point it out to me.
    So, here's what I've done so far: http://www.catherinemix.com
    And it works pretty well as far as I'm concerned! The app dynamically loads as many images as my client (my mom ) puts on the server, resizes them dynamically, adds L/R arrow buttons dynamically based on how many images are involved, etc... But the downside to all that dynamic flexibility is that I haven't found a way to load the thumbnail images (and their respective full size images) one by one. Instead, I have to load them all together and keeping the user waiting that long is unacceptable to my mom. What I would love is for each thumbnail/full size combo to get its own preloader bar in the location it will eventually be embedded, but I haven't found a way to do that and account for an unknown number of images (as it is determined dynamically.)
    Any ideas here? I would specifically like to know which functions y'all use when you need to load multiple files simultaenously (AttachMovie?)
    I have posted the kluge-y code which handles all of the image gallery functions below.
    Thanks! and Be Well
    Graham
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    var wait:PleaseWait = new PleaseWait();
    wait.x = 400;
    wait.y = 50;
    addChild(wait);
    var waitFadeIn:Tween = new Tween(wait, "alpha", Regular.easeOut, 0, 1, 1, true);
    var titleText:TextField;
    var textSprite:Sprite;
    //thumbH is the ideal height for our thumbnails, and thumbW the ideal width
    var thumbH = 120;
    var thumbW = 170;
    //loadH is the ideal height for our fullsize images, and loadW the ideal width
    var loadH = 500;
    var loadW = 600;
    //some counter numbers
    var thumbNum = 1;
    var loadNum = 1;
    //some Sprites which need to be accessed by more than one function
    var darkStage:Sprite;
    var loadSprite:Sprite;
    //Let's instantiate some Arrays that we can load the images into.
    //Since Arrays of Loaders can't be copied, we have to go through the process twice.
    var thumbArray:Array = new Array();
    var loadArray:Array = new Array();
    firstLoad();
    firstThumb();
    function firstLoad():void {
        trace("firstLoad");
        var loadski = new Loader();
        loadski.load(new URLRequest("images/fulls/0.png"));
        loadski.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
        loadArray.push(loadski);
    //Starting with the above Loader, this function will execute every time the Loader completes
    function loadComplete(e:Event):void {
        trace("loadComplete");
        var loadski = new Loader();
        loadski.load(new URLRequest("images/fulls/" + loadNum + ".png"));
        loadArray.push(loadski);
        loadski.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
        loadski.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loadError);
        loadNum++;
    //Once the Loader goes too far by attempting to load an image that doesn't exist on the computer,
    //it will thorw an IOError Event at which point the following function will execute.
    function loadError(e:IOErrorEvent):void {
        trace("loadError");
        loadArray.pop();
        loadNum = 0;
        loadResize();
        //We use the pop function to remove the most recently added Loader instance, since we know it
        //contains a null reference (beacuse the IOError Event is asynchronous.)
        thumbArray.pop();
        //We reset the counter variable.
        thumbNum = 0;
        //Add the little arrows that allow the user to click to see more thumbnails (if there are more
        //than 8 images on the server.)
        removeChild(wait);
        addArrows();
        //Let's resize the images to thumbnail size and add them to the display list.
        thumbResize();
        addClickOnThumb();
    function loadResize():void {
        trace("loadResize");
        for (var ex = 0; ex < loadArray.length; ex++) {
            //If the width of the image is greater than the ideal width, OR the height is greater than the ideal height...
            if ( loadArray[loadNum].content.width > loadW || loadArray[loadNum].content.height > loadH) {
                //And if the width of the image is greater than the height, apply Scaler 1...
                if ( loadArray[loadNum].content.width > loadArray[loadNum].content.height ) {
                    //Scaler 1 is the ratio of the ideal width to the image width
                    var scaler1 = loadW / loadArray[loadNum].content.width;
                    trace(loadNum + " load scaler 1: " + scaler1);
                    //Apply Scaler 1 to both the width and height of the image
                    loadArray[loadNum].content.scaleX = loadArray[loadNum].content.scaleY = scaler1;
                    //Otherwise, apply Scaler 2
                } else {
                    //Scaler 2 is the ratio of the ideal width to the image height
                    var scaler2 = loadH / loadArray[loadNum].content.height;
                    trace(loadNum + " load scaler 2: " + scaler2);
                    //Apply Scaler 2 to both the width and height of the image
                    loadArray[loadNum].content.scaleX = loadArray[loadNum].content.scaleY = scaler2;
                    trace("loadArray[loadNum].content.height = " + loadArray[loadNum].content.height);
                    trace("loadArray[loadNum].content.width = " + loadArray[loadNum].content.width);
                //Otherwise... (that is, the image width and height are in both cases less than the ideal)
            } else {
                //And if the width of the image is greater than the heigh, apply Scaler 3
                if ( loadArray[loadNum].content.width > loadArray[loadNum].content.height ) {
                    //Scaler 3 is the ratio of the ideal width to the image width
                    var scaler3 = loadW / loadArray[loadNum].content.width;
                    trace(loadNum + " load scaler 3: " + scaler3);
                    //Apply Scaler 3 to both the width and height of the image
                    loadArray[loadNum].content.scaleX = loadArray[loadNum].content.scaleY = scaler3;
                } else {
                    //Scaler 4 is the ratio of the ideal width to the image height
                    var scaler4 = loadH / loadArray[loadNum].content.height;
                    trace(loadNum + " load scaler 4: " + scaler4);
                    //Apply Scaler 4 to both the width and height of the image
                    loadArray[loadNum].content.scaleX = loadArray[loadNum].content.scaleY = scaler4;
            loadArray[loadNum].content.x = - (loadArray[loadNum].content.width / 2);
            loadArray[loadNum].content.y = - (loadArray[loadNum].content.height / 2);
            loadNum++;
    function firstThumb():void {
        trace("firstThumb");
        //Let's populate the first Array with Loaders that load the images Mom has put on the server.
        //We have to do this first Loader object by hand to get the Event.COMPLETE-based-loop going.
        var thumbski = new Loader();
        thumbski.load(new URLRequest("images/thumbs/0.png"));
        thumbski.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbComplete);
        //We add the MouseEvent.CLICK listener to the actual Loader instance so that, later on, in the
        //function enLarge, we can make use of the currentTarget parameter to correlate the Array index of
        //the thumbnail that the user is clicking on with that of the loadArray.
        thumbski.addEventListener(MouseEvent.CLICK, enLarge);
        thumbArray.push(thumbski);
    //Starting with the above Loader, this function will execute every time the Loader completes
    function thumbComplete(event:Event):void {
        trace("thumbComplete");
        var thumbski = new Loader();
        thumbski.load(new URLRequest("images/thumbs/" + thumbNum + ".png"));
        thumbski.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbComplete);
        //We add the IOErrorEvent listener so that as soon as this error is thrown, we will exit this loop
        //and proceed to the next logical step in the program can be taken.
        thumbski.addEventListener(MouseEvent.CLICK, enLarge);
        thumbArray.push(thumbski);
        thumbNum++;
    function addArrows():void {
        //Let's determine how many batches there are. A batch is the minimum amount of thumbnail images
        //mom wants to show up onscreen at a time. In this case, she has decided on 8.
        var batches =  Math.ceil(thumbArray.length / 8);
        //The variable m is part of a kluge fix related to the calculation of startX (explained below.)
        var m = 0;
        //Pseudocode for this loop: If there are at least two batches, then...
        //We do this because less than 2 batches doesn't warrant arrows
        if (batches > 1) {
            for (var k = 1; k < batches; k++) {
                //triW is the desired width of our arrows
                var triW = 20;
                //startX is the x position of the start of our rightward facing triangle(s)
                //The formula says: Our x starting position should be a triangle width shy of the
                //far edge of the stage (multiplying it by k ensures it happens as many times
                //as there are batches, which is why we intialize k = 1.) Every subsequent iteration
                //of the formula has to add a triangle's width worth of distance, except for the
                //very first one, which is why it is multiplied by m, which is initially set to 0.
                var startX = (((stage.stageWidth - triW) * k) + (triW * m));
                //We want the arrows to sit perfectly between the two rows of thumbnails. Since the
                //max height of every thumbnail is thumbW, that would seem to be the natural choice
                //for the starting y position of the arrows. But, we actually have to use thumbW/2
                //because the thumbnails have already been offset by half of thumbW due to being
                //aligned vertically with each other.
                var startY = (thumbW / 2);
                //This is the rightward facing triangle
                var tri:Sprite = new Sprite();
                tri.graphics.beginFill(0xFFFFFF);
                tri.graphics.moveTo(startX, startY);
                tri.graphics.lineTo(startX, (startY + triW));
                tri.graphics.lineTo((startX + triW), (startY + (triW/2)));
                tri.graphics.lineTo(startX, startY);
                tri.graphics.endFill();
                tri.buttonMode = true;
                tri.useHandCursor = true;
                tri.addEventListener(MouseEvent.CLICK, moveLeft);
                addChild(tri);
                //This is the leftward facing triangle
                var tri2:Sprite = new Sprite();
                var startX2 = (startX + (triW * 2));
                tri2.graphics.beginFill(0xFFFFFF);
                tri2.graphics.moveTo(startX2, startY);
                tri2.graphics.lineTo(startX2, (startY + triW));
                tri2.graphics.lineTo((startX2 - triW), (startY + (triW / 2)));
                tri2.graphics.lineTo(startX2, startY);
                tri2.graphics.endFill();
                tri2.buttonMode = true;
                tri2.useHandCursor = true;
                tri2.addEventListener(MouseEvent.CLICK, moveRight);
                addChild(tri2);
                //Increase m (see above)
                m++;
    //This function moves the entire Gallery MovieClip to the left 800 pixels.
    function moveLeft(event:MouseEvent):void {
        var leftTween:Tween = new Tween(this, "x", Regular.easeOut, this.x, (this.x - 800), .5, true);
    //This function moves the entire Gallery MovieClip to the right 800 pixels.
    function moveRight(event:MouseEvent):void {
        var rightTween:Tween = new Tween(this, "x", Regular.easeOut, this.x, (this.x + 800), .5, true);
    //This function resizes the loaded images to the desired thumbnail dimensions and adds them
    //to the display list.
    function thumbResize():void {
        //The highest level of organization of thumbnails is the batch. There are only as many batches
        //as the length of the thumbArray divided by 8 (the max amount of thumbnails in a batch, as determined
        //by mom.)
        for (var batch = 0; batch < Math.ceil(thumbArray.length / 8); batch++) {
            trace("batch " + batch);
            //This Sprite serves as the container that we use to position entire batches
            var batchSprite: Sprite = new Sprite();
            //The logic behind setting the x position of the batchSprite to 800 x batch should be self-evident --
            //we want each new batch to be 800 pixels to the right of the former one -- but the addition of (thumbW
            //divided by 1.5) is a kluge fix for how much space to give the batches on left margin.
            batchSprite.x = (thumbW / 1.5) + (batch * 800);
            addChild(batchSprite);
            //The second highest level of organization for our thumbnails is the row. Our grid of thumbnails is
            //two rows deep.
            for (var row = 0; row < 2; row++) {
                trace("     row " + row);
                //The third highest level of organization for our thumbnails is the column. Our grid of thumbnails is
                //four columns deep.
                for (var col = 0; col < 4; col++) {
                    trace("          col " + col);
                    trace("               thumb " + thumbNum);
                    if (thumbNum < thumbArray.length) {
                        //The following is the logic structure for handling the resizing of images. The goal was to develop
                        //a system robust enough to allow my mom to put whatever size images she wanted on the server and the
                        //app would use them. The logic is explained at each step...
                        //If the width of the image is greater than the ideal width, OR the height is greater than the ideal height...
                        if ( thumbArray[thumbNum].content.width > thumbW || thumbArray[thumbNum].content.height > thumbH) {
                            //And if the width of the image is greater than the height, apply Scaler 1...
                            if ( thumbArray[thumbNum].content.width > thumbArray[thumbNum].content.height ) {
                                //Scaler 1 is the ratio of the ideal width to the image width
                                var scaler1 = thumbW / thumbArray[thumbNum].content.width;
                                trace("               scaler1 = " + scaler1);
                                //Apply Scaler 1 to both the width and height of the image
                                thumbArray[thumbNum].content.scaleX = thumbArray[thumbNum].content.scaleY = scaler1;
                                trace("               image width:" + thumbArray[thumbNum].content.width);
                                trace("               image height:" + thumbArray[thumbNum].content.height);
                                //Otherwise, apply Scaler 2
                            } else {
                                //Scaler 2 is the ratio of the ideal width to the image height
                                var scaler2 = thumbW / thumbArray[thumbNum].content.height;
                                trace("               scaler2 = " + scaler2);
                                //Apply Scaler 2 to both the width and height of the image
                                thumbArray[thumbNum].content.scaleX = thumbArray[thumbNum].content.scaleY = scaler2;
                                trace("               image width:" + thumbArray[thumbNum].content.width);
                                trace("               image height:" + thumbArray[thumbNum].content.height);
                            //Otherwise... (that is, the image width and height are in both cases less than the ideal)
                        } else {
                            //And if the width of the image is greater than the heigh, apply Scaler 3
                            if ( thumbArray[thumbNum].content.width > thumbArray[thumbNum].content.height ) {
                                //Scaler 3 is the ratio of the ideal width to the image width
                                var scaler3 = thumbW / thumbArray[thumbNum].content.width;
                                trace("               scaler3 = " + scaler3);
                                //Apply Scaler 3 to both the width and height of the image
                                thumbArray[thumbNum].content.scaleX = thumbArray[thumbNum].content.scaleY = scaler3;
                                trace("               image width:" + thumbArray[thumbNum].content.width);
                                trace("               image height:" + thumbArray[thumbNum].content.height);
                            } else {
                                //Scaler 4 is the ratio of the ideal width to the image height
                                var scaler4 = thumbW / thumbArray[thumbNum].content.height;
                                trace("               scaler4 = " + scaler4);
                                //Apply Scaler 4 to both the width and height of the image
                                thumbArray[thumbNum].content.scaleX = thumbArray[thumbNum].content.scaleY = scaler4;
                                trace("               image width:" + thumbArray[thumbNum].content.width);
                                trace("               image height:" + thumbArray[thumbNum].content.height);
                        //Here is where we center the images vertically...
                        thumbArray[thumbNum].content.x = - (thumbArray[thumbNum].content.width / 2);
                        //Here is where we center the images horizontally...
                        thumbArray[thumbNum].content.y = - (thumbArray[thumbNum].content.height / 2);
                        //Before placing them in their own container Sprite, so that their relative positions can be
                        //determined accurately (a task that would've been otherwise impossible after the
                        //adjustments to position made above.)
                        var thumby = new MovieClip();
                        thumby.addChild(thumbArray[thumbNum]);
                        //thumbW being the max possible length or width of any one thumbnail (this was done for visual
                        //consistency and codified in the logic tree above), placing two thumbnails thumbW
                        //apart (measuring from center point in either case) will put them edge to edge at best. This is why
                        //we add (thumbW / 8) as additional spacing.
                        thumby.y = (row * (thumbW + (thumbW / 8)));
                        thumby.x = (col * (thumbW + (thumbW / 8)));
                        thumby.buttonMode = true;
                        thumby.useHandCursor = true;
                        var fA:Array = new Array();
                        var dS:DropShadowFilter = new DropShadowFilter(5, 45, 0x000000, 0.33, 5, 5, 1, 1);
                        fA.push(dS);
                        thumby.filters = fA;
                        trace("thumby.width = " + thumby.width);
                        trace("thumby.height = " + thumby.height);
                        batchSprite.addChild(thumby);
                        thumbNum++;
    function enLarge(event:MouseEvent):void {
        var indexNum:Number = new Number();
        indexNum = thumbArray.indexOf(event.currentTarget);
        trace("indexNum = " + indexNum);
        darkStage = new Sprite();
        darkStage.graphics.beginFill(0x333333, .9);
        darkStage.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
        darkStage.addEventListener(MouseEvent.CLICK, reMove);
        darkStage.buttonMode = true;
        darkStage.useHandCursor = true;
        (parent  as  MovieClip).addChild(darkStage);
        loadSprite = new Sprite();
        loadSprite.addChild(loadArray[indexNum]);
        loadSprite.x = (stage.stageWidth / 2);
        loadSprite.y = (stage.stageHeight / 2);
        loadSprite.addEventListener(MouseEvent.CLICK, reMove);
        loadSprite.buttonMode = true;
        loadSprite.useHandCursor = true;
        loadSprite.mouseEnabled = false;
        (parent  as  MovieClip).addChild(loadSprite);
        var urlRequest:URLRequest = new URLRequest("xmls/" + indexNum + ".xml");
        var titleURL:URLLoader = new URLLoader();
        titleURL.addEventListener(Event.COMPLETE, completeListener);
        titleURL.load(urlRequest);
        function completeListener(event:Event):void {
            titleText = new TextField();
            titleText.autoSize = TextFieldAutoSize.LEFT;
            var myFont:Font = new BOF();
            var ttFormat:TextFormat = new TextFormat();
            ttFormat.color = 0xFFFFFF;
            ttFormat.size = 18;
            ttFormat.font = myFont.fontName;
            textSprite = new Sprite();
            textSprite.addChild(titleText);
            (parent  as  MovieClip).addChild(textSprite);
            var titleXML:XML = new XML(titleURL.data);
            titleText.text = titleXML.toXMLString();
            titleText.setTextFormat(ttFormat);
            titleText.embedFonts = true;
            textSprite.y = 570;
            textSprite.x = ((stage.stageWidth / 2) - (titleText.textWidth / 2));
            textSprite.mouseEnabled = false;
            titleText.mouseEnabled = false;
    function reMove(event:MouseEvent):void {
        (parent  as  MovieClip).removeChild(textSprite);
        (parent  as  MovieClip).removeChild(loadSprite);
        (parent  as  MovieClip).removeChild(darkStage);
    function addClickOnThumb():void {
        var cot:ClickOnThumbnail = new ClickOnThumbnail();
        cot.x = 400;
        cot.y = 583;
        (parent  as  MovieClip).addChild(cot);

    Hey Jim
    Wow, that's great; thanks! Can I ask what settings you used to get the files so small?
    Yes, I am familiar with Photoshop and image optimization issues, but I didn't realize that PNG was so much bigger than JPG and that I had so much file size I could shed before I would notice a degradation in image quality. Your advice will certainly help greatly, and I will certainly apply it to the thumbs as well. I think my mom will be very pleased.  : )
    I look forward to hearing what collection of settings you used.
    Thanks and Be Well
    Graham

  • Is there a better way to generate custom timed digital Signals

    I am trying to generate digital output of high and lows with particular delays on different lines. Each daq assistant is activating single line on a port on USB 6501. There more complex high and lows that I need to generate with variable time difference between high and low. There is codebelow which accomplishes what I am trying to achieve but for executing a long pattern of high and low signal is very time consuming to do this way. I am sure there is a better way to do this, I  not a expert on labview so I haven't uncovered its full potential. Can anybody suggest a more effective and a quick way to do this. I would hgihly appreciate. Thanks!
    I have not shown in the code below but through DAQ assistant I have initialized lines to low level logic.
    Solved!
    Go to Solution.

    See the attached file
    Attachments:
    Digital Signal.vi ‏335 KB

  • Better way to do this

    When selecting into a variable, is there a better way to do this? I want to make sure I don't get an error if there are no rows found. I think it's inefficient to count the number of occurrences before selecting into the variable. Can I use %NOROWSFOUND or something similar? If so, can you please provide an example? Thanks, Margaret
    Tzi := null;
    SELECT count(BUSINESS_tz)
    INTO Tzi_cnt
    FROM BUSINESS O
    WHERE ID = Fac_id AND BUSINESS_type = 'Store' AND O.Business_seq = (SELECT Business_seq
    FROM Org_lookup
    WHERE Store_seq = 0);
    IF Tzi_cnt > 0
    THEN
    SELECT BUSINESS_tz
    INTO Tzi
    FROM BUSINESS O
    WHERE ID = Fac_id AND BUSINESS_type = 'Store' AND O.Business_seq = (SELECT Business_seq

    the proper way to do this is to use an exception block;
    so
    begin
    Tzi := null;
    SELECT BUSINESS_tz
    INTO Tzi_cnt
    FROM BUSINESS O
    WHERE ID = Fac_id AND BUSINESS_type = 'Store' AND O.Business_seq = (SELECT Business_seq
    FROM Org_lookup
    WHERE Store_seq = 0);
    exception
    when no_data_found
    then
       null;   -- put any code to execute here or raise exception
    end;you can also use sql%rowcount to find out how many rows your sql statement affected:
    eg directly after your sql and before any rollback or commit
    declare
    v_rowcount number;
    begin
    insert into <table_name>
    select * from <other_table>;
    v_rowcount := sql%rowcount;
    end;

  • Is there a better way to do this projection/aggregate query?

    Hi,
    Summary:
    Can anyone offer advice on how best to use JDO to perform
    projection/aggregate queries? Is there a better way of doing what is
    described below?
    Details:
    The web application I'm developing includes a GUI for ad-hoc reports on
    JDO's. Unlike 3rd party tools that go straight to the database we can
    implement business rules that restrict access to objects (by adding extra
    predicates) and provide extra calculated fields (by adding extra get methods
    to our JDO's - no expression language yet). We're pleased with the results
    so far.
    Now I want to make it produce reports with aggregates and projections
    without instantiating JDO instances. Here is an example of the sort of thing
    I want it to be capable of doing:
    Each asset has one associated t.description and zero or one associated
    d.description.
    For every distinct combination of t.description and d.description (skip
    those for which there are no assets)
    calculate some aggregates over all the assets with these values.
    and here it is in SQL:
    select t.description type, d.description description, count(*) count,
    sum(a.purch_price) sumPurchPrice
    from assets a
    left outer join asset_descriptions d
    on a.adesc_no = d.adesc_no,
    asset_types t
    where a.atype_no = t.atype_no
    group by t.description, d.description
    order by t.description, d.description
    it takes <100ms to produce 5300 rows from 83000 assets.
    The nearest I have managed with JDO is (pseodo code):
    perform projection query to get t.description, d.description for every asset
    loop on results
    if this is first time we've had this combination of t.description,
    d.description
    perform aggregate query to get aggregates for this combination
    The java code is below. It takes about 16000ms (with debug/trace logging
    off, c.f. 100ms for SQL).
    If the inner query is commented out it takes about 1600ms (so the inner
    query is responsible for 9/10ths of the elapsed time).
    Timings exclude startup overheads like PersistenceManagerFactory creation
    and checking the meta data against the database (by looping 5 times and
    averaging only the last 4) but include PersistenceManager creation (which
    happens inside the loop).
    It would be too big a job for us to directly generate SQL from our generic
    ad-hoc report GUI, so that is not really an option.
    KodoQuery q1 = (KodoQuery) pm.newQuery(Asset.class);
    q1.setResult(
    "assetType.description, assetDescription.description");
    q1.setOrdering(
    "assetType.description ascending,
    assetDescription.description ascending");
    KodoQuery q2 = (KodoQuery) pm.newQuery(Asset.class);
    q2.setResult("count(purchPrice), sum(purchPrice)");
    q2.declareParameters(
    "String myAssetType, String myAssetDescription");
    q2.setFilter(
    "assetType.description == myAssetType &&
    assetDescription.description == myAssetDescription");
    q2.compile();
    Collection results = (Collection) q1.execute();
    Set distinct = new HashSet();
    for (Iterator i = results.iterator(); i.hasNext();) {
    Object[] cols = (Object[]) i.next();
    String assetType = (String) cols[0];
    String assetDescription = (String) cols[1];
    String type_description =
    assetDescription != null
    ? assetType + "~" + assetDescription
    : assetType;
    if (distinct.add(type_description)) {
    Object[] cols2 =
    (Object[]) q2.execute(assetType,
    assetDescription);
    // System.out.println(
    // "type "
    // + assetType
    // + ", description "
    // + assetDescription
    // + ", count "
    // + cols2[0]
    // + ", sum "
    // + cols2[1]);
    q2.closeAll();
    q1.closeAll();

    Neil,
    It sounds like the problem that you're running into is that Kodo doesn't
    yet support the JDO2 grouping constructs, so you're doing your own
    grouping in the Java code. Is that accurate?
    We do plan on adding direct grouping support to our aggregate/projection
    capabilities in the near future, but as you've noticed, those
    capabilities are not there yet.
    -Patrick
    Neil Bacon wrote:
    Hi,
    Summary:
    Can anyone offer advice on how best to use JDO to perform
    projection/aggregate queries? Is there a better way of doing what is
    described below?
    Details:
    The web application I'm developing includes a GUI for ad-hoc reports on
    JDO's. Unlike 3rd party tools that go straight to the database we can
    implement business rules that restrict access to objects (by adding extra
    predicates) and provide extra calculated fields (by adding extra get methods
    to our JDO's - no expression language yet). We're pleased with the results
    so far.
    Now I want to make it produce reports with aggregates and projections
    without instantiating JDO instances. Here is an example of the sort of thing
    I want it to be capable of doing:
    Each asset has one associated t.description and zero or one associated
    d.description.
    For every distinct combination of t.description and d.description (skip
    those for which there are no assets)
    calculate some aggregates over all the assets with these values.
    and here it is in SQL:
    select t.description type, d.description description, count(*) count,
    sum(a.purch_price) sumPurchPrice
    from assets a
    left outer join asset_descriptions d
    on a.adesc_no = d.adesc_no,
    asset_types t
    where a.atype_no = t.atype_no
    group by t.description, d.description
    order by t.description, d.description
    it takes <100ms to produce 5300 rows from 83000 assets.
    The nearest I have managed with JDO is (pseodo code):
    perform projection query to get t.description, d.description for every asset
    loop on results
    if this is first time we've had this combination of t.description,
    d.description
    perform aggregate query to get aggregates for this combination
    The java code is below. It takes about 16000ms (with debug/trace logging
    off, c.f. 100ms for SQL).
    If the inner query is commented out it takes about 1600ms (so the inner
    query is responsible for 9/10ths of the elapsed time).
    Timings exclude startup overheads like PersistenceManagerFactory creation
    and checking the meta data against the database (by looping 5 times and
    averaging only the last 4) but include PersistenceManager creation (which
    happens inside the loop).
    It would be too big a job for us to directly generate SQL from our generic
    ad-hoc report GUI, so that is not really an option.
    KodoQuery q1 = (KodoQuery) pm.newQuery(Asset.class);
    q1.setResult(
    "assetType.description, assetDescription.description");
    q1.setOrdering(
    "assetType.description ascending,
    assetDescription.description ascending");
    KodoQuery q2 = (KodoQuery) pm.newQuery(Asset.class);
    q2.setResult("count(purchPrice), sum(purchPrice)");
    q2.declareParameters(
    "String myAssetType, String myAssetDescription");
    q2.setFilter(
    "assetType.description == myAssetType &&
    assetDescription.description == myAssetDescription");
    q2.compile();
    Collection results = (Collection) q1.execute();
    Set distinct = new HashSet();
    for (Iterator i = results.iterator(); i.hasNext();) {
    Object[] cols = (Object[]) i.next();
    String assetType = (String) cols[0];
    String assetDescription = (String) cols[1];
    String type_description =
    assetDescription != null
    ? assetType + "~" + assetDescription
    : assetType;
    if (distinct.add(type_description)) {
    Object[] cols2 =
    (Object[]) q2.execute(assetType,
    assetDescription);
    // System.out.println(
    // "type "
    // + assetType
    // + ", description "
    // + assetDescription
    // + ", count "
    // + cols2[0]
    // + ", sum "
    // + cols2[1]);
    q2.closeAll();
    q1.closeAll();

  • How to create a function with dynamic sql or any better way to achieve this?

            Hello,
            I have created below SQL query which works fine however when scalar function created ,it
            throws an error "Only functions and extended stored procedures can be executed from within a
            function.". In below code First cursor reads all client database names and second cursor
            reads client locations.
                      DECLARE @clientLocation nvarchar(100),@locationClientPath nvarchar(Max);
                      DECLARE @ItemID int;
                      SET @locationClientPath = char(0);
                      SET @ItemID = 67480;
       --building dynamic sql to replace database name at runtime
             DECLARE @strSQL nvarchar(Max);
             DECLARE @DatabaseName nvarchar(100);
             DECLARE @localClientPath nvarchar(MAX) ;
                      Declare databaselist_cursor Cursor for select [DBName] from [DataBase].[dbo].
                      [tblOrganization] 
                      OPEN databaselist_cursor
                      FETCH NEXT FROM databaselist_cursor INTO @DatabaseName
                      WHILE @@FETCH_STATUS = 0
                      BEGIN       
       PRINT 'Processing DATABASE: ' + @DatabaseName;
        SET @strSQL = 'DECLARE organizationlist_cursor CURSOR
        FOR SELECT '+ @DatabaseName +'.[dbo].[usGetLocationPathByRID]
                                   ([LocationRID]) 
        FROM '+ @DatabaseName +'.[dbo].[tblItemLocationDetailOrg] where
                                   ItemId = '+ cast(@ItemID as nvarchar(20))  ;
         EXEC sp_executesql @strSQL;
        -- Open the cursor
        OPEN organizationlist_cursor
        SET @localClientPath = '';
        -- go through each Location path and return the 
         FETCH NEXT FROM organizationlist_cursor into @clientLocation
         WHILE @@FETCH_STATUS = 0
          BEGIN
           SELECT @localClientPath =  @clientLocation; 
           SELECT @locationClientPath =
    @locationClientPath + @clientLocation + ','
           FETCH NEXT FROM organizationlist_cursor INTO
    @clientLocation
          END
           PRINT 'current databse client location'+  @localClientPath;
         -- Close the Cursor
         CLOSE organizationlist_cursor;
         DEALLOCATE organizationlist_cursor;
         FETCH NEXT FROM databaselist_cursor INTO @DatabaseName
                    END
                    CLOSE databaselist_cursor;
                    DEALLOCATE databaselist_cursor;
                    -- Trim the last comma from the string
                   SELECT @locationClientPath = SUBSTRING(@locationClientPath,1,LEN(@locationClientPath)-  1);
                     PRINT @locationClientPath;
            I would like to create above query in function so that return value would be used in 
            another query select statement and I am using SQL 2005.
            I would like to know if there is a way to make this work as a function or any better way
            to  achieve this?
            Thanks,

    This very simple: We cannot use dynamic SQL from used-defined functions written in T-SQL. This is because you are not permitted do anything in a UDF that could change the database state (as the UDF may be invoked as part of a query). Since you can
    do anything from dynamic SQL, including updates, it is obvious why dynamic SQL is not permitted as per the microsoft..
    In SQL 2005 and later, we could implement your function as a CLR function. Recall that all data access from the CLR is dynamic SQL. (here you are safe-guarded, so that if you perform an update operation from your function, you will get caught.) A word of warning
    though: data access from scalar UDFs can often give performance problems and its not recommended too..
    Raju Rasagounder Sr MSSQL DBA
          Hi Raju,
           Can you help me writing CLR for my above function? I am newbie to SQL CLR programming.
           Thanks in advance!
           Satya
              

  • Is there any better way for updating table other than this?

    Hi all, I need to update a row in the table that require me to search for it first (the table will have more than hundred thousands of row). Now, I am using a LOV that will return the primary key of the row and put that primary key to DEFAULT_WHERE property in the block and execute query command to fetch the row that need updating. This works fine except that it require 2-query-trip per update (the lov and the execute_query). Is there any better way to doing this? This update is the main objective for my application and I need to use the most effective way to do it since we need to update many records per hour.

    Thanks Rama, I will try your method. Others, how to query row instead of primary key? I thought that querying primary key is faster due to the index?
    BTW, what people do if you need to update a table using Form? I have been using the LOV then execute query since I first developing form. But I am building a bigger database recently that I start worrying about multiple query trip to dbms.
    FYI my table will have up to million rows on it. Each row will be very active (updated) within 1-2 weeks after it creation. After that it will exist for records purposes only (select only). The active rows are probably less than 1% of all the rows.

  • Is there any way to execute a custom script after JPA created tables?

    Hi
    I am looking for a way to execute some scripts right after JPA created the tables. I want the script to be executed once and not every time my application start.
    I though maybe Toplink has some extensions for this.
    Thanks.

    In general the auto-generated DDL is more for rapid prototyping, than production. If you have got to the point of defining your own DDL extensions, you may be better off outputting the auto-generated DDL to a file, and using ant or some other tool to define the schema including your extensions.
    You could do it using EclipseLink as well using a SessionCustomizer (which is an event class set in your persistence.xml). The SessionCustomizer is executed before the DDL is generated however, so you would need to remove the DDL properties from your persistence.xml and generate the DDL using an EclipseLink SchemaManager (SchemaManager.replaceDefaultTables(true, true)).
    James : http://www.eclipselink.org

  • What is the best way to import a series of still images?

    I'm trying to import a series of 300 PNG images into an existing FCP project. I've gotten the stills imported into FCP but when I place them into the timeline they are setup to be 10 seconds long and then if I change them all to 1 frame they are spread out throughout the project and lining them all up is a nightmare. Is there a better way to do this?

    Went looking for this post by Ronny Courtens on Phillip Hodgetts' blog because I thought his succinct summary of image sequences in FCP might be useful to your issue.
    Russ
    Ronny Courtens · August 7, 2013 at 2:43 am
    Frank,
    Maybe some ideas for your main work:
    1. Image sequences.
    Although the best workflow for working with image sequences is to turn them into a video clip before importing them in an NLE, you can import image sequences and work with them in FCPX. It actually takes longer to explain this than to do it (-:
    A. Import the image sequence in FCPX, group-select all the images of the sequence in the Event Browser and press ALT+G to turn the images into a Compound Clip. Set the format and frame rate for your CC. The image sequence will appear as a single compound clip in your Event Browser.
    B. Change the speed of your image sequence.
    Now here’s the rub: by default every image in the CC will have a duration of 10 seconds, which is wrong. That’s something that needs to be addressed in the way FCPX handles imported image sequences. But you can easily change the duration of the stills.
    R-click your CC and select Open in Timeline. In the timeline press CMD+A, then CTRL+D. Now enter 1 and press Return. All your images will now have a duration of one frame, which is correct.
    So, in short: Import image sequence, create CC, change duration. The whole process takes about 20 seconds. I do agree FCPX should be able to recognize images sequences properly, just like Motion does. Perhaps in the next major update.
    - See more at: http://www.philiphodgetts.com/2013/08/final-cut-pro-x-is-faster/#sthash.1OlGyw6q .dpuf

  • Switching a panel to another panel in the same frame.Is there a better way?

        public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof toolButton){
                westPanel.remove(optionPanel);
                westPanel.setVisible(false);
                toolButton tb = (toolButton)e.getSource();
                optionPanel = tb.getPanel();
                westPanel.add(optionPanel);
                westPanel.setVisible(true);
        }This code above is what I used to execute when one of several JButtons is being pressed.
    In this program, one of the JPanel will be automatically switched to another JPanel when you press the respective JButtons.
    Here are my questions:
    1. Right now, I use westPanel.setVisible(false) and then change some stuff and then invoke westPanel.setVisible(true) to make it visible again. Although this works, I have a feeling that this is not quite right. I feel that there should be some better way to do this, switching the panel and request the program to redraw the replacing JPanel. Is there a better way for this?
    2. Most of the time, the JPanel changes the size according to the components on it. I have tried several LayoutManager, but it seems that those components have more priority. Is there a way to completely fix the JPanel so that they stay the same size?

    Look into using a Card Layout rather than manually swapping the panels: http://java.sun.com/docs/books/tutorial/uiswing/layout/card.html

Maybe you are looking for

  • Two ipods+ two xp users - one computer  = AAaarghhh

    Please any help appreciated, i'm pulling my hair out over this. My girlfriend has just moved in. I've got an XP machine. I've set her up an account on my computer (admin level) and transfered all her music over. She has an 4th gen Ipod, I have a 5th

  • Messages are not reflecting correctly

    Hi, I have created message ABC from the front end. later I have changed to content of the message, changed message content is not reflecting in OAF even after bouncing the apache. can any one help me to resolve this issue. Thanks, Mahesh

  • Maintaining search results in popup window

    I have a jsp with a link to search .. when i click on the link, i popup a jsp search window.. on submit,it displays the results in a table.. but when i close the popup window and again open it, the search results are not displayed.. How can i once ma

  • Artist names missing in browse, iTunes for Windows 7.1.1

    Certain artist names are missing from the browse window. The songs are there in the library, but the artist's name is not displayed. Some are copied off my CDs, others purchased. I looked at the xml file, and could not see any obvious difference betw

  • Properly updating Flash CS5.5 to use the lastest Flash Player/Debugger

    Hey all, I'm just about to uninstall and reinstall at this point but I'm getting my install all screwed up trying to update Flash Pro CS5.5 to use Flash Player 11. I had it fine using the MXP provided in this adobe blog. Though that's 11.0 not 11.1.