Wrong array output
Could someone please help me? I am trying to print out the same array, except with no duplicates. This is what I have and it is compiling, but when I run it, the ouput is not even close. It should be: 3.7 3.8 4.0 5.2
<code>
public class Test3
public static void main(String[] args)
double[] array = {3.7, 3.8, 3.8, 4.0, 4.0, 4.0, 5.2};
double[] dTemp = new double[array.length];
int k;
k = -1;
for(int j = 0; j < array.length; j++)
if(array[j] == array[j++])
j++;
else
k++;
array = dTemp;
System.out.println(dTemp);
Any help is appreciated and I thank you beforehand!
public class Test3 {
public static void main(String[] args) {
double[] array = {3.7, 3.8, 3.8, 4.0, 4.0, 4.0, 5.2};
double[] dTemp = new double[array.length];
int k;
k = -1;
for(int j = 0; j < array.length; j++) {
if(array[j] == array[j+1]) {
j++;
} else {
k++;
dTemp[k] = array[j];
}According to the above, when j = array[j], array[j+1] will be larger than the largest index of the array. Therefore, ArrayIndexOutOfBound will be thrown.
So, try the following:
public class Test3 {
public static void main(String[] args) {
double[] array = {3.7, 3.8, 3.8, 4.0, 4.0, 4.0, 5.2};
double[] dTemp = new double[array.length];
dTemp[0] = array[0]; // Since the first one will never be the same as
// the previous, just put it to the temp array
int k;
k = 0;
for(int j = 1; j < array.length; j++) {
if (array[j] == array[j-1]) {
j++;
} else {
k++;
dTemp[k] = array[j];
Similar Messages
-
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,
NaveenI 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.
-
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? -
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.
ThanksDon'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. -
Wrong query output..
Guys,
Please can someone help me ? I am getting a wrong query output.. There is data available for 31-DEC-2006 but the below query doesn't seem to display it.. What could be the reason ? The query displays results for all date except 31st
SELECT date_inserted ||','||
COUNT (DECODE (HR, '00', user_id)
) ||','||
COUNT (DECODE (HR, '01', user_id)
) ||','||
COUNT (DECODE (HR, '02', user_id)
) ||','||
COUNT (DECODE (HR, '03', user_id)
) ||','||
COUNT (DECODE (HR, '04', user_id)
) ||','||
COUNT (DECODE (HR, '05', user_id)
) ||','||
COUNT (DECODE (HR, '06', user_id)
) ||','||
COUNT (DECODE (HR, '07', user_id)
) ||','||
COUNT (DECODE (HR, '08', user_id)
) ||','||
COUNT (DECODE (HR, '09', user_id)
) ||','||
COUNT (DECODE (HR, '10', user_id)
) ||','||
COUNT (DECODE (HR, '11', user_id)
) ||','||
COUNT (DECODE (HR, '12', user_id)
) ||','||
COUNT (DECODE (HR, '13', user_id)
) ||','||
COUNT (DECODE (HR, '14', user_id)
) ||','||
COUNT (DECODE (HR, '15', user_id)
) ||','||
COUNT (DECODE (HR, '16', user_id)
) ||','||
COUNT (DECODE (HR, '17', user_id)
) ||','||
COUNT (DECODE (HR, '18', user_id)
) ||','||
COUNT (DECODE (HR, '19', user_id)
) ||','||
COUNT (DECODE (HR, '20', user_id)
) ||','||
COUNT (DECODE (HR, '21', user_id)
) ||','||
COUNT (DECODE (HR, '22', user_id)
) ||','||
COUNT (DECODE (HR, '23', user_id)
) ||','
FROM (
select distinct user_id,
trunc(date_inserted) date_inserted,
to_char(date_inserted,'HH24') HR
from production.gl_user_game_sessions ugs
where date_inserted between '01-DEC-2006' and '31-DEC-2006'
AND exists( select 1
from production.gl_user_registrations gur
where gur.registration_site = 'rokes.com'
and gur.user_id = ugs.user_id)
order by user_id,trunc(date_inserted))
group by date_inserted
order by date_inserted
Date,00:00 to 00:59,01:00 to 01:59,02:00 to 02:59,03:00 to 03:59,04:00 to 04:59,05:00 to 05:59,06:00
01-DEC-06,66,47,23,20,11,9,23,45,59,82,68,78,77,87,85,101,118,129,129,140,139,142,132,111,
02-DEC-06,88,53,29,24,15,19,15,38,53,66,83,96,85,116,128,139,133,132,123,102,133,125,113,113,
03-DEC-06,100,68,45,23,18,14,21,19,42,75,87,87,82,92,103,72,0,111,225,170,165,125,124,81,
04-DEC-06,70,42,25,36,8,15,22,35,58,68,54,75,78,78,101,90,125,130,132,112,107,132,122,81,
05-DEC-06,56,44,25,12,6,16,28,28,69,89,65,75,67,86,110,90,104,123,123,144,137,140,109,83,
06-DEC-06,54,36,24,11,12,13,21,28,60,72,61,89,67,73,105,94,104,106,131,127,170,123,134,85,
07-DEC-06,58,26,23,17,11,9,22,31,59,63,69,75,82,79,103,79,102,106,150,138,178,163,126,103,
08-DEC-06,59,45,19,17,12,10,24,35,59,57,75,64,68,59,92,101,108,123,131,119,133,129,110,80,
09-DEC-06,77,50,28,21,14,16,19,32,65,61,69,87,107,109,106,114,121,122,94,113,113,110,131,101,
10-DEC-06,73,57,42,16,21,18,20,25,34,61,44,88,62,88,96,127,140,107,141,115,117,126,93,78,
11-DEC-06,58,32,17,8,6,8,14,29,57,62,76,73,58,72,96,95,102,98,129,126,124,148,117,92,
12-DEC-06,67,37,20,15,11,16,19,33,62,76,75,55,67,71,75,98,103,101,116,119,134,121,120,88,
13-DEC-06,57,37,11,15,3,14,2,0,9,73,61,59,59,75,85,87,97,107,122,124,143,129,124,105,
14-DEC-06,55,39,14,16,11,17,25,35,40,61,54,62,69,68,87,79,108,99,118,132,132,142,124,82,
15-DEC-06,69,39,21,26,12,13,17,27,50,64,69,60,74,88,88,92,115,105,114,127,106,123,117,114,
16-DEC-06,77,59,27,24,20,16,17,24,41,68,75,98,82,87,90,111,103,122,102,99,131,71,117,103,
17-DEC-06,84,47,22,17,13,13,12,25,40,59,45,56,72,82,85,96,88,106,107,117,149,116,105,82,
18-DEC-06,51,24,29,12,15,10,10,28,38,38,48,47,59,80,72,74,91,103,100,116,119,123,139,83,
19-DEC-06,53,36,17,12,11,23,20,29,58,77,70,71,62,83,81,89,106,104,101,120,130,118,125,94,
20-DEC-06,60,32,12,18,11,14,17,27,53,56,66,67,76,65,103,103,125,92,112,123,109,130,108,86,
21-DEC-06,50,29,22,16,9,12,22,34,35,58,78,71,62,85,101,105,110,124,129,147,156,129,108,88,
22-DEC-06,64,36,23,28,20,14,31,44,58,49,65,78,76,81,109,117,139,138,141,121,112,130,128,94,
23-DEC-06,95,67,31,28,22,13,21,32,40,48,80,76,83,105,123,126,118,155,131,124,147,124,135,106,
24-DEC-06,84,53,44,31,15,18,22,33,36,58,76,82,91,90,113,124,118,113,98,108,117,124,107,91,
25-DEC-06,71,54,40,15,12,20,17,22,38,61,56,70,63,73,94,93,109,97,87,100,98,109,85,84,
26-DEC-06,56,45,18,23,13,14,14,18,35,48,73,82,95,115,143,153,136,147,111,110,138,125,96,85,
27-DEC-06,82,42,27,18,13,13,27,18,37,60,65,87,78,94,164,166,171,147,160,143,120,150,118,115,
28-DEC-06,98,51,38,28,18,22,16,25,49,57,78,82,95,129,145,135,145,142,133,157,183,165,131,136,
29-DEC-06,93,62,32,20,16,13,24,31,51,72,71,84,96,110,179,166,190,167,156,153,142,162,148,114,
30-DEC-06,94,66,44,28,18,18,21,21,41,53,95,87,91,139,161,154,201,162,150,166,152,128,144,133,
SQL> Thanks in advance
GHi,
try this:
where date_inserted between to_date('01-DEC-2006 00:00:00','DD-MM-YYYY HH24:MI:SS') and to_date('31-DEC-2006 23:59:59' 'DD-MM-YYYY HH24:MI:SS')(not tested) -
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 KBWait 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 -
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 -
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,
-MikeHi 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 -
Wrong classes output directory when use of dependant projects
Hi,
JDev 10.1.2.1 but also in previous versions.
Windows XP Prof, AMD Athlon, 1 Go Mem
I have following setup:
Projects:
DTO (data transfer objects and utility classes used in other projects)
-> dependies: none
Directory tree:
MyWorkspace\DTO\classes
MyWorkspace\DTO\src
Model (model classes)
-> dependies: DTO
Directory tree:
MyWorkspace\Model\classes
MyWorkspace\Model\src
View (JClient app)
-> dependies: DTO, Model
Directory tree:
MyWorkspace\View\classes
MyWorkspace\View\src
WebView (Struts app)
-> dependies: DTO, Model
Directory tree:
MyWorkspace\WebView\deploy
MyWorkspace\WebView\model
MyWorkspace\WebView\public_html
For some unexplained reasons sometimes (difficult to reproduce)
JDev get confused and DTO classes, sometimes Model classes are copied to the View project classes directory.
Example utility class of the DTO project:
source:
MyWorkspace\DTO\src\com\photoswing\dto\util\TextUtils.java
instead of being generated in:
MyWorkspace\DTO\classes\com\photoswing\dto\util\TextUtils.class
is found in the View claases output directory (directory tree created by JDev):
MyWorkspace\View\classes\com\photoswing\dto\util\TextUtils.class
I noticed that regularly the JDev navigator has synchronization problems and can't find the class when activating the right-click Select in Navigator action in an open source file.
This generally happens when switching from source files of different projects.
Now if you compile a source file and the navigator has a synchronization problem following warning is displayed:
Warning: The file is not part of the active project DTO.jpr, compiled class will be written to DTO.jpr output directory
When only one file gets compiled this can be repaired easely by deleting the class written in the wrong directory.
But when several files are changed and are compiled the warning is only displayed for the current source file and all classes output trees must be scanned manually.
When testing the app if I'm not wrong JDev reads from the classes directories and doesn't produce a jar file, so deleting manually the wrong classes is a valid workaround.
But what if the app gets deployed and jars are generated?
I can't imagine myself changing manually the produced jars by removing the wrong classes and what about the manifest?
Your help is requested.
Regards
Fred
PS Can't provide a TestCase => happens in complex environment only.Glad to know I'm not the only one having that serious problem.
JDev by default create at least 2 different projects (model and view) so it seems to be a standard.
Working simultaneously on source files of different projects seems to the cause the trouble.
Is there somekind of patch available?
Could somebody of Oracle answer the question of the first message of this thread?
Thanks
Fred -
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 -
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(&myArray); // 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(&myArray); // 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 InstructorTunde 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!
Maybe you are looking for
-
when i click download it starts to download the file. But then when it hits 99% i get another box that says that it was unable to download Firefox 3.6 and the session has timed out. What is going on?
-
Adobe media encoder - export h.264 59.94fps 4096x2160 .mp4 file
I have been trying to export footage from the following camera, the Sony PXW-Z100 and trying to export a h.264 59.94fps 4096x2160 .mp4/.mov file. I found this article and presets from Video Road, but am unable to get this specific combination working
-
How to deactivate rules sync in apple mail?
Hi, unfortunately, rules in apple mail are synced via iCloud when "Documents & Data" is activated in iCloud settings. I would have thought that deactivating the "Mail" checkbox should do that, but this one seems to be related to iCloud email adresses
-
I am having a problem importing MP4 video into Premier Elements 11.
When I try to edit a video the highlights are turning black/grey and other colours are turning white or grey making the video look like a negative . . . sometimes the colour goes completely but not always. Also, when this happens the whole thing fre
-
Where are the OSX Server features?
Im looking for the "Server" features in MAc OSX 10.8. Im using a Mac Mini that I loaded a clean installation of 10.8 Mountain Lion