Array output to GUI

I need to write a gui that takes data from an array and puts it in a gui frame. Nothing fancy, no buttons, just a frame with all the data in there. A close button wouldnt be a bad idea but its not needed.
The program currently displays the information I want just fine but does it in console. I just want to tell that data to use a gui instead of console.
Can anyone give me a hint on where to begin? I havent used swing or created a gui before this and I am new to java entirely.

Hmm, that gives me an idea where to start but I think my case is a bit more sophisticated then that. Here is the code.
//  Jmichelsen
//  Created June 17, 2007
/*  This program is designed to show an inventory of CD's in alphabetical order
    and their corresponding prices.
    It gives the prices of the CD's and the value of the entire inventory.
    It adds a restocking fee for the entire product inventory and displays it separately */
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Inventory4 {
    public static void main(String[] args) {
        CD cd;
        Inventory inventory = new Inventory();
        cd = new CDWithGenre(16, "Snatch Soundtrack", 11, 13.01f, "Soundtrack");
        inventory.add(cd);
        cd = new CDWithGenre(12, "Best Of The Beatles", 10, 19.99f, "Classic Rock");
        inventory.add(cd);
        cd = new CDWithGenre(45, "Garth Brooks", 18, 10.87f, "Country");
        inventory.add(cd);
        cd = new CDWithGenre(32, "American Idol", 62, 25.76f, "Alternative");
        inventory.add(cd);
        cd = new CDWithGenre(18, "Photoshop", 27, 99.27f, "None");
        inventory.add(cd);
        inventory.display();    
    } //End main method
} //End Inventory4 class
     /* Defines data from main as CD data and formats it. Calculates value of a title multiplied by its stock.
      Creates compareTo method to be used by Arrays.sort when sorting in alphabetical order. */
class CD implements Comparable{
    //Declares the variables as protected so only this class and subclasses can act on them
    protected int cdSku;        
    protected String cdName;               
    protected int cdCopies;
    protected double cdPrice;
    protected String genre;
    //Constructor
    CD(int cdSku, String cdName, int cdCopies, double cdPrice, String genre) {
        this.cdSku    = cdSku;
        this.cdName   = cdName;
        this.cdCopies = cdCopies;
        this.cdPrice  = cdPrice;
        this.genre = genre;
    // This method tells the sort method what is to be sorted     
    public int compareTo(Object o)
        return cdName.compareTo(((CD) o).getName());
    // Calculates the total value of the copies of a CD
    public double totalValue() {
        return cdCopies * cdPrice;
    // Tells the caller the title
    public String getName() {
        return cdName;       
    //Displays the information stored by the constructor
    public String toString() {
        return String.format("SKU=%2d   Name=%-20s   Stock=%3d   Price=$%6.2f   Value=$%,8.2f",
                              cdSku, cdName, cdCopies, cdPrice, totalValue());
} // end CD class    
     //Class used to add items to the inventory, display output for the inventory and sort the inventory
class Inventory {
    private CD[] cds;
    private int nCount;
     // Creates array cds[] with 10 element spaces
    Inventory() {
        cds = new CD[10];
        nCount = 0;
     // Used by main to input a CD object into the array cds[]
    public void add(CD cd) {
        cds[nCount] = cd;
        ++nCount;
        sort();               
     //Displays the arrays contents element by element
    public void display() {
        System.out.println("\nThere are " + nCount + " CD titles in the collection\n");
        for (int i = 0; i < nCount; i++)
            System.out.println(cds);
System.out.printf("\nTotal value of the inventory is $%,.2f\n\n", totalValue());
     // Steps through the array adding the totalValue for each CD to "total"
public double totalValue() {
double total = 0;
double restock = 0;
for (int i = 0; i < nCount; i++)
total += cds[i].totalValue();                
return total;
     //Method used to sort the array by the the name of the CD
private void sort() {
     Arrays.sort(cds, 0, nCount);
} // end Inventory class
// Subclass of CD. Creates new output string to be used, adds a restocking fee calculation and genre catagory to be displayed.
class CDWithGenre extends CD {
     String genre;
     CDWithGenre(int cdSku, String cdName, int cdCopies, double cdPrice, String genre) {
super(cdSku, cdName, cdCopies, cdPrice, genre);
this.cdName = cdName;
          this.cdCopies = cdCopies;
this.cdPrice = cdPrice;
this.genre = genre;
// Calculates restocking fee based on previous data.
public double restockFee() {
     double total = 0;
     double restock = 0;
     total = cdCopies * cdPrice;
     restock = total * .05;
return restock;
// New output method overrides superclass's output method with new data and format.
     public String toString() {
          return String.format("SKU: %2d     Genre: %-12s     Name: %-20s     \nPrice: $%6.2f Value: $%,8.2f Stock: %3d      Restocking Fee: $%6.2f\n",
cdSku, genre , cdName, cdPrice, totalValue(), cdCopies, restockFee());
     }// Ends CDWithGenre class
would I make a new class calling it GUI or whatever, in there extend JFrame and add a JTextArea and JScrollpane there? Would I need to make the class public or just an internal class?

Similar Messages

  • New to Graphics, trying to display array output in a single window

    I am trying to figure out how to use the GUI components of JAVA.
    What I am trying to do is take my packaged array output and list it in a single window. All that ever prints is last array data set. The last keeps overwritting the previous. How do I keep the previous data shown while listing the next in the array?
    Below are my three classes. The Frame Class is the class containing the display method. It is called near the bottom of the Product Class.
    Product.java
    // Inventory Program Part 4
    /* This program will store multiple entries
    for office supplies, give the inventory value,
    sort the data by Product Name,
    and output the results using a GUI */
    import javax.swing.text.JTextComponent;
    import javax.swing.JLabel;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.JOptionPane; //Uses class JOptionPane
    import java.util.Scanner; //Uses class Scanner
    import java.util.Arrays; //Uses class Arrays
    public class Product
         private String productBrand[]; // Declares the array
         public void setProductBrand( String brand[] ) // Declare setProductBrand method
              productBrand = brand; // stores the productbrand
         } // End setProductBrand method
         public String getProductBrand( int counter )  // Declares getProductBrand method
              return productBrand[ counter ]; // Returns data using counter to define the element
         } // End method getProductBrand
         public double restockingFee( double value ) // Declares restocking Fee method
              double fee = 0; // Declares variable fee
              fee = value * 0.05; // Calculates the sum of values
              return fee;  // Returns the restocking fee
         } // End method restockingFee     
         public String inventoryValue( double value[] , int number, String name[] ) // Declares inventoryValue method
              OfficeSupplies myOfficeSupplies = new OfficeSupplies();  //Creates OfficeSupplies Object
              Product myProduct = new Product();
              double total = 0; // Declares variable total
              for ( int counter = 0; counter < number ; counter++ )
                   total += ( value[ counter ] + myProduct.restockingFee( value[ counter ] ) ); // Calculates the sum of values
                        return String.format( "%s$%.2f", "Total Inventory Value: " , total );  // Returns the total value
         } // End method inventoryValue
         // main method begins execution
         public static void main( String args[] )
              Scanner input = new Scanner( System.in ); //Creates Scanner object to input from command window
              Product myProduct = new Product(); //Creates Product object
              OfficeSupplies myOfficeSupplies = new OfficeSupplies();  //Creates OfficeSupplies Object          
              //Prompt for maxNumber using JOptionPane
              String stringMaxNumber =
                   JOptionPane.showInputDialog( "Enter the number of products you wish to enter" );
              int maxNumber = Integer.parseInt( stringMaxNumber );     
              String prodName[] = new String[ maxNumber ]; // Declares prodName array
              int numberUnits[] = new int[ maxNumber ]; // Declares maxNumber array          
              float unitPrice[] = new float[ maxNumber ]; // Declares unitPrice array
              double value[] = new double[ maxNumber ]; // Declares value array
              String brand[] = new String [ maxNumber ]; // Declares brand array
              String stringNumberUnits[] = new String [ maxNumber]; // Declares array
              String stringUnitPrice[] = new String [ maxNumber ]; // Declares array
              int productNumber[] = new int[ maxNumber ]; // Declares array
              for ( int counter = 0; counter < maxNumber; counter++ ) // For loop for the number of products to enter
                   productNumber[ counter ] = counter;
                   myOfficeSupplies.setProductNumber( productNumber ); // Sends the Product name to method setProductNumber                         
                   //Prompt for product name using JOptionPane
                   prodName[ counter ] =
                        JOptionPane.showInputDialog( "Enter the Product Name" );
                   myOfficeSupplies.setProductName( prodName ); // Sends the Product name to method setProductName
                   //Prompt for brand name using JOptionPane
                   brand[ counter ] =
                        JOptionPane.showInputDialog( "Enter the Brand name of the Product" );
                   myProduct.setProductBrand( brand ); // Sends the Brand name to method setProductBrand
                   //Prompt for number of units using JOptionPane
                   stringNumberUnits[ counter ] =
                        JOptionPane.showInputDialog( "Enter the Number of Units" );
                   numberUnits[ counter ] = Integer.parseInt( stringNumberUnits[ counter ] );
                   myOfficeSupplies.setNumberUnits( numberUnits ); // Sends the Number Units to the method setNumberUnits
                   //Prompt for unit price using JOptionPane
                   stringUnitPrice[ counter ] =
                        JOptionPane.showInputDialog( "Enter the Unit Price" );
                   unitPrice[ counter ] = Float.parseFloat( stringUnitPrice[ counter ]);
                   myOfficeSupplies.setUnitPrice( unitPrice ); // Sends the Unit Price to the method setUnitPrice
                   value[ counter ] = numberUnits[ counter ] * unitPrice[ counter ]; // Calculates value for each item
                   myOfficeSupplies.setProductValue( value ); // Sends the product value to the method setProductValue
              Arrays.sort( prodName, String.CASE_INSENSITIVE_ORDER ); // Calls method sort from Class Arrays
                   Frame myFrame = new Frame();
                   myFrame.displayData( myProduct, myOfficeSupplies, maxNumber );
              // Outputs Total Inventory Value using a message dialog box
              JOptionPane.showMessageDialog( null, myProduct.inventoryValue( value, maxNumber, prodName ),
                   "Total Inventory Value", JOptionPane.PLAIN_MESSAGE );
         } // End method main
    } // end class ProductOfficeSupplies.java ----> This is the data container
    // Inventory Program Part 4
    /* Stores the array values */
    public class OfficeSupplies // Declaration for class Payroll
         private int productNumber[];
         public void setProductNumber( int number[] ) // Declare setProductNumber method
              productNumber = number; // stores the product number
         } // End setProductNumber method
         public int getProductNumber( int counter )  // Declares getProductNumber method
              return productNumber[ counter ];
         } // End method getProductNumber
         private String productName[];
         public void setProductName( String name[] ) // Declare setProductName method
              productName = name; // stores the Product name
         } // End setProductName method
         public String getProductName( int counter )  // Declares getProductName method
              return productName[ counter ];
         } // End method getProductName
         private int numberUnits[];
         public void setNumberUnits( int units[] ) // Declare setNumberUnits method
              numberUnits = units; // stores the number of units
         } // End setNumberUnits method
         public int getNumberUnits( int counter )  // Declares getNumberUnits method
              return numberUnits[ counter ];
         } // End method getNumberUnits
         private float unitPrice[];
         public void setUnitPrice( float price[] ) // Declare setUnitPrice method
              unitPrice = price; // stores the unit price
         } // End setUnitPrice method
         public float getUnitPrice( int counter )  // Declares getUnitPrice method
              return unitPrice [ counter ];
         } // End method getUnitPrice
         private double productValue[];
         public void setProductValue( double value[] ) // Declare setProductValue method
              productValue = value; // stores the product value
         } // End setProductValue method
         public double getProductValue( int counter )  // Declares getProductValue method
              return productValue[ counter ];
         } // End method getProductValue
    } // end class OfficeSuppliesFrame.java ------> Contains the display method
    import java.awt.Color;
    import javax.swing.text.JTextComponent;
    import javax.swing.JLabel;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.JOptionPane; //Uses class JOptionPane
    public class Frame extends JFrame
         public Frame() //Method declaration
              super( "Products" );
         } // end frame constructor
         public void displayData( Product myProduct, OfficeSupplies myOfficeSupplies, int maxNumber )
              //Here I attempted to use an array to output all of the array data in a single window
    //          JTextArea myTextArea[] = new JTextArea[ maxNumber ]; // Declares myTextArea array to display output
              JTextArea myTextArea = new JTextArea(); // textarea to display output
              // For loop to display data array in a single Window
              for ( int counter = 0; counter < maxNumber; counter++ )  // Loop for displaying each product
    //               myTextArea[ counter ].setText( packageData( myProduct, myOfficeSupplies, counter ) + "\n" );
    //                add( myTextArea[ counter ] ); // add textarea to JFrame
                   myTextArea.setText( packageData( myProduct, myOfficeSupplies, counter ) + "\n" );
                   add( myTextArea ); // add textarea to JFrame
              } // End For Loop
              setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              setSize( 450, maxNumber*400 ); // set frame size
              setVisible( true ); // display frame
         public String packageData( Product myProduct, OfficeSupplies myOfficeSupplies, int counter ) // Method for formatting output
              return String.format( "%s: %d\n%s: %s\n%s: %s\n%s: %s\n%s: $%.2f\n%s: $%.2f\n%s: $%.2f\n%s: $%.2f",
              "Product Number", myOfficeSupplies.getProductNumber( counter ),
              "Product Name", myOfficeSupplies.getProductName( counter ),
              "Product Brand",myProduct.getProductBrand( counter ),
              "Number of Units in stock", myOfficeSupplies.getNumberUnits( counter ),
              "Price per Unit", myOfficeSupplies.getUnitPrice( counter ),
              "Total Value of Item in Stock is", myOfficeSupplies.getProductValue( counter ),
              "Restock charge this product is", myProduct.restockingFee( myOfficeSupplies.getProductValue( counter ) ),
              "Total Value of Inventory plus restocking fee", myOfficeSupplies.getProductValue( counter )+
                   myProduct.restockingFee( myOfficeSupplies.getProductValue( counter ) ) );
         } // end method packageData
    }

    Lets pretend that your assignment was to manage a list of employees of a store, and that each employee is identified by their name, position, and hourly wage. If you created a program along the lines of your current product program, I picture you creating three separate ArrayLists (or arrays), one for each variable, something like this:
    import java.util.ArrayList;
    public class MyEmployees1
        private ArrayList<String> names = new ArrayList<String>();
        private ArrayList<String> positions = new ArrayList<String>();
        private ArrayList<Double> hourlyWages = new ArrayList<Double>();
        public void add(String name, String position, double wage)
            names.add(name);
            positions.add( position);
            hourlyWages.add(wage);
        public void removed()
            // TODO: I am nervous about trying to manage this!
        //.......... more
    }This program tries to manage three separate parallel arrays (arraylists actually). They are parallel because the 3rd item in the names list corresponds to the 3rd item in the positions list and also the hourlywages list. If I wanted to delete data, I'd have to be very careful to delete the correct item in all three lists. If I tried to sort one list, I'd have to sort the other two in exactly the same way. It is extremely easy to mess this sort of program up.
    Now lets look at a different approach. Say we created a MyEmployee class that contains the employee's name, position, and wage, along with the appropriate constructors, getters, setters, toString method, etc... something like so:
    import java.text.NumberFormat;
    public class MyEmployee
        private String name;
        private String position;
        private double hourlyWage;
        public MyEmployee(String name, String position, double hourlyWage)
            this.name = name;
            this.position = position;
            this.hourlyWage = hourlyWage;
        public String getName()
            return name;
        public String getPosition()
            return position;
        public double getHourlyWage()
            return hourlyWage;
        public String toString()
            // don't worry about these methods here.  They're just to make the output look nice
            NumberFormat currency = NumberFormat.getCurrencyInstance();
            return String.format("Name: %-15s    Position: %-15s    Wage: %s",
                    name, position, currency.format(hourlyWage));
    }Now I can create a MyEmployees2 class that holds a single list of MyEmployee objects, like so:
    import java.util.ArrayList;
    public class MyEmployees2
        private ArrayList<MyEmployee> employeeList = new ArrayList<MyEmployee>();
        public boolean add(MyEmployee employee)
            return employeeList.add(employee);
        public boolean remove(MyEmployee employee)
            return employeeList.remove(employee);
        public void display()
            for (MyEmployee employee : employeeList)
                System.out.println(employee);
        public static void main(String[] args)
            MyEmployees2 empl2 = new MyEmployees2();
            empl2.add(new MyEmployee("John Smith", "Salesman", 20));
            empl2.add(new MyEmployee("Jane Smyth", "Salesman", 25));
            empl2.add(new MyEmployee("Fred Flinstone", "Janitor", 15));
            empl2.add(new MyEmployee("Barney Rubble", "Supervisor", 35));
            empl2.add(new MyEmployee("Mr. Spacely", "The Big Boss", 45));
            empl2.display();
    }Now if I want to add an Employee, I only add to one list. Same if I want to remove, only one list, and of course, the same for sorting. It is much safer and easier to do things this way. Make sense?

  • How do I get an array output on a Formula Node?

    My problem is simply that I cannot figure out how to get an output on a Formula Node to be an array. Documentation states that "you must declare local arrays and output arrays in the Formula Node" but doesn't say anything more than than. Attempts to put something like "float32 out[100];" for an array output called "out" fail.
    If anybody knows how you can do this or even knows if it is possible I would appriciate your help.
    Thanks,
    Naveen

    I found a typo in the formula node I was doing that was making the output not be an array. I don't think I was getting the error before but I was going to put together an example VI to attach here and I found it. So, thanks for your help even tho it was a stupid little mistake on my part.

  • How to view C/C++   pointer as an array in Xcode GUI debugger?

    How to view C/C++ pointer as an array in Xcode GUI debugger?

    A similar question was asked recently regarding strings. You cannot pass pointers in LabVIEW as you do in C. You can pass an array to a DLL, but that means you would need to write a wrapper DLL. Be sure to read the section in the LabVIEW Help on calling code from text-based languages and also take a look at the "Call DLL" example that ships with LabVIEW  - it contains many examples of how to deal with various datatypes.

  • Array output from formula node with input variable as array size

    Hi,
    I have created a formula node with an array output called al, but I get an error "you have connected a scalar type to an array with that type".
    I declare the output as follows..
    float64 al[len_as];
    where len_as is an scalar input to the formula node.
    It only works when I put a number as.
    float64 al[5];
    ,but I don't know beforehand how many elements I need, so I cannot use this.
    Please help! This is so stupid.
    Thanks

    Don't define your array in your formula node.
    Initialize the array as the size you want and pass it in as an input into the formula node.
    Are you sure you even need to use a formula node?  Can you implement your formula using all native LabVIEW functions?
    Message Edited by Ravens Fan on 10-07-2009 11:51 PM
    Attachments:
    Example_VI_BD.png ‏3 KB

  • Array output from formula node

    How to get an array output from the formula node.I am trying to use a for loop inside the formula node and want an array output.

    You cannot place a For or While Loop inside the formula node.
    Here is what the Help Description says about the syntax inside the Formula Node:
    Formula Node
    Evaluates mathematical formulas and expressions similar to C on the block diagram. The following built-in functions are allowed in formulas: abs, acos, acosh, asin, asinh, atan, atan2, atanh, ceil, cos, cosh, cot, csc, exp, expm1, floor, getexp, getman, int, intrz, ln, lnp1, log, log2, max, min, mod, pow, rand, rem, sec, sign, sin, sinc, sinh, sizeOfDim, sqrt, tan, tanh. There are some differences between the parser in the Mathematics VIs and the Formula Node.
     Place on the block diagram
     Find on the Functions palette
    Refer to Creating Formula Nodes and Formula Node Syntax for more information about the Formula Node and the Formula Node syntax.
    Note  The Formula Node accepts only the period (.) as a decimal separator. The node does not recognize localized decimal separators.
    <SCRIPT type=text/javascript>if (typeof(writeVarRefs)=="function"){writeVarRefs("763");}</SCRIPT>
    <SCRIPT type=text/javascript> if(typeof(lvrthelp763) != "undefined"){document.writeln(lvrthelp763)}</SCRIPT>
    <SCRIPT type=text/javascript> if(typeof(lvfpga763) != "undefined"){document.writeln(lvfpga763)}</SCRIPT>
    <SCRIPT type=text/javascript> if(typeof(lvemb763) != "undefined"){document.writeln(lvemb763)}</SCRIPT>
    <SCRIPT type=text/javascript> if(typeof(lvpdahelp763) != "undefined"){document.writeln(lvpdahelp763)}</SCRIPT>
    <SCRIPT type=text/javascript> if(typeof(lvtpchelp763) != "undefined"){document.writeln(lvtpchelp763)}</SCRIPT>
    <SCRIPT type=text/javascript> if(typeof(lvblackfin763) != "undefined"){document.writeln(lvblackfin763)}</SCRIPT>
    <SCRIPT type=text/javascript> if(typeof(lvdsp763) != "undefined"){document.writeln(lvdsp763)}</SCRIPT>
    Example
    Refer to the Create Function with Formula Node VI in the labview\examples\general\structs.llb for an example of using the Formula Node.

  • Variable size array output from dynamic dispatch class method on FPGA

    I have a Parent class on the FPGA that will serve as a template/framework for future code that will be developed. I had planned on creating a child class and overriding a couple methods. The child class constant would be dropped on the block diagram so the compiler wouldn't have any trouble figuring out which method (parent's or child's) should be used (i.e. the parent's method will never actually be used and won't be compiled with the main code). The output of one of the methods is an array. This array will have a different size depending on the application. I defined the array size as variable. In the child method, there is no question about the size of the array so the compiler should be able to figure it out. However, when I try to compile, I get an error about the array size. I can't figure out any way around it. Any thought would be greatly appreciated! 
    Thanks, Patrick
    Solved!
    Go to Solution.
    Attachments:
    FPGA Test.zip ‏1194 KB

    Wait what?
    Can we use dynamic dispatch VIs on FPGA?  Really?  I was completely unaware of this.  Obviously the dependencies need to be constant and known at compile time but...... This would have saved me a lot of headaches in the last few months.
    Since which LV version is this supported?
    Say hello to my little friend.
    RFC 2323 FHE-Compliant

  • 2D array output in a loop

    Hello,
    I need output data (several array string) from FOR-loop to 2D array. I use Replace array subset inside the loop (after array initialize). Output works (I see each step right string in its right place), But each next loop clear all previous strings to 0 0 0 . Finally stay only the last string in result array (see fig). Output to file works perfectly.
    Similarly, no result outside of loop. 
    WHY?
    I'm beginner...
    Solved!
    Go to Solution.

    Hi zazra,
    But outside Out_array 2 and Out_array are empty (grey zero fields). 
    THINK DATAFLOW!
    Those two array indicators stay empty UNTIL the FOR loop finishes!
    How to use out_array 4 - data outside the loop?
    Either finish the FOR loop - or use a local variable (as easiest, but not the only solution)…
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Array output question

    Hello,
    I'm trying to get this foreach to output to HTML.
    What I need help with is how to make this report output the array data.
    $MyCollection = @()
    $arrViewPropertiesToGet = "Name","Summary.Runtime.PowerState","Config.GuestFullName","Summary.Config.Annotation","CustomValue","AvailableField"
    foreach ($cluster in Get-Cluster) {
        Get-View -ViewType VirtualMachine -Property $arrViewPropertiesToGet -SearchRoot $cluster.id | Select `
      @{n="VM name"; e={$_.Name}},
            @{n="Cluster"; e={$cluster.name}},
      #@{n="PowerState"; e={$_.Summary.Runtime.PowerState}},
            @{n="Guest OS"; e={$_.Config.GuestFullName}},
            @{n="Notes"; e={$_.Summary.Config.Annotation}},
            ## just using the data already retrieved; far faster
            @{n="Tier"; e={$viewThisVM = $_; ($viewThisVM.CustomValue | ?{$_.Key -eq ($viewThisVM.AvailableField | ?{$_.Name -eq "Tier"}).Key}).Value}}
      $MyCollection += $viewThisVM
    } ## end foreach
    $MyCollection | ConvertTo-HTML -Fragment | Set-Content c:\temp\test.htm
    Invoke-Expression C:\temp\test.htm
    Here is what I know how to do, but need help with the array part, everything else is working great.
    #Sample Code
    Get-Service | Select-Object Status, Name, DisplayName | ConvertTo-HTML | Out-File C:\Scripts\Test.htm
    Invoke-Expression C:\Scripts\Test.htm
    Thanks,
    -Mike

    Hi sneddo,
    That is the complete script.
    $MyCollection = @()
    $arrViewPropertiesToGet = "Name","Summary.Runtime.PowerState","Config.GuestFullName","Summary.Config.Annotation","CustomValue","AvailableField"
    foreach ($cluster in Get-Cluster) {
        Get-View -ViewType VirtualMachine -Property $arrViewPropertiesToGet -SearchRoot $cluster.id | Select `
      @{n="VM name"; e={$_.Name}},
            @{n="Cluster"; e={$cluster.name}},
      #@{n="PowerState"; e={$_.Summary.Runtime.PowerState}},
            @{n="Guest OS"; e={$_.Config.GuestFullName}},
            @{n="Notes"; e={$_.Summary.Config.Annotation}},
            ## just using the data already retrieved; far faster
            @{n="Tier"; e={$viewThisVM = $_; ($viewThisVM.CustomValue | ?{$_.Key -eq ($viewThisVM.AvailableField | ?{$_.Name -eq "Tier"}).Key}).Value}}
      $MyCollection += $viewThisVM # we can delete this line, I was testing here.
    } ## end foreach
    $MyCollection | ConvertTo-HTML -Fragment | Set-Content c:\temp\test.htm
    If you test this part in your lab it works great.
    $arrViewPropertiesToGet = "Name","Summary.Runtime.PowerState","Config.GuestFullName","Summary.Config.Annotation","CustomValue","AvailableField"
    foreach ($cluster in Get-Cluster) {
        Get-View -ViewType VirtualMachine -Property $arrViewPropertiesToGet -SearchRoot $cluster.id | Select `
      @{n="VM name"; e={$_.Name}},
            @{n="Cluster"; e={$cluster.name}},
      #@{n="PowerState"; e={$_.Summary.Runtime.PowerState}},
            @{n="Guest OS"; e={$_.Config.GuestFullName}},
            @{n="Notes"; e={$_.Summary.Config.Annotation}},
            ## just using the data already retrieved; far faster
            @{n="Tier"; e={$viewThisVM = $_; ($viewThisVM.CustomValue | ?{$_.Key -eq ($viewThisVM.AvailableField | ?{$_.Name -eq "Tier"}).Key}).Value}}
    } ## end foreach
    I just need this part to export to a HTML Web Page.
    Thanks,

  • In formula node how to use array outputs

    someone has talked about this. but it is still a problem to me.
    no matter how i declare the variable, the output terminal keeps a scalar.

    You should be able to declare it using:
    int32 VarName[x][y];
    That should make an array of 32bit integers.
    See one of my earlier posts here: http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=135&HOID=506500000008000000EE2C0000&UCATEGORY_0=_49_%24_6_&UCATEGORY_S=0&USEARCHCONTEXT_TIER_0=0&USEARCHCONTEXT_TIER_S=0&USEARCHCONTEXT_QUESTION_0=array+formula+node&USEARCHCONTEXT_QUESTION_S=0
    Try copying the code that I posted into your formula node and see if you get an array out. Or try the example I attached with the same code in it.
    Let us know if you are still having trouble.
    Brian
    Attachments:
    ArrayFormulaNode.vi ‏23 KB

  • Array output of a Labview dll

    Hi all,
    I haven´t found the solution in the posts of this forum, if somebody has, please inform me.
    I want to output an array from a dll compiled in LV7.1. It doesn´t work. I have tried all the combinations of Array Data Pointer & Array Handle Pointer, and the two calling conventions, and it doesn´t work. My output array (Y) is always the unchanged input array. Any idea?

    Whithout having your DLL it's difficult to say why your code is not working. There are different ways to pass array data, please also have a look at the examples that are contained in LabVIEW.
    You can also find a pretty good tutorial here 

  • Formatting array output

    how do i format the output of an array so that only a certain number of the elements print per line. i know this is basic, i am a beginner and need help.

    final int itemsPerLine = 5;
    int counter = 0;
    String myArray[]; // This will contain your array
    while (counter < myArray.length) {
        System.out.print(myArray[counter]; // Print out the item
        counter++; // increment our counter;
        if (counter%itemsPerLine == 0) {
            System.out.print("\n"); // ad a line return
    }This is one example. It prints out the next string in the array (which you need to initialise and populate first), increments the counter, then checks the modulus to see if its time for a newline.
    Rob.

  • LabVIEW DLL 2D Array output deallocati​on

    Hey everyone,
    I am using a custom built DLL made with LabVIEW.  One of the functions outputs a 2D array of data by "handle".  I can catch the 2D array from the function just fine from within my C program, however I have a question about deallocating the memory allocated by the LabVIEW DLL for the 2D array.
    I call the DLL function repeatedly in a loop and as this occurs the RAM used on my machine continues to increase until it is full or I exit the program.  There are no other dynamically allocated peices of data within the C program that could be causing this.
    The question is, can I call free() on the 2D array handle safely?  Is this the correct way to deallocate the 2D arrays passed out of LabVIEW DLL functions?  One dimension of the 2D array is always the same size, but the other dimension varies per call.
    Here is an example (I have renamed function calls and library headers due to security reasons):
    #include "DLLHeader.h"
    int main(void)
        ResponseArrayHdl myArray = NULL;
        DLL_FUNC_InitializeLibrary();
        DLL_FUNC_ConfigurePortWithDefaults("COM3");
        DLL_FUNC_StartAutoSend(9999999);
        while(DLL_FUNC_IsTransmitting())
            DLL_FUNC_GetAllAvailableResponseMessagesByHndl(&my​Array);      // gets the 2D array
            // do something with array data here!
            free(myArray);   // is this the appropriate way to clean up the array?
            Delay(0.05);
        DLL_FUNC_GetAllAvailableResponseMessagesByHndl(&my​Array);      // gets the 2D array
        // do something with array data here!
        free(myArray);   // is this the appropriate way to clean up the array?
        DLL_FUNC_ShutdownLibrary();
        return 0;
    from DLLHeader.h:
    typedef struct {
        } ResponseMessage;      // created by the LabVIEW DLL build process
    typedef struct {
        long dimSize;
        ResponseMessage Responses[1];
        } ResponseArray;
    typedef ResponseArray **ResponseArrayHdl;   // created by the LabVIEW DLL build process
    I want to make sure this is an appropriate technique to deallocate that memory, and if not, what is the appropriate way?  I am using LabVIEW 7.1 if that matters.  The C program is just ANSI C and can be compiled with any ANSI C compliant compiler.
    Thanks!
    ~ Jeramy
    CLA, CCVID, Certified Instructor

    Tunde A wrote:
    A relevant function that will be applicable in this case (to free the memory) is the "AZDisposeHandle or DSDisposeHandle". For more information on this function and other memory management functions, checkout the " Using External Code in LabVIEW" reference manual, chapter 6 (Function Description), Memory Management Functions.
    Tunde
    One specific extra info. All variable sized LabVIEW data that can be accessed by the diagram or are passed as native DLL function parameters use always DS handles, except the paths which are stored as AZ handles (But for paths you should use the specific FDisposePath function instead).
    So in your case you would call DSDisposeHandle on the handle returned by the DLL. But if the array itself is of variable sized contents (strings, arrays, paths) you will have to first go through the entire array and dispose its internal handles before disposing the main array too.
    Rolf Kalbermatter
    Message Edited by rolfk on 01-10-2007 10:43 PM
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Newbie Seeking Help With Array Output!

    Hey all, I'm new here, so here goes nothing! :) I'm in my first programming class at college, and we need to output multiple arrays. We're using JTextAreas and I'm not sure how I should go about this, but this is what I have so far:
    import java.io.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class Application1
    public Application1()
    String name[]={"Mary","John","William","Debbie","Ralph"};
    int temp[]={34,24,78,65,45,100,90,97,56,89,78,98,74,90,98,24,45,76,89,54,12,20,22,55,6};
    int [][]scores=new int[8][8];
    float []avg=new float[5];
    char []lettergrade={'F','F','F','F','F'}; //Initialized at "F" and replaced by their actual grade
    String out="";
    move_score(temp,scores);
    tot_hi_low(scores);
    average(scores,avg,lettergrade); //Calculates Average and Letter Grade
    graph(scores,avg);
    JTextArea outarea=new JTextArea(8,8); //Output
    out+="Name\t"+"Test1\t"+"Test2\t"+"Test3\t"+"Test4\t"+"Final\t"+"Total\t"+"High\t"+"Low\t"+scores;
    outarea.setText(out);
    JOptionPane.showMessageDialog(null,outarea);
    public void move_score(int temporary[],int sc[][])
    int c=0;
    for(int a=0;a<=4;a++) //Moves values of "temp" into 2D array "scores"
    for(int b=0;b<=4;b++)
    sc[a]=temporary[c];
    c++;
    public void tot_hi_low(int [][]score)
    int d=100; //Low Variable
    int e=-1; //High Variable
    for(int r=0;r<=4;r++)
    for(int c=0;c<=4;c++)
    score[r][5]+=score[r][c]; //Total for Columns
    score[5][r]+=score[c][r]; //Total for Rows
    if(score[r][c]>e) //High for Columns
    e=score[r][c];
    score[r][6]=e;
    if(score[c][r]>e) //High for Rows
    e=score[c][r];
    score[6][r]=e;
    if(score[r][c]<d) //Low for Columns
    d=score[r][c];
    score[r][7]=d;
    if(score[c][r]<d) //Low for Rows
    d=score[c][r];
    score[7][r]=d;
    public void average(int [][]score,float []avg,char []grade){
    int l=800;
    for(int a=0;a<=4;a++)
    for(int b=0;b<=3;b++)
    if(score[a][b]<l)
    l=score[a][b];
    avg[a]=(score[a][5]-l+score[a][4])/5.0f;
    if(avg[a]>=60) //Assigns Letter Grades
    grade[a]='D';
    if(avg[a]>=70)
    grade[a]='C';
    if(avg[a]>=80)
    grade[a]='B';
    if(avg[a]>=90)
    grade[a]='A';
    public void graph(int [][]score,float []average){
    //DECLARE EVERYTHING HERE
    //DECLARE ARRAYS
    public static void main(String args[]){
    Application1 app=new Application1();
    System.exit(0);

    Ah sorry about that; like I said I'm fresh off the 'coding' boat. What I meant to ask in my original post is: "Could someone show me an example of how I could get arrays into output?" I am definately not looking for someone to do my work for me, but I am at a dead end, and would appreciate any examples or even tips! Here is what I have:
    import java.io.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class Application1
    public Application1()
    String name[]={"Mary","John","William","Debbie","Ralph"};
    int temp[]={34,24,78,65,45,100,90,97,56,89,78,98,74,90,98,24,45,76,89,54,12,20,22,55,6};
    int [][]scores=new int[8][8];
    float []avg=new float[5];
    char []lettergrade={'F','F','F','F','F'}; //Initialized at "F" and replaced by their actual grade
    String out="";
    move_score(temp,scores);
    tot_hi_low(scores);
    average(scores,avg,lettergrade); //Calculates Average and Letter Grade
    graph(scores,avg);
    JTextArea outarea=new JTextArea(8,8); //Output
    out+="Name\t"+"Test1\t"+"Test2\t"+"Test3\t"+"Test4\t"+"Final\t"+"Total\t"+"High\t"+"Low\n"+scores;
    outarea.setText(out);
    JOptionPane.showMessageDialog(null,outarea);
    public void move_score(int temporary[],int sc[][])
    int c=0;
    for(int a=0;a<=4;a++) //Moves values of "temp" into 2D array "scores"
    for(int b=0;b<=4;b++)
    sc[a]=temporary[c];
    c++;
    public void tot_hi_low(int [][]score)
    int d=100; //Low Variable
    int e=-1; //High Variable
    for(int r=0;r<=4;r++)
    for(int c=0;c<=4;c++)
    score[r][5]+=score[r][c]; //Total for Columns
    score[5][r]+=score[c][r]; //Total for Rows
    if(score[r][c]>e) //High for Columns
    e=score[r][c];
    score[r][6]=e;
    if(score[c][r]>e) //High for Rows
    e=score[c][r];
    score[6][r]=e;
    if(score[r][c]<d) //Low for Columns
    d=score[r][c];
    score[r][7]=d;
    if(score[c][r]><d) //Low for Rows
    d=score[c][r];
    score[7][r]=d;
    public void average(int [][]score,float []avg,char []grade){
    int l=800;
    for(int a=0;a<=4;a++)
    for(int b=0;b<=3;b++)
    if(score[a]><l)
    l=score[a];
    avg[a]=(score[a][5]-l+score[a][4])/5.0f;
    if(avg[a]>=60) //Assigns Letter Grades
    grade[a]='D';
    if(avg[a]>=70)
    grade[a]='C';
    if(avg[a]>=80)
    grade[a]='B';
    if(avg[a]>=90)
    grade[a]='A';
    public void graph(int [][]score,float []average){
    public static void main(String args[]){
    Application1 app=new Application1();
    System.exit(0);
    }I want to get my scores array into my JTextArea, but the array isn't displaying as I intended it to. Any help would be incredibly useful!

  • Linking output to gui

    Im trying to link the output text terminals contents to be displayed within the gui, is using a JtextArea the correct way to do this, and also is there a shortcut such as copying the contents straight into the gui window? ive checked the APi but have either overlooked or cant find an item to do this.
    thanks!

    If I understand you, there is no shot cut to using setText or append. One
    handy method that is often overlooked is
    read(Reader , Object )
    Which would help copy from a file, but not from the console, unless stdin is
    being redirected from a file :-)

Maybe you are looking for

  • How do I combine duration with hourly rate?

    I've just started using Numbers, and am having trouble recreating my Excel billing sheet. I'm trying to create a spreadsheet which will track the time spent on a task, and then calculate the billable cost for that task based on my hourly rate. So far

  • RMAN error while allocating channels

    Hi We are trying to backup Oracle 11gr2 database using RMAN. The MML is provided by the vendor and we have linked the library with libobk.so. The server OS is Solaris 10 64 bit on AMD64 architecture. When we try to run backup the RMAN returns with th

  • 100% Cheapest and easiest way to Charge iPhone 3G in your car - Works

    OK So i have spent a long time in these forums, and other forums, looking for a way to charge the iPhone 3G in my car. There have been lots of posts explaining why current chargers wont work and because of the firewire pins being removed etc, yet noo

  • BES error when trying to download

    Hi! I've got a Bold Touch 9900 with BlackBerry Internet Service activated from my carrier. Mail, web, Facebook, everything works great but when I acces the AppWorld and try to download an application, I get the error that I don't have the right to in

  • Error 1406.Could not write value  to key

    When I at almost done installing iTunes, I get this error message, everytime whether I do it from the CD that came with my iPod or if I download it from apple.com and try to install it. For the sufficient access part (In full error message below), I