Re: Multiple Array

double[] discountValues = { 0.0, 0.15, 0.25, 0.3 };

Perhaps an additional if instead of a long for loop will help readability:
     private static final double[][] table = { { 0,0 },
                              { 1000,0.15 },
                              { 5000,0.25 },
                              { 10000,0.30 } };
     public static double getDiscountedValue( double amount ) {
          for(int i=0; i<table.length; i++)
               if (amount < table[0])
                    return amount * (1-table[i-1][1]);
          return amount * table[table.length-1];

Similar Messages

  • Writing multiple arrays to a single xml file at seperate times without overwriting the previous file?

    Hi my name is Dustin,
    I am new to labview and teststand... I am trying to right multiple arrays of data to a single xml file. I can do this with a cluster but I have to create a variable for each of those arrays (21 arrays) and I was hoping to use the same variable for each array. Meaning I obtain my array of data write it to an xml file then replace that array in that variable with a new array and then call up my VI that writes that array to an xml file and write it to the same xml file underneath the first array without overwriting it. Attached is my VI I created to write an array to an xml file. Again I am wondering if there is a way to write multiple arrays to a single xml file at different times without overwriting the previous xml file.
    Thanks
    Solved!
    Go to Solution.
    Attachments:
    Write_to_XML_File.vi ‏11 KB

    Hi dlovell,
    Check the attached example. I think it may help you.
    Regards,
    Nitz
    (Give Kudos to Good Answers, Mark it as a Solution if your problem is Solved) 
    Attachments:
    Write to XML.vi ‏17 KB

  • Obtain Array from an XML file with Multiple Arrays

    Hi,
    So I have been struggling with this program I am making for the last few months but I am almost there. I have a program that creates multiple arrays and place them one after another in an xml file and each array has its own unique name. Now I would like to create a VI that takes this XML file and when the user inputs the specific array name they are looking for it goes into the xml file finds the entire array under that name and displays it in an output indictor to be viewed on the VI. Attached is a sample of my xml file and the VI that creates this xml file.
    Thanks,
    dlovell
    Solved!
    Go to Solution.
    Attachments:
    I_Win.zip ‏20 KB

    Here is a slightly different version. The one above reads from a file. This is how you would read from an already loaded XML string.
    =====================
    LabVIEW 2012
    Attachments:
    Find Array.vi ‏18 KB

  • Multiple Arrays for limiting Record Pulling in Main Report

    I have created an array in a subreport that pulls all applicable order #'s for a specific period.  The subreport has been placed in the report header of the main report.  In the main report, I have a formula that looks at the order # in the database.  If that order # exists in the array, then I want the main report to pull that order # and the related invoices.  One order # can have more than one invoice.
    I've used the above method many times to limit records pulled when I had less than 1000 applicable records.  Now, out of necessity, I'm trying to do this with more than 1000 records, so I have created multiple array strings within the "array" formula.  The "array" formula is working correctly - the data that I see is correct. The problem is with the formula in the main report. This formula is not returning any data - so, basically, the main report formula is saying that no order #'s exist in the array.
    Here's my coding for the array (appears to be working fine since the data looks correct):
    whileprintingrecords;
    shared stringvar array Groups1;
    shared stringvar array Groups2;
    shared stringvar array Groups3;
    numbervar rtc1;
    //if pymt receipt date is in the report period, add that order# to the array. 
    if {BI50_BankTransactions_AR_InvcDt_H.ValueDate} = {?Cash Receipt Period}
    then
    (redim Groups1[1];
    redim Groups2[1];
    redim Groups3[1];
    rtc1 := 0);
    // the code below checks to see if the order ID field is in any of the above-declared arrays...
    //if it is it is not added again and rtc1 is not incremented
    if not({oehdrhst_sql.ord_no} in Groups1 or {oehdrhst_sql.ord_no} in Groups2 or {oehdrhst_sql.ord_no} in Groups3) then
    rtc1 := rtc1 + 1;
    if rtc1 <= 1000 then (Redim Preserve Groups1[rtc1]; Groups1[rtc1] := {oehdrhst_sql.ord_no});
    if rtc1 in 1001 to 2000 then (Redim Preserve Groups2[rtc1-1000]; Groups2[rtc1-1000] := {oehdrhst_sql.ord_no});
    if rtc1 in 2001 to 3000 then (Redim Preserve Groups3[rtc1-2000]; Groups3[rtc1-2000] := {oehdrhst_sql.ord_no});
    if rtc1 <= 1000 then Groups1[rtc1]
    else if rtc1 in 1001 to 2000 then Groups2[rtc1-1000]
    else if rtc1 in 2001 to 3000 then Groups3[rtc1-2000]
    Now, here's the code for the formula in the Main Report (please note, for now I'm just trying to generate a "true" or "false" result - so my current results are all "false" which isn't correct)
    whileprintingrecords;
    shared stringvar array Groups1;
    shared stringvar array Groups2;
    shared stringvar array Groups3;
    ({oehdrhst_sql.ord_no} in shared stringvar array Groups1) or
    ({oehdrhst_sql.ord_no} in shared stringvar array Groups2) or
    ({oehdrhst_sql.ord_no} in shared stringvar array Groups3);
    If I only use one "shared stringvar array", everything works like a charm, but when I add another "shared stringvar array", the formula in my main report stops working.  I've tried changing this code but nothing has worked.  I'm at a loss as to what the problem is.  Any suggestions would be very much appreciated.
    Edited by: Linda Offenbacker on Sep 21, 2010 9:41 PM
    I have resolved this issue.  I guess seeing my coding in a different perspective helped me identify the issue.  The problem was in this section of the code where my redim criteria was incorrect:
    "if {BI50_BankTransactions_AR_InvcDt_H.ValueDate} = {?Cash Receipt Period}"
    It should be:
    "if {BI50_BankTransactions_AR_InvcDt_H.ValueDate} <> {?Cash Receipt Period}"

    Post Author: Don
    CA Forum: General
    Also, keep in mind that you only need a sub-report if your table joins are one to many records.  If they are = joins then you don't need a sub-report if the tables are linked in Crystal correctly.

  • Sorting between multiple arrays.

    I thought that I had posted this yesterday; however as I can not find my post...
    I need assistance with part of a project where I need to sort between multiple arrays; using one of the columns as the sort criteria. The arrays contain integers, strings, and doubles; however I would like to sort and display the arrays alphabetically using the string column. I was told that a bubble array may work, however as I can not find specific information on the use of a bubble array, I really don't know where to start. The arrays look like the following:
    productArray[0] = new Product(1, "binder ", 15, 1.5, 0, 0);
    productArray[1] = new Product(2, "marker ", 13, .5, 0, 0);
    productArray[2] = new Product(3, "paper ", 24, .95, 0, 0);
    productArray[3] = new Product(4, "pen ", 5, .25, 0, 0); \
    Any assistance that anyone could provide would be greatly appreciated. I am a newbie when it comes to Java and the course materials are extremely vague.
    Dman

    Thank you for your assistance.
    The site that I found to be most helpful was the http://www.onjava.com/lpt/a/3286 site; however I am still experiencing problems. I have added code to the program as noted below:
    public class Inventoryprogrampart3
    /** Creates a new instance of Main */
    * @param args the command line arguments
    public static void main(String[] args)
    // create Scanner to obtain input from command window
    java.util.Scanner input = new java.util.Scanner( System.in );
    double totalInventoryValue = 0;
    NumberFormat nf = NumberFormat.getCurrencyInstance();
    System.out.println(); // Displays a blank line
    System.out.println( " Welcome to the Inventory Program - Part 2 " ); // Display the string
    System.out.println( " ----------------------------------------- " ); // displays a line of characters
    System.out.println(); // Displays a blank line
    System.out.println( "This program will output an office supply inventory" ); // Display the string
    System.out.println( "listing that includes item numbers for the" ); // Display the string.
    System.out.println( "inventoried products, the items product names, the" ); // Display the string.
    System.out.println( "quantity of each product in stock, the unit price" ); // Display the string
    System.out.println( "for each product, the total value of each products" ); // Display the string
    System.out.println( "inventory, and a total value of the entire inventory." ); // Display the string
    System.out.println(); // Displays a blank line
    System.out.println( "*****************************************************" ); // Displays a line of characters
    System.out.println(); // Displays a blank line
    Product[] productArray = new Product[ 7 ]; // creates 7 product arrays
    // adds data to the 7 arrays
    productArray[0] = new Product();
    productArray[0].setitemNumber(1);
    productArray[0].setproductName ( "binder" );
    productArray[0].setitemQuantity(15);
    productArray[0].setitemPrice(1.5);
    productArray[0].setinventoryValue(0);
    productArray[1] = new Product();
    productArray[1].setitemNumber(2);
    productArray[1].setproductName( "paper" );
    productArray[1].setitemQuantity(24);
    productArray[1].setitemPrice(.95);
    productArray[1].setinventoryValue(0);
    productArray[2] = new Product();
    productArray[2].setitemNumber(4);
    productArray[2].setproductName( "pen" );
    productArray[2].setitemQuantity(5);
    productArray[2].setitemPrice(.25);
    productArray[2].setinventoryValue(0);
    productArray[3] = new Product();
    productArray[3].setitemNumber(3);
    productArray[3].setproductName( "marker" );
    productArray[3].setitemQuantity(13);
    productArray[3].setitemPrice(.5);
    productArray[3].setinventoryValue(0);
    productArray[4] = new Product();
    productArray[4].setitemNumber(5);
    productArray[4].setproductName( "pencil" );
    productArray[4].setitemQuantity(28);
    productArray[4].setitemPrice(.4);
    productArray[4].setinventoryValue(0);
    productArray[5] = new Product();
    productArray[5].setitemNumber(7);
    productArray[5].setproductName( "tape" );
    productArray[5].setitemQuantity(14);
    productArray[5].setitemPrice(1.65);
    productArray[5].setinventoryValue(0);
    productArray[6] = new Product();
    productArray[6].setitemNumber(6);
    productArray[6].setproductName( "staples" );
    productArray[6].setitemQuantity(13);
    productArray[6].setitemPrice(1.25);
    productArray[6].setinventoryValue(0);
    System.out.println( "Inventory listing prior to sorting by product name:" );
    System.out.println(); // Displays a blank line
    System.out.println( "Item #"+"\t"+"Product Name"+"\t"+"Stock"+"\t"+"Price"+"\t"+"Total Value"); // Displays a header line for the inventory array display
    System.out.println(); // Displays a blank line
    System.out.println( "-----------------------------------------------------" ); // Displays a line of characters
    System.out.println(); // Displays a blank line
    for (int i=0; i<=6; i++)
    Product products = productArray;
    String productName = products.getproductName();
    int itemNumber = products.getitemNumber();
    int itemQuantity = products.getitemQuantity();
    double itemPrice = products.getitemPrice();
    double inventoryValue = products.getinventoryValue();
    System.out.println( productArray[i].getitemNumber() +"\t"+ productArray[i].getproductName() +"\t"+"\t" + productArray[i].getitemQuantity() +"\t"+ nf.format(productArray[i].getitemPrice()) +"\t"+ nf.format(productArray[i].getinventoryValue()) );
    Arrays.sort(productArray);
    System.out.println( "-----------------------------------------------------" ); // Displays a line of characters
    System.out.println(); // Displays a blank line
    System.out.println( "Inventory listing after being sorted by product name:" );
    System.out.println(); // Displays a blank line
    System.out.println( "Item #"+"\t"+"Product Name"+"\t"+"Stock"+"\t"+"Price"+"\t"+"Total Value"); // Displays a header line for the inventory array display
    System.out.println(); // Displays a blank line
    System.out.println( "-----------------------------------------------------" ); // Displays a line of characters
    for(int i=0; i <= 6; i++)
    totalInventoryValue = totalInventoryValue + productArray[i].getinventoryValue(); // calculates the total value of the entire products inventory
    System.out.println( productArray[i].getitemNumber() +"\t"+ productArray[i].getproductName() +"\t"+"\t"+ productArray[i].getitemQuantity() +"\t"+ nf.format(productArray[i].getitemPrice()) +"\t"+ nf.format(productArray[i].getinventoryValue()) );
    }// end for
    System.out.println(); // Displays a blank line
    System.out.println( "The total value of the entire inventory is: " + nf.format(totalInventoryValue) ); // Displays the entire inventory value
    System.out.println(); // Displays a blank line
    System.out.println( "*****************************************************" ); // Displays a line of characters
    } // end public static void main
    }// end public class Inventoryprogrampart3 main
    The following utilities have been set:
    import java.io.*;
    import java.text.*;
    import java.util.Scanner;
    import java.util.*;
    import java.util.Arrays;
    import java.util.ArrayList;
    import java.util.Comparator;
    The program compiles, however when I try to run the program I receive the following error (which outputs about 1/2 way through the program:
    Exception in thread "main" java.lang.ClassCastException: Product can not be cast to java language comparable.
    (along with a listing of other errors - I can't even get my cut and paste to work on my command prompt window).
    I've tried about 50 different iterations and nothing seems to work.

  • Multiple Arrays to Spreadsheet

    Hi,
    I've a vi that process data files and saves the analysis on a new file (it's a 2D array). This being done in a for loop to allow multiple files to be processed with user intervention. Instead of saving a new analysis file every iteration, I would like to save all of the analyzed data in one file. For example:
    Cable #11
    x   y   z
    1   2   3
    4   5   6
    Cable #12
    4  5   4
    3  2   2
    The two problems I have:
    I know how to insert headers but how do you insert a string after each array?
    How do I save all the arrays to one array? I've tried taking the spreadsheet function out of the for loop, but it didn't work.
    I'll appreciate any input,
    Solved!
    Go to Solution.

    I've tried appending it in & out of the for loop and it doesn't make a difference; it just writes the last data file.
    Thank you for taking a look at it. The data I want to save is the case structure outside of the for loop.
    Attachments:
    stat_done.vi ‏124 KB

  • Call Library node and multiple array copies

    Hey everyone,
    I am trying to do the following using a hybrid of C and Labview:
    1.) Create an array in Labview
    2.) Pass the array into 2 seperate DLLs at the same time
    3a.) One DLL modifies the data and then updates a flag.  For example, the array created in 1 in 100,000 units long, this DLL modifies 999 units in one pass and updates the 1000th unit to say that the 999 units have been succesfully written.  It would do this 100 times in this example.
    3b.) The 2nd DLL checks the flag unit set in 3a, and if the flag is a certain value, the 2nd DLL reads the 999 units modified in 3a and performs operations on them.
    Note:  There is no read/write conflict here, since the only way 3b operates on the memory is if 3a has completed its operations and updated the flag.
    The problem:
    Labview creates 3 copies of the same array in memory.  Once in step 1, and 1 for each DLL.  This is problematic since the 2 DLLs can't communicate with each other anymore in the way that is described above, since the method above requires that the DLLs in 3a and 3b operate on the same memory locations.
    The question:
    How can I prevent Labview from creating multiple copies at the Call Library node so that my DLLs can operate on the same chuck of memory that is created in step 1.
    Thanks,
    Austin McElroy

    AustinMcElroy wrote:
    Ok, so as nk said, even if the idea is terrible why is Labview making extra copies?  If I have 2 DLLs in serial to avoid the flag idea, and I am working with  datarates of 100MB/s coming off of my acq. card, that is  100MB allocated for the initial array, 100MB allocated for the first DLL and 100MB allocated for the 2nd DLL, per second.  Perhaps even more allocations and copying from C back into Labview (I am unsure of this, I will test it tomorrow).  This is alot of memory being allocated and copied extraneously.  Is there a way to prevent Labview from doing this?
    And LabVIEW doesn't make copies if it doesn't need too. For this to work however you need to pass the array through the CLN (input it on the left side and output it at the right side of the CLN and from there wire it to the next function), not branch it. That should even work if you configure the array parameter to be a C array data pointer (since LabVIEW will pass the pointer to the actual data to the DLL), but it definitly works without copies for LabVIEW array handles.
    Then LabVIEW won't make a copy (except maybe in some older versions).
    If  you branch the wire however, LabVIEW has no choice but to create at
    least one copy to satisfy data flow contraints.
    This doesn't mean that the first DLL function could store the array pointer and operate on it after it has returned since a C function once returning control to the caller has absolutely no control over a pointer it got passed anymore. At the time your DLL might decide to access that pointer LabVIEW quite likely might have left the diagram already and consequently deallocated or reused the handle for something else, causing your DLL to corrupt memory. Even if you decide to use events to signal the second function to not return before the data has been modified by the first, you create a monster of complexity that will sooner or later blow in your face. Either the user might decide to abort the programm mid term and your second function never receives the signal so never returning, making your application simply hang in there with no other option than to kill it through the task manager, or someone will go modify your little program not knowing the (unlogical) dependency of those two calls and creating something that simply works very wrong or if you are very lucky will crash with an access violation exception early on.
    Rolf Kalbermatter
    Message Edited by rolfk on 03-24-2008 01:39 PM
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Random from multiple arrays

    I'm trying to generate a random picture half the time from
    one array and half the time from another array.
    I've get as far as this and it doesn't work. Any help would
    be useful
    var ranArrays: Array = new Array ("bluePixs", "redPixs");
    var bluePixs:Array = new Array ("bluePix1.swf",
    "bluePix2.swf", "bluePix3.swf");
    var redPixs:Array = new Array ("redPix1.swf", "redPix2.swf",
    "redPix3.swf");
    function randomBackground(){
    var randomArray = random (ranArrays.length);
    var randomNumber = random (randomArray.length);
    _root.pix.loadMovie (randomArray[randomNumber]);
    randomBackground();

    Hi,
    Your SQL would be something like:
    SELECT M.MONEY, DRINKS.NAME, DRINKS.PRICE, F1.PRODUCT, F1.PRICE, F2.PRODUCT, F2.PRICE, DESERT.PRODUCT, DESERT.PRICE
    FROM MONEY M
    CROSS JOIN DRINKS
    CROSS JOIN F1
    CROSS JOIN F2
    CROSS JOIN DESERT
    WHERE DRINKS.PRICE + F1.PRICE + F2.PRICE + DESERT.PRICE <= M.MONEYThat may return multiple results - as there may be a number of combinations less than your MONEY value. You can restrict this to return just one:
    SELECT M.MONEY, DRINKS.NAME, DRINKS.PRICE, F1.PRODUCT, F1.PRICE, F2.PRODUCT, F2.PRICE, DESERT.PRODUCT, DESERT.PRICE
    FROM MONEY M
    CROSS JOIN DRINKS
    CROSS JOIN F1
    CROSS JOIN F2
    CROSS JOIN DESERT
    WHERE DRINKS.PRICE + F1.PRICE + F2.PRICE + DESERT.PRICE <= M.MONEY
    AND ROWNUM = 1As you then only want to return a single string for display to the user, you will have to concatenate the items found into a single string:
    SELECT DRINKS.NAME || ' ' || DRINKS.PRICE || ' ' || F1.PRODUCT || ' ' || F1.PRICE || ' ' || F2.PRODUCT || ' ' || F2.PRICE || ' ' || DESERT.PRODUCT || ' ' || DESERT.PRICE X
    FROM MONEY M
    CROSS JOIN DRINKS
    CROSS JOIN F1
    CROSS JOIN F2
    CROSS JOIN DESERT
    WHERE DRINKS.PRICE + F1.PRICE + F2.PRICE + DESERT.PRICE <= M.MONEY
    AND ROWNUM = 1Obviously, you would want to replace the spaces (' ') with something more meaningful to the user
    Andy

  • Copying Multiple Arrays into One Large Array

    I'm currently trying to copy multiple character arrays into one larger character array in a method that prints data gathered from a database. Here is my code:
    private static void printData(String[] data){
            try {
                int totalLengthOfAllStrings = 0;
                for(int i = 0; i < data.length; i++) {
                    data[i] += '\n';
                    totalLengthOfAllStrings += data.length();
    int runningLength = 0;
    char[] printArray = new char[totalLengthOfAllStrings];
    for(int j = 0; j < data.length; j++) {
    char[] tempArray = data[j].toCharArray();
    runningLength += tempArray.length;
    System.arraycopy(tempArray, 0, printArray, runningLength - 1, tempArray.length);
    DocFlavor df = DocFlavor.CHAR_ARRAY.TEXT_PLAIN;
    Doc printDoc = new SimpleDoc(printArray, df, null);
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(new Copies(1));
    aset.add(MediaSize.NA.LETTER);
    aset.add(Sides.DUPLEX);
    PrintService[] services = PrintServiceLookup.lookupPrintServices(df, aset);
    if (services.length > 0) {
    DocPrintJob job = services[0].createPrintJob();
    try {
    job.print(printDoc, aset);
    System.out.println("Print successful!");
    catch (PrintException pe) {
    catch(Exception e) {
    e.printStackTrace();
    I keep getting an ArrayIndexOutOfBoundsException and for the life of me I can't figure out why.
    Can anyone help with this?
    Thanks!
    -Matt

    I think your problem lies with the second for loop:
    for(int j = 0; j < data.length; j++)  {
        char[] tempArray = data[j].toCharArray();
        runningLength += tempArray.length;
        System.arraycopy(tempArray, 0, printArray, runningLength - 1, tempArray.length);
    }If I am not wrong, you should swap the sequence of the runningLength and System.arraycopy statements, and also move the minus 1 from arraycopy statement to the runningLength statement. The result would look like this:
    for(int j = 0; j < data.length; j++)  {
        char[] tempArray = data[j].toCharArray();
        System.arraycopy(tempArray, 0, printArray, runningLength, tempArray.length);    // swapped and removed the -1
        runningLength += tempArray.length - 1;    // swapped and appended the -1
    }The main reason for these changes is because when j == data.length - 1, the value of runningLength would have already exceeded the size of printArray. Therefore, swapping the position would be able to overcome this problem.

  • Is it better to make multiple arrays of data or one big array and access it many times?.

    I am going to acquire up to 5 samples per second of 50 channels over 30 minutes then average ten of the channels and generate a report.  There are other bits of information needed to complete my task and graphs.  Would it be "faster" for the PC to have one large 4d array with all the information or faster to make several separate arrays?  Would it be more reliable to have one or many(fewer code lockups)?
    Also,
    Yes, I do mean to be using labview.  I expected this crowd to have a different perspective (and I could not find LV blog).
    For each channel, I want to scale per 6 other variables per channel(nominal high, mid, low, and reading high, mid low)  So there is the channels and time, then there is the calibration values, then there is the calibrated readings.  If I put all that along with my test information in one large matrix, it would be simpler for me to remember where in the matrix each item is, but if it is in several matrixies then the "active" matrix is smaller while the other information is not used.
    The sales rep for NI was indicating the computer power is much higher than I am used to.  (I have not started programming yet, I am preparing for a huge project on a "new"(2 year old)PC.)  I am trying to understand just how much power I am missing from my days of gwbasic, Q-basic and our current Visual Basic 6.0 running on XP.  This matrix question is new to me.
    Solved!
    Go to Solution.

    I don't see where you are getting 4 dimentions for your array.  I only see 2: channel and sample.
    From what you are describing, I would put any "support" information for a channel into a cluster.  So you should have an array of clusters to contain your support data.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How do i output multiple arrays from a case structure to create one larger array

    I currently have a vi that has one hardware input that i needed to take a measurement then be moved and take a similar measurement at a different point.  To accomplish this i used a while loop inside a case structure.  The while loop takes the measurement  and finds the numbers i need while the case structure is changed per the new measurement location.  I want to take the data points i have created in each case and output them into a single table.  I assumed to do this the best way would be to get the data from each case into its own built array and build a larger array but I cant get the information out of the case structure so that it all inputs at different places.
    thanks for your help
    Attachments:
    Array.vi ‏30 KB

    Hi Ross,
    attached you will find a solution for your table building problem.
    I would suggest thinking about program design - having the same case content in several cases doesn't make sense. I also would not want my user to press several stop buttons depending on choosen measurement...
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    Array.vi ‏45 KB

  • Reading information from multiple arrays efficiently

    So I'm trying to make a flash application about number of felonies of different trafic violations from different years, example:
    In 2002 there was 9631 drunk drivers, 13481 driving without a license, 9863 speeders and 18862 who broke other laws
    In 2003 there was 8593 drunk drivers, 12785 driving without a license, 12217 speeders and 19196 who broke other laws
    The list goes on and I've made 5 different arrays, one for year, one for drunk drivers, one for driving without a license,
    I call them:
    var arTab:Array = new Array();
    arTab[0] = new Array(2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012);
    var promilleTab:Array = new Array();
    promilleTab[0] = new Array(9631, 8593, 8363, 8128, 8514, 8534, 8560, 8146, 8241, 8019, 8759);
    var forerkortTab:Array = new Array();
    forerkortTab[0] = new Array(13481, 12785, 12585, 12492, 13470, 14181, 14622, 14082, 14287, 13640, 14180);
    var hastighetTab:Array = new Array();
    hastighetTab[0] = new Array(9863, 12217, 14920, 14929, 15425, 18010, 15909, 14197, 13276, 11158, 12264);
    var trafikklovenTab:Array = new Array();
    trafikklovenTab[0] = new Array(18862, 19196, 20101, 20026, 21381, 21845, 20005, 19446, 20900, 19346, 20265);
    After that I added 2 comboboxes, one for the year and one to pick felony, but when I try to write out the information in a text box I have to add ALOT of code, example:
    function skrivUt(Event:MouseEvent)
           var arListe:int = arKombo.selectedItem.data;
           var bruddListe:int = bruddKombo.selectedItem.data;
           if(bruddListe == 1)
                if(arListe == 1)
                txtSvar.text = "I " + arTab[0][0] + " ble det anmeldt " + promilleTab[0][0] + " for promillekjøring";
                if(arListe == 2)
                txtSvar.text = "I " + arTab[0][1] + " ble det anmeldt " + promilleTab[0][1] + " for promillekjøring";
                if(arListe == 3)
                txtSvar.text = "I " + arTab[0][2] + " ble det anmeldt " + promilleTab[0][2] + " for promillekjøring";
    And I would have to make tons of almost the same line which works, but my question is:
    Is there any way I can write this in a more efficient way?

    You could look for a pattern that follows your current code.  For what you show already I see...
    function skrivUt(Event:MouseEvent)
           var arListe:int = arKombo.selectedItem.data;
           var bruddListe:int = bruddKombo.selectedItem.data;
           if(bruddListe == 1)
                txtSvar.text = "I " + arTab[0][arListe-1] + " ble det anmeldt " + promilleTab[0][arListe-1] + " for promillekjøring";

  • Combining multiple arrays into one

    I am sure this is probably really simple to do, but for some reason I just cannot figure it out.  
    I am creating an HTA that will be used to backup terminated employee's PC.  It will scan the drive for the specific file Types chosen and XCopy them up to the server.
    Originally I had the different file types writing into Strings and then just combining those strings.  I was deliminating the entries with a ;.  The issue I ran into is when combining them I have to have a ; in front of the first entry, the issue
    starts if someone only choose one file type.  Then it looks for any file with no extensions, which is a lot.  
    So then I thought I would just put them into their own arrays and then combine those arrays, but this just seems to be above my head.  I cannot wrap my mind around it.  
    Writing it in VBScript.  Here is the a snippet of the section I am working on.  Everything else in the script/HTA works fine. 
    Sub Extensions(strEndUserFolder)
    If Office.checked Then strOfficeExtensions = "doc;docx;docm;xls;xlt;xlm;xlsx;xlsm;ppt;pps;pptx;pptm;ppsx;ppsm;mdb;ldb;one;onetoc2"
    If PDF.checked Then strPDFExtensions = "pdf"
    If SRA.checked Then strSRAExtensions = "rws"
    If Pictures.checked Then strPictureExtensions = "bmp;jpg;jpeg;gif;tiff;png"
    If Videos.checked Then strVideoExtensions = "mp4;mov;mpeg;mpg;wmv;mov"
    If Notes.checked Then strNotesExtensions = "id"
    If CADUG.checked Then strCADUGExtensions = "dwg;dwt;dxf;dwf;dst;prt"
    arrOfficeExtensions = Split(strOfficeExtensions, ";")
    arrPDFExtensions = Split(strPDFExtensions, ";")
    arrSRAExtensions = Split(strSRAExtensions, ";")
    arrPictureExtensions = Split(strPictureExtensions, ";")
    arrVideoExtensions = Split(strVideoExtensions, ";")
    arrNotesExtensions = Split(strNotesExtensions, ";")
    arrCADUGExtensions = Split(strCADUGExtensions, ";")
    arrExtensions =
    Call SetDrivetoScan(arrExtensions, strEndUserFolder)
    End Sub

    Wow!  A hash table in VBScript would be a great extension.
    Sounds like a job for "ta-da!" ... Array Man!.
    Sub Extensions(strEndUserFolder)
    ext=""
    If Office.checked Then ext=ext & "doc;docx;docm;xls;xlt;xlm;xlsx;xlsm;ppt;pps;pptx;pptm;ppsx;ppsm;mdb;ldb;one;onetoc2;"
    If PDF.checked Then ext = ext & "pdf;"
    If SRA.checked Then ext = ext & "rws;"
    If Pictures.checked Then ext = ext & "bmp;jpg;jpeg;gif;tiff;png;"
    If Videos.checked Then ext = ext & "mp4;mov;mpeg;mpg;wmv;mov;"
    If Notes.checked Then ext = ext & "id;"
    If CADUG.checked Then ext = ext & "dwg;dwt;dxf;dwf;dst;prt;"
    If Right(ext,1) = ";" Then
    ext = Left(ext,Len(ext) -1 )
    End If
    arrExtensions = Split(ext,";")
    SetDrivetoScan arrExtensions, strEndUserFolder
    End Sub
    Just add them up and remove the last extra one if it exists.
    ¯\_(ツ)_/¯

  • [PS] Multiple array´s split and merge

    Is it possible to: when you have 3 array's split the value's after the comma and then from each array merge every 1st value with 1st, 2 with 2 and so on.
    I know you can use split to split up an array, but i have no clue how to merge it like i want.
    example:
    array 1 :
    1,7,5,0,9,1
    array 2 :
    dog,cow,cat,horse,man,girl
    array 3 :
    short,big,little,huge,long,small
    output 1 :
    1 dog short
    output 2 :
    7 cow big
    output 3 :
    5 cat little
    or even better is that it gonna be variable
    $array1 :
     1,7,5,0,9,1
    $array2 :
     dog,cow,cat,horse,man,girl
    $array3 :
     short,big,little,huge,long,small
    output 1 :  $array1 $array2 $array3
    output 1 :
     1 dog short
    output 2 :  $array1 $array2 $array3
    output 2 :
     7 cow big
    output 3 :  $array1 $array2 $array3
    output 3 :
     5 cat little
    Sincerely,
    Jeroen 

    hi Jeroen,
    sure you can do that. Simply iterate over each index of the arrays:
    $int = 0
    While ($int -lt $array1.Length)
    ($array1[$int] + " " + $array2[$int] + " " + $array3[$int])
    $int++
    Cheers,
    Fred
    There's no place like 127.0.0.1

  • How to break up a String into multiple array Strings?

    How do I break up a string into a bunch of String arrays after the line ends.
    For example,
    JTextArea area = new JTextArea();
    this is a string that i have entered in the area declared above
    now here is another sting that is in the same string/text area
    this is all being placed in one text field
    Sting input = area.getText();
    now how do I break that up into an array of strings after each line ends?

    Ok I tested it out and it works.
    So for future refrence to those that come by the same problem I had:
    To split up a string when using a textfield or textarea so that you can store seperate sections of the string based on sperate lines, using the following code:
    String text = area.getText() ;
    String[] lines = text.split("\n") ;
    This will store the following
    this is all one
    entered string
    into two arrays
    Cheers{
    Edited by: watwatacrazy on Oct 21, 2008 11:06 AM
    Edited by: watwatacrazy on Oct 21, 2008 11:16 AM
    Edited by: watwatacrazy on Oct 21, 2008 11:16 AM

  • Problem passing multiple array lists to a single method

    Hi, all:
    I have written a generic averaging method that takes an array list full of doubles, adds them all up, divides by the size of the array list, and spits out a double variable. I want to pass it several array lists from another method, and I can't quite figure out how to do it. Here's the averager method:
         public double averagerMethod (ArrayList <Double> arrayList) {
              ArrayList <Double> x = new ArrayList <Double> (arrayList); //the array list of integers being fed into this method.
              double total = 0;//the total of the integers in that array list.
              for (int i = 0; i < x.size(); i++) {//for every element in the array list,
                   double addition = x.get(i);//get each element,
                   total = total + addition; //add it to the total,
              double arrayListSize = x.size();//get the total number of elements in that array list,
              double average = total/arrayListSize;//divide the sum of the elements by the number of elements,
              return average;//return the average.
         }And here's the method that sends several array lists to that method:
         public boolean sameParameterSweep (ArrayList <Double> arrayList) {
              sameParameterSweep = false;//automatically sets the boolean to false.
              arrayList = new ArrayList <Double> (checker);//instantiate an array list that's the same as checker.
              double same = arrayList.get(2); //gets the third value from the array list and casts it to double.
              if (same == before) {//if the third value is the same as the previous row's third value,
                   processARowIntoArrayLists(checker);//send this row to the parseAParameterSweep method.
                   sameParameterSweep = true;//set the parameter sweep to true.
              if (same != before) {//if the third value is NOT the same,
                   averagerMethod(totalTicks);//go average the values in the array lists that have been stored.
                   averagerMethod(totalNumGreens);
                   averagerMethod(totalNumMagentas);
                   sameParameterSweep = false;
              before = same; //problematic!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
         return sameParameterSweep;
         }Obviously, the problem is that I'm not passing the array lists from this method to the averager method the right way. What am I doing wrong?

    Encephalopathic wrote:
    There are several issues that I see, but the main one is that you are calculating average results but then just discarding them. You never assign the result to a variable.
    In other words you're doing this:
    averagerMethod(myArrayList);  // this discards the resultinstead of this:
    someDoubleVariable = averagerMethod(myArrayList); // this stores the resultAlso, do you wish to check for zero-sized array lists before calculating? And what would you return if the array list size were zero?So in solving that problem, I've come up with another one that I can't figure out, and I can't fix this problem until I fix that.
    I have several thousand lines of data. They consist of parameter sweeps of given variables. What I'm trying to do is to store pieces of
    data in array lists until the next parameter adjustment happens. When that parameter adjustment happens, I want to take the arraylists
    I've been storing data in, do my averaging thing, and clear the arraylists for the next set of runs under a given parameter set.
    Here's the issue: I'm having the devil of a time telling my application that a given parameter run is over. Imagine me doing stuff to several variables (number of solders, number of greens, number of magentas) and getting columns of output. My data will hold constant the number of soldiers, and for, say, ten runs at 100 soldiers, I'll get varying numbers of greens and magentas at the end of each of those ten runs. When I switch to 150 soldiers to generate data for ten more runs, and so forth, I need to average the number of greens and magentas at the end of the previous set of ten runs. My problem is that I can't figure out how to tell my app that a given parameter run is over.
    I have it set up so that I take my data file of, say, ten thousand lines, and read each line into a scanner to do stuff with. I need to check a given line's third value, and compare it to the previous line's third value (that's the number of soldiers). If this line has a third value that is the same as the previous line's third value, send this line to the other methods that break it up and store it. If this line has a third value that is NOT the same as the previous line's third value, go calculate the averages, clear those array lists, and begin a new chunk of data by sending this line to the other methods that break it up and store it.
    This is not as trivial a problem as it would seem at first: I can't figure out how to check the previous line's third value. I've written a lot of torturous code, but I just deleted it because I kept getting myself in deeper and deeper with added methods. How can I check the previous value of an array list that's NOT the one I'm fiddling with right now? Here's the method I use to create the array lists of lines of doubles:
         public void parseMyFileLineByLine() {
              totalNumGreens = new ArrayList <Double>();//the total number of greens for a given parameter sweep
              totalNumMagentas = new ArrayList <Double>();//the total number of magentas for a given parameter sweep.
              totalTicks = new ArrayList <Double>();//the total number of ticks it took to settle for a given parameter sweep.
              for (int i = 8; i < rowStorer.size() - 2; i++) {//for each line,
                   checker = new ArrayList <Double>();//instantiates an array list to store each piece in that row.
                   String nextLine = rowStorer.get(i); //instantiate a string that contains all the information in that line.
                   try {
                        Scanner rowScanner = new Scanner (nextLine); //instantiates a scanner for the row under analysis.
                        rowScanner.useDelimiter(",\\s*");//that scanner can use whitespace or commas as the delimiter between information.
                        while (rowScanner.hasNext()) {//while there's still information in that scanner,
                             String piece = rowScanner.next(); //gets each piece of information from the row scanner.
                             double x = Double.valueOf(piece);//casts that stringed piece to a double.
                             checker.add(x);//adds those doubles to the array list checker.
                   catch (NoSuchElementException nsee) {
                        nsee.printStackTrace();
                   //System.out.println("checker contains: " + checker);
                   processARowIntoArrayLists(checker);//sends checker to the method that splits it up into its columns.
         }

Maybe you are looking for

  • How do I output a large Ai file as multiple PDFs (via views, pages, whatever)

    I am working in FreeHand 10 and Illustrator CS3 on a large street map. The client wants to do his own edits to the map in Illustrator (version unknown) then output it so he can show a section per page, in an atlas he plans to publish. And maintain th

  • Automatic creation of limit order

    Hi, We have a limit SC with an assigned source of supply (contract). But after approval this SC becomes a PR in ECC and not a PO directly. We are in classic scenario and all SC with source of supply should do that (including limit orders). What could

  • Hint: Beware when using JDev 10.1.3 EA to deploy to 10.1.2 App server!!

    I've struggled a bit with deploying a War packaged application from JDev 10.1.3 to a version 10.1.2 Application Server, and since I've encountered loads of messages in the various forums talking about "Http -'something' when trying to deploy through

  • Converting Word 2007 Styles to PDF

    I just upgraded to word 2007. I don't have the PDF Maker for word installed (where you see the Acrobat option on the toolbar in word), and not sure it will install with 2007. So the first question is: Does it? Second question. If you can install PDF

  • Created an event by mistake

    I made a huge mistake in using my keyword "favorite" to group photos, then used the "create event" tab to make those photos one event. I thought they would stay in their own original events (created automatically by time of import but they all got pu