Saving Arrays
I am trying to create an two data arrays and display them on my front panel as I aquire them over time. I do not know why, but neither array appears to be saving the values that I expect and neither are displaying correctly....
The first array is simply an index of stage positions and the second is the data aquired at each position. For the "Last Scan" display, it shows my data once and then does not update, and for my averaged array for the averaged data over time, it never shows anything.
Additionally, my array that is saved at the end is all zeros for my data, despite the fact that I know that the program is reading non-zero data points.
Any advice would be greatly appreciated.
Solved!
Go to Solution.
I cannot test without your gear, but there are a couple of simple beginners mistakes:
Realtime monitoring:
Dataflow problem. The loop conditions will never change once the loop runs. The control terminal needs to be in the innermost loop.
Saving problem:
You have an uninitialized shift register, meaning it starts out as an empty array. Adding an array to an empty array will always result in an empty array, because the shorter array "wins". LAter building the 2D array will pad with zeroes. You need to initialize the shift register with an aray of the proper size. You could multiply the array output from the preceeding loop by zero and wire from the outside of the shift regsiter.
There are probably other problems, I have not studied the code in detail. For example the larger sequence structure has no purpose. The innermost while loop should be a FOR loop, etc.
LabVIEW Champion . Do more with less code and in less time .
Similar Messages
-
Saving array data from a waveform chart
I am using a CRIO 9004 and a 9237 bridge module to measure some strains from strain gauges. I've got one timed loop that reads the DMA FIFO and puts the arrays of values (16 data points, 4 per channel) into a queue. In the consumer timed loop a For loop scales the binary data, auto indexes it into arrays, then the arrays are merged into a 2D array for the four channels displayed on a waveform chart . Everytime the consumer loop runs it indexes 4 data points (per channel) yet the waveform chart plots them in a consecutive manner and doesn't overwrite the previous four. If I convert the arrays to waveform arrays I don't see anything on the waveform chart.
If I pass the 2D array of data to a array indicator inside or outside the consumer loop I get only 16 data points. I want to save the information that appears on the waveform chart after the consumer loop but because I'm not using waveform data type I can't use the write waveforms to file vi. The waveform chart history buffer has been set to 195360.
Idealy we will run the four channels for 120 seconds charting the data and saving the data. The minimum data rate is 1613kS/s (403 per channel) The data can be saved after the loops have finished gathering and processing or while they are running. I noticed when I tried to write to TDMS it slowed the consumer down. Same thing if I use a shift register with the volume of data.
I suspect I'm not sending data to the chart in the correct manner ( usualy takes two attempts to "clear chart" using shortcut menu). I'm not too familiar with timed loops /producer consumer loops and just tried to put something together based on examples.
I've attached my host vi and front panel screenshot.Hope they appear attached this time.
Attachments:
Basic DMA (Host).vi 444 KB
screenshot2.jpg 113 KB -
Saving Arrays to database???
Hi! I'am new on Jsp and I want to save values that the user add into a combobox. I Have a Save_action.jsp that executes when the user click on the submit button. So I want the array values to be saved into the database + be updated. Here is the problem area in Sava_action.jsp
<%
String update="";
Long aCustomerId = aCustomerSession.getCustomer().getCustomerId();
String[] aIPAddressAllow = request.getParameterValues("IPAddressAllow");
String[] aEmailAllow = request.getParameterValues("emailAllow");
String atruncuationMode = request.getParameter("truncuationMode");
String aoriginatorTemplate = request.getParameter("originatorTemplate");
String amessageTemplate = request.getParameter("messageTemplate");
String areceiptActive = request.getParameter("receiptActive");
String arecipientInMailSubject = request.getParameter("recipientInMailSubject");
ResultSet aResultSet;
ICDatabase aDatabase = new ICDatabase();
//Here is my problem??? What shell I write??
for (int i = 0; i < aIPAddressAllow.length; i++) {
if (aIPAddressAllow != null)
for (int l = 0; l < aEmailAllow.length; l++) {
if (aEmailAllow != null)
update = "UPDATE tM2SMSSettings Set IPAddressAllow='" + aIPAddressAllow[0] +"', emailAllow='" + aEmailAllow[0] +"', truncuationMode='" + atruncuationMode +"', originatorTemplate='" + aoriginatorTemplate +"' ,messageTemplate='" + amessageTemplate +"' , receiptActive=" + areceiptActive +", recipientInMailSubject=" + arecipientInMailSubject +" WHERE customerId=" + aCustomerSession.getCustomer().getCustomerId();
aResultSet = aDatabase.sql(update);
response.sendRedirect(response.encodeRedirectURL("customerm2sms.jsp"));
%>this is a way but if i see it correctly for each ip adress you'll be adding the emailadresses...
if that is what you need, then just put the for integer in th array (i for ip and l for email).
greetings -
Possible bug: Saving array with extended and double precision to spreadshee​t
If one concatenates a double precision array and an extended precision array with the "build array" vi and then saves using "Write to Spreadsheet File" vi any digits to the right of the decimal place are set to zero in the saved file. This happens regardless of the format signifier input (e.g. %.10f) to the "Write to Spreadsheet File" vi.
I am on Vista Ultimate 32 bit and labview 9.0
This is a possible bug that is easily circumvented by converting to one type before combining arrar to a spreadsheet. Nonetheless, it is a bug and it cost me some time.
Solved!
Go to Solution.
Attachments:
Spreadsheet save bug.vi 9 KBHi JL,
no, it's not a bug - it's a feature
Well, if you would look more closely you would recognize the "Save to Spreadsheet" as polymorphic VI. As this polymorphic VI doesn't support EXT numbers internally (it only supports DBL, I64 and String) LabVIEW chooses the instance with most accuracy: I64 (I64 has 64 bits precision, DBL only 53...). So your options are:
- set the instance to use as DBL (by right-click and "Select type...")
- make a copy of this VI, save it with a different name and make it support EXT numbers (don't rework the polymorphic VI as you would break compatibility with other LV installations or future revisions)
And yes, those coercion dots always signal some conversions - you should atleast check what's going on there...
Message Edited by GerdW on 05-21-2010 10:01 PM
Best regards,
GerdW
CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
Kudos are welcome -
Saving arrays in file and read it back
I am planning to save some data that been insert by user and save it . Then try read it back using data from the user... I' m still having problem to save the array of data...
Attachments:
gui1.3.vi 331 KBHi,
Take a look at the example I have attached. I think you are trying to continuously write out waveform data to a spreadsheet and append a column header information related to that waveform information.
Note that in this example, opening and closing the file is occuring outside of the loop where the data acquisition is occuring. This allows for a HUGE performance gain as opening/closing a file will take >80% of your computer's resources. The Write/Read LabVIEW Measurement File is doing just this: opening/closing a file every time you call it inside the loop. Try tweaking the example attached and hopefully it will work much better in your application.
Thanks and have a great day!
Kileen C.
Applications Engineer
National Instruments
Attachments:
Continuous_Write_to_Speadsheet_File_with_Row_and_Column_Headers.zip 22 KB -
Saving Arrays to one Array, Arrays zusammenfassen
Hallo,
I have two arrays, f.e. "1 2 3 4 5" and "6 7 8 9 0", an I want to save them in one array like:
1 6
2 7
3 8
4 9
5 0
(two values in one line seperated by tab)
The "Build array" vi gives the following output:
" 1 2 3 4 5 6 7 8 9 0"
inkluding the strange Symbol "[]" (a square) and no linebreak. How can I handle this? I attached my original output.
Arno
PS: LabVIEW 7, answers in german, english or dutch
Attachments:
substract_ausgabe.txt 15 KBOK, try this. It will only work if you are using numerics. Modify the %15e as required for your type of numbers.
Dave.
==============================================
David Kaufman
LabVIEW Certified Developer
==============================================
Attachments:
Tab_Array.vi 28 KB -
Saving array of images to gif animation
Hi, i have a program that generates x images and i want to save these images into one gif file, and then show the file to the user as an animation. I know how to save individual files, but i'm not sure how to do this.
i appreciate any hints, tips, or you could even show me a plugin that i can figure out...
thanksYou won't write gif images into a single animated file with any of the core java libraries. If you do a google on 'java gif animation' you can get a few links to some free and some trial+pay libraries to help you out.
If all you want to do is show an animation to the user you don't have to create a gif to do that, make animations in java is easy...
If a file is what you want though make sure you research LZW, the patents may still hold up in some areas.. most places they don't. -
Saving an integer array into a .txt file
hii, im only a beginner in java, so this is the only code i've learned so far for saving array elements into a file
public static void saveNames(String [] name) throws IOException
FileWriter file = new FileWriter("Example\\names.txt");
BufferedWriter out = new BufferedWriter(file);
int i = 0;
while (i < name.length)
if (name[i] != null)
out.write(name);
out.newLine();
i++;
out.flush();
out.close();
However, this is only used for string arrays; and i can't call the same method for an integer array (because it's not compatible with null)
I don't really understand this code either... since my teacher actually just gave us the code to use, and didn't really explain how it works
I have the same problem for my reading a file code as well --> it's only compatible with string
public static String [] readNames (String [] name) throws IOException
int x = 0;
int counter = 0;
String temp = "asdf";
name = new String [100];
FileReader file = new FileReader("Example\\names.txt");
BufferedReader in = new BufferedReader(file);
int i = 0;
while (i < array.length && temp != null) // while the end of file is not reached
temp = in.readLine();
if (temp != null)
name[i] = temp; // saves temp into the array
else
name[i] = "";
i++;
in.close(); // close the file
return name;
Could someone suggest a way to save elements from an integer array to a file, and read integer elements of that file?
Or if it's possible, replace null with a similar variable (function?), that is suitable for the integer array (i can't use temp != 0 because some of my elements might be 0)
Thanks so much!!!!!because it's not compatible with nullI think it should be okay to just remove the null condition check since there are no null elements in a primitive array when writing.
Use Integer.parseInt() [http://java.sun.com/javase/6/docs/api/java/lang/Integer.html] to convert the String into an Integer when you read it back and use Integer.toString() to be able to write it as a String. -
Hi
I'm writing a GUI program in java and have a problem. I need to have an array filled with random numbers when one button is clicked, and the same array to be accessed when clicking another button. I tried to do this by using methods to pass the array, but i keep getting stuck. Is there another way to do this?
if(e.getSource() == startButton) // Start Question
int Nums[] = new int[50];
Nums = fillArray(Nums);
int x = 0;
Nums = arrayStore(Nums, x);
int n = Nums[1];
String q = Integer.toString(n);
displayArea1.setText(q);
if(e.getSource() == listButton) // Get Question
int x = 1;
int Nums[] = new int[50];
Nums = arrayStore(Nums, x);
int a = Nums[1];
String b = Integer.toString(a);
displayArea1.setText(b);
String q = Questions(a);
String c = Choices(a);
displayArea2.setText(q);
displayArea3.setText(c);
static int[] fillArray(int qNum[])
// Input array with numbers from 1 - 50
for (int x=0; x<50; x++)
qNum[x] = x;
// Shuffle numbers randomly
int x,y,z;
Random generator = new Random();
for (int i = 0; i<101; i++)
x = generator.nextInt( 49 );
y = generator.nextInt( 49 );
z = qNum[x];
qNum[x] = qNum[y];
qNum[y] = z;
return qNum;
// This is what i can't figure out! :
int[] arrayStore(int qNum[], int x)
int[] storedNum = qNum;
int[] tempNum;
String q = Integer.toString(x);
//displayArea1.setText(q);
if (x==0)
tempNum = qNum;
if (x==1)
return tempNum;
return storedNum;
}Well, this is what i'm trying to do.
if(e.getSource() == startButton) // Start Question // ** BUTTON 1
1) Empty array is created.
2) Array is sent to fillArray method
3) Array is sent to arrayStore method
if(e.getSource() == listButton) // Get Question // ** BUTTON 2
1) Empty array is created.
2) Array is retrieved from arrayStore method.
static int[] fillArray(int qNum[])
1) Array is filled with random numbers and returned
int[] arrayStore(int qNum[], int x)
this is what needs to happen:
1) When method is called by ** BUTTON 1, it saves the array passed to it.
2) When method is called by ** BUTTON 2, it passes the saved array (from BUTTON1) to it (BUTTON2).
}Hope that clears it up.
Any ideas? -
Running Average of a 2D array element-wi​se
Hello all,
I am having trouble approaching this problem. I have a sub-VI which outputs a 2D-array for each iteration of a while-loop. This is spectroscopic data set where the first column is the time value and the next 32 columns are intensities from the array detector. RIght now I am fine with just figuring out how to solve my problem with only two columns.
Anyways, I want to be able to save the array between iterations ( which I am implementing a shift register for) and then average the next array with the previous saved array. Since all my time points will be equivalent in between iterations (the sub-VI creates a special time axis), I want to do a straight running average where each element is averaged with the previous corresponding element in the array.
What would be the best way to approach this part? Should I just do a build array and at the end somehow iteratively average together all of the appended arrays? I figure that would take way too long compared to a running average though.
Thank you for your help. I can clarify further if anything seems unclear.Try using index array for elemenet by element averaging for both the arrays. You dont need buid array anyways.
One more question, if some points are same then do averaging of those elements which are not equal or expected to be different.
Do you have any sample data. It will be great if i have some data on which operation needs to be performed.
Kudos are always welcome if you got solution to some extent.
I need my difficulties because they are necessary to enjoy my success.
--Ranjeet -
I am really sorry but I am still stuck. Please help.
Please can someone help me with the following code. I have a number of questions. So far all buttons that I have coded actions for work fine. When The program saves it does it correctly as I have seen the text file. However I have some problems.
1) How can I declare the arrays in another way without setting them to "" when the program starts. I need the program to start and show the previous saved arrays instead. I dont know if my method used for retrieving data from the file is correct either?.
2) When retrieving the values from a file that has example (all are string values). ADAM SANDLER 111 222 333 MICKY MOUSE 222 444 666
Where I want them to be in the follwing arrays as an example.
String name[1] = ADAM
String surname[1] = SANDLER
String home[1] = 111
String work[1] = 222
String cell[1] = 333
String name[2] = MICKY
String surname[2] = MOUSE
String home[2] = 222
String work[2] = 444
String cell[2] = 666
Here is my code.
Filename: ContactsListInterface.java
Date: 16 March 2008
Programmer: Yucca Nel
Purpose: Provides a GUI for entering names and contact numbers into a telephone directory.
Also allows options for searching for a specific name and deleting of data from the record
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import java.io.*;
import java.util.*;
import java.text.*;
public class ContactsListInterface extends JFrame implements ActionListener
{ //start of class
// Declare outputstream and inputStream
DataOutputStream output;
DataInputStream input;
String filename = "phonebook";
// construct fields, buttons, labels and text boxes
JTextPane displayPane = new JTextPane();
JLabel listOfContacts = new JLabel("List Of Contacts"); // creates a label for the scrollpane
JButton createButton = new JButton("Create");
JButton searchButton = new JButton("Search");
JButton modifyButton = new JButton("Modify");
JButton deleteButton = new JButton("Delete");
// declare data arrays for name, surname, work number, home number and cell number
private String name[] = {""};
private String surname[] = {""};
private String home[] = {""};
private String work[] = {""};
private String cell[] = {""};
// create an instance of the ContactsListInterface
public ContactsListInterface()
{ // start of cli()
super("Phonebook Interface");
} // end of cli()
public JMenuBar createMenuBar()
{ // start of the createMenuBar()
// construct and populate a menu bar
JMenuBar mnuBar = new JMenuBar(); // creates a menu bar
setJMenuBar(mnuBar);
JMenu mnuFile = new JMenu("File",true); // creates a file menu in the menu bar which is visible
mnuFile.setMnemonic(KeyEvent.VK_F);
mnuFile.setDisplayedMnemonicIndex(0);
mnuFile.setToolTipText("File Options");
mnuBar.add(mnuFile);
JMenuItem mnuFileExit = new JMenuItem("Exit"); // creates an exit option in the file menu
mnuFileExit.setMnemonic(KeyEvent.VK_X);
mnuFileExit.setDisplayedMnemonicIndex(1);
mnuFileExit.setToolTipText("Close Application");
mnuFile.add(mnuFileExit);
mnuFileExit.setActionCommand("Exit");
mnuFileExit.addActionListener(this);
JMenu mnuEdit = new JMenu("Edit",true); // creates a menu for editing options
mnuEdit.setMnemonic(KeyEvent.VK_E);
mnuEdit.setDisplayedMnemonicIndex(0);
mnuEdit.setToolTipText("Edit Options");
mnuBar.add(mnuEdit);
JMenu mnuEditSort = new JMenu("Sort",true); // creates an option for sorting entries
mnuEditSort.setMnemonic(KeyEvent.VK_S);
mnuEditSort.setDisplayedMnemonicIndex(0);
mnuEdit.add(mnuEditSort);
JMenuItem mnuEditSortByName = new JMenuItem("Sort By Name"); // to sort entries by name
mnuEditSortByName.setMnemonic(KeyEvent.VK_N);
mnuEditSortByName.setDisplayedMnemonicIndex(8);
mnuEditSortByName.setToolTipText("Sort entries by first name");
mnuEditSortByName.setActionCommand("Name");
mnuEditSortByName.addActionListener(this);
mnuEditSort.add(mnuEditSortByName);
JMenuItem mnuEditSortBySurname = new JMenuItem("Sort By Surname"); // to sort entries by surname
mnuEditSortBySurname.setMnemonic(KeyEvent.VK_R);
mnuEditSortBySurname.setDisplayedMnemonicIndex(10);
mnuEditSortBySurname.setToolTipText("Sort entries by surname");
mnuEditSortBySurname.setActionCommand("Surname");
mnuEditSortBySurname.addActionListener(this);
mnuEditSort.add(mnuEditSortBySurname);
JMenu mnuHelp = new JMenu("Help",true); // creates a menu for help options
mnuHelp.setMnemonic(KeyEvent.VK_H);
mnuHelp.setDisplayedMnemonicIndex(0);
mnuHelp.setToolTipText("Help options");
mnuBar.add(mnuHelp);
JMenuItem mnuHelpHelp = new JMenuItem("Help"); // creates a help option for help topic
mnuHelpHelp.setMnemonic(KeyEvent.VK_P);
mnuHelpHelp.setDisplayedMnemonicIndex(3);
mnuHelpHelp.setToolTipText("Help Topic");
mnuHelpHelp.setActionCommand("Help");
mnuHelpHelp.addActionListener(this);
mnuHelp.add(mnuHelpHelp);
JMenuItem mnuHelpAbout = new JMenuItem("About"); // creates a about option for info about api
mnuHelpAbout.setMnemonic(KeyEvent.VK_T);
mnuHelpAbout.setDisplayedMnemonicIndex(4);
mnuHelpAbout.setToolTipText("About this program");
mnuHelpAbout.setActionCommand("About");
mnuHelpAbout.addActionListener(this);
mnuHelp.add(mnuHelpAbout);
return mnuBar;
} // end of the createMenuBar()
// create the content pane
public Container createContentPane()
{ // start of createContentPane()
// try blocks for the input and output
try
output = new DataOutputStream(new FileOutputStream(filename));
catch(IOException io)
JOptionPane.showMessageDialog(null,"This program could not create a storage location. Please check the disk drive and the tun the program again.","Error",JOptionPane.ERROR_MESSAGE);
System.exit(1);
//construct and populate panels and content pane
JPanel labelPanel = new JPanel(); // panel is only used to put the label for the textpane in
labelPanel.setLayout(new FlowLayout());
labelPanel.add(listOfContacts);
JPanel displayPanel = new JPanel();// panel is used to display all the contacts and thier numbers
setTabsAndStyles(displayPane);
displayPane = addTextToTextPane();
displayPane.setEditable(false);
JScrollPane scrollPane = new JScrollPane(displayPane);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); // pane is scrollable vertically
scrollPane.setWheelScrollingEnabled(true);// pane is scrollable by use of the mouse wheel
scrollPane.setPreferredSize(new Dimension(400,320));
displayPanel.add(scrollPane);
JPanel workPanel = new JPanel();// panel is used to enter, edit and delete data
workPanel.setLayout(new FlowLayout());
workPanel.add(createButton);
createButton.setToolTipText("Create a new entry");
createButton.addActionListener(this);
workPanel.add(searchButton);
searchButton.setToolTipText("Search for an entry by name number or surname");
searchButton.addActionListener(this);
workPanel.add(modifyButton);
modifyButton.setToolTipText("Modify an existing entry");
modifyButton.addActionListener(this);
workPanel.add(deleteButton);
deleteButton.setToolTipText("Delete an existing entry");
deleteButton.addActionListener(this);
labelPanel.setBackground(Color.red);
displayPanel.setBackground(Color.red);
workPanel.setBackground(Color.red);
// create container and set attributes
Container c = getContentPane();
c.setLayout(new BorderLayout(30,30));
c.add(labelPanel,BorderLayout.NORTH);
c.add(displayPanel,BorderLayout.CENTER);
c.add(workPanel,BorderLayout.SOUTH);
c.setBackground(Color.red);
// add a listener for the window closing and save
addWindowListener(
new WindowAdapter()
public void windowClosing(WindowEvent e)
int answer = JOptionPane.showConfirmDialog(null,"Are you sure you would like to save all changes and exit?","File submission",JOptionPane.YES_NO_OPTION);
if(answer == JOptionPane.YES_OPTION)
save();
System.exit(0);
return c;
} // end of createContentPane()
protected void setTabsAndStyles(JTextPane displayPane)
{ // Start of setTabsAndStyles()
// set Font style
Style fontStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
Style regular = displayPane.addStyle("regular", fontStyle);
StyleConstants.setFontFamily(fontStyle, "SansSerif");
Style s = displayPane.addStyle("bold", regular);
StyleConstants.setBold(s,true);
} // End of setTabsAndStyles()
public JTextPane addTextToTextPane()
{ // start of addTextToTextPane()
try
input = new DataInputStream(new FileInputStream(filename));
for(int i=0; i<name.length;i++)
name[i] = input.readUTF();
surname[i] = input.readUTF();
home[i] = input.readUTF();
work[i] = input.readUTF();
cell[i] = input.readUTF();
catch(IOException io)
Document doc = displayPane.getDocument();
try
{ // start of tryblock
// clear previous text
doc.remove(0,doc.getLength());
// insert titles of columns
doc.insertString(0,"NAME\tSURNAME\tHOME NO\tWORK NO\tCELL NO\n",displayPane.getStyle("bold"));
// insert data
for(int i=0; i<name.length; i++)
doc.insertString(doc.getLength(), name[i] +"\t",displayPane.getStyle("regular"));
doc.insertString(doc.getLength(), surname[i] +"\t",displayPane.getStyle("regular"));
doc.insertString(doc.getLength(), home[i]+"\t",displayPane.getStyle("regular"));
doc.insertString(doc.getLength(), work[i]+"\t",displayPane.getStyle("regular"));
doc.insertString(doc.getLength(), cell[i]+"\t",displayPane.getStyle("regular"));
} // end of try block
catch(BadLocationException ble)
{ // start of ble exception handler
System.err.println("Could not insert text.");
} // end of ble exception handler
return displayPane;
} // end of addTextToTextPane()
// code to process user clicks
public void actionPerformed(ActionEvent e)
{ // start of actionPerformed()
String arg = e.getActionCommand();
// user clicks exit option
if(arg.equals("Exit"))
int answer = JOptionPane.showConfirmDialog(null,"Exiting will save all changes to file. \nAre you sure you would like to save and exit now?","File submission",JOptionPane.YES_NO_OPTION);
if(answer == JOptionPane.YES_OPTION)
save();
System.exit(1);
// user clicks help option
if(arg.equals("Help"))
JOptionPane.showMessageDialog(null, "Welcome to the phone book application. To add a new entry press the \"Create\" button.\n To search for an entry press the \"Search\" button.\n To modify an existing entry press the \"Modify\" button. \n To delete an entry press the \"Delete\" button.","Help Topic",JOptionPane.INFORMATION_MESSAGE);
// user clicks about option
if(arg.equals("About"))
JOptionPane.showMessageDialog(null,"Phonebook v 1.01 created by Yucca Nel.\nNo copyright exists.\nThis program is freeware and should not be sold.\nEnjoy :-)","About phonebook",JOptionPane.INFORMATION_MESSAGE);
// user clicks create button
if(arg.equals("Create"))
createNew();
// user clicks search button
if(arg.equals("Search"))
searchForName(arg, name); // Only possible to search by name as all contacts Must have a name
if(arg.equals("Modify"))
modifyContact(arg,name);
save();
// user clicks the sort by name option
if(arg.equals("Name"))
sort(name);
if(arg.equals("Surname"))
sort(surname);
} // end of actionPerformed()
// Method to ceate a new entry
public void createNew()
{ // start of createNew()
int newHome, newWork, newCell = 0;
String newContactName = JOptionPane.showInputDialog(null,"Please enter the new contacts first name or press cancel to exit.");
if(newContactName == null) finish(); // if user clicks cancel
if(newContactName.length() <=0)
JOptionPane.showMessageDialog(null,"You did not enter a valid name.\nPlease make sure you enter data correctly.","Error",JOptionPane.ERROR_MESSAGE);
createNew(); // To return to the create method
String newContactSurname = JOptionPane.showInputDialog(null,"Please enter the new contacts surname or press cancel to exit.");
if(newContactSurname == null) finish(); // if user clicks cancel
if(newContactSurname.equals(""))
int answer = JOptionPane.showConfirmDialog(null,"You did not enter a surname.\nAre you sure you wish to leave the surname empty?","No data entered",JOptionPane.YES_NO_OPTION); // Asks if data was valid
if(answer == JOptionPane.NO_OPTION)
newContactSurname = JOptionPane.showInputDialog(null,"Please enter the new contacts surname.");
String newContactWorkNum = JOptionPane.showInputDialog(null,"Please enter the new contacts work number or press cancel to exit.");
if(newContactWorkNum == null) finish(); // if user clicks cancel
String newContactHomeNum = JOptionPane.showInputDialog(null,"Please enter the new contacts home number or press cancel to exit.");
if(newContactHomeNum == null) finish(); // if user clicks cancel
String newContactCellNum = JOptionPane.showInputDialog(null,"Please enter the new contacts cell number or press cancel to exit.");
if(newContactCellNum == null) finish(); // if user clicks cancel
// enlarge the arrays so they can accept data
name = enlargeArray(name);
surname = enlargeArray(surname);
work = enlargeArray(work);
home = enlargeArray(home);
cell = enlargeArray(cell);
// add the new data into the arrays
name[name.length-1] = newContactName;
surname[surname.length-1] = newContactSurname;
home[home.length-1] = newContactHomeNum;
work[work.length-1] = newContactWorkNum;
cell[cell.length-1] = newContactCellNum;
// sort the names so they appear in alphebetical order
sort(name);
} // end of createNew()
// The enlarge array method
//method to enlarge an array by 1
public String[] enlargeArray(String[] currentArray)
String[] newArray = new String[currentArray.length + 1];
for (int i = 0; i < currentArray.length; i++)
newArray[i] = currentArray;
return newArray;
}// End of enlargeArray()
// The Sort Method
public void sort(String tempArray[])
{ // start of sort()
// for loop
for(int pass = 1; pass < tempArray.length; pass++)
for(int element = 0; element < tempArray.length -1; element++)
if(tempArray[element].compareTo(tempArray[element+1])>0)
swap(name, element, element+1);
swap(surname, element, element+1);
swap(home, element, element+1);
swap(work, element, element+1);
swap(cell, element, element+1);
addTextToTextPane();
} // end of sort()
// The swap method
public void swap(String swapArray[], int first, int second)
{ // start of swap()
String hold;
hold = swapArray[first];
swapArray[first] = swapArray[second];
swapArray[second] = hold;
} // end of swap()
// method to search for a name
public void searchForName(String searchField, String searchArray[])
{ // start of searchForName()
try
Document doc = displayPane.getDocument(); // assign text to an object
doc.remove(0,doc.getLength()); // clear the screen
doc.insertString(0,"NAME\tSURNAME\tHOME NO\tWORK NO\tCELL NO\n",displayPane.getStyle("bold"));
String searchValue = JOptionPane.showInputDialog(null,"Please enter the 1st name of the person you would like to see phone numbers for or press cancel to exit.");
boolean found = false;
if(searchValue == null) finish(); // if user clicks cancel
//search the array
for(int i=0; i < name.length; i++)
if(searchValue.compareTo(searchArray[i])==0)
doc.insertString(doc.getLength(), name[i] +"\t",displayPane.getStyle("regular"));
doc.insertString(doc.getLength(), surname[i] +"\t",displayPane.getStyle("regular"));
doc.insertString(doc.getLength(), home[i]+"\t",displayPane.getStyle("regular"));
doc.insertString(doc.getLength(), work[i]+"\t",displayPane.getStyle("regular"));
doc.insertString(doc.getLength(), cell[i]+"\t",displayPane.getStyle("regular"));
found = true;
if(found == false)
JOptionPane.showMessageDialog(null,"No contact with that name found.","No result found",JOptionPane.INFORMATION_MESSAGE);
sort(name);
catch(BadLocationException ble)
System.err.println("Could not insert text.");
} // end of searchForName()
// Method to modify contact
public void modifyContact(String searchField, String searchArray[])
{ // start of modifyContact()
try
Document doc = displayPane.getDocument(); // assign text to an object
doc.remove(0,doc.getLength()); // clear the screen
doc.insertString(0,"NAME\tSURNAME\tHOME NO\tWORK NO\tCELL NO\n",displayPane.getStyle("bold"));
String modifyValue = JOptionPane.showInputDialog(null,"Please enter the 1st name of the person you would like to change details for. Or press cancel to exit");
boolean found = false;
if(modifyValue == null) finish(); // if user clicks cancel
//search the array
for(int i=0; i < name.length; i++)
if(modifyValue.compareTo(searchArray[i])==0)
// To change the name
String oldName = name[i];
String newName = JOptionPane.showInputDialog(null,"Please enter a new name if you would like to change the name for "+name[i]+". Or press cancel to exit");
if(newName == null)
name[i] = oldName; // if user clicks cancel keep old entry
finish();
if(newName.equals("")) // if no data entered then name will stay same
JOptionPane.showMessageDialog(null,"You did not enter a name in the name field.\nOld name will be kept.","Information Message",JOptionPane.INFORMATION_MESSAGE);
name[i] = oldName;
addTextToTextPane();
else
name[i] = newName; // new name is saved into array
addTextToTextPane();
//To change the surname
String oldSurname = surname[i];
String newSurname = JOptionPane.showInputDialog(null,"Please enter a new surname if you would like to change the surname for "+name[i]+". Or press cancel to exit");
if(newSurname == null)
surname[i] = oldSurname; // if user clicks cancel keep old entry
finish();
if((oldSurname.length()>0) && newSurname.length()<=0) // if surname existed but no new surname was entered
int answer = JOptionPane.showConfirmDialog(null,"You are about to remove the surname for "+name[i]+".\nAre you sure you would like to remove the surname for this contact?","Please confirm the following",JOptionPane.YES_NO_OPTION);
if(answer == JOptionPane.YES_OPTION) // user wishes to remove old surname and leave no surname in place
surname[i] = newSurname; // new surname is saved into the array
else // user does not wish to remove surname
surname[i] = oldSurname; // keep the old surname
else // just replace the surname with new one as everything seems fine
surname[i] = newSurname;
//To change the work number of contact
String oldWork = work[i];
String newWork = JOptionPane.showInputDialog(null,"Please enter a new work number if you would like to change the work number for "+name[i]+". Or press cancel to exit");
if(newWork == null)
work[i] = oldWork; // user clicks cancel keep old entry
finish();
if((oldWork.length()>0) && newWork.length()<=0) // if number existed but no new number was entered
int answer = JOptionPane.showConfirmDialog(null,"You are about to remove the work number for "+name[i]+".\nAre you sure you would like to remove the work number for this contact?","Please confirm the following",JOptionPane.YES_NO_OPTION);
if(answer == JOptionPane.YES_OPTION) // user wishes to remove old number and leave no number in place
work[i] = newWork; // new number is saved into the array
else // user does not wish to remove number
work[i] = oldWork; // keep the old number
else // just replace the number with new one as everything seems fine
work[i] = newWork;
//To change the work number of contact
String oldHome = home[i];
String newHome = JOptionPane.showInputDialog(null,"Please enter a new home number if you would like to change the home number for "+name[i]+". Or press cancel to exit");
if(newHome == null)
home[i] = oldHome; // if user clicks cancel keep old value
finish();
if((oldHome.length()>0) && newHome.length()<=0) // if number existed but no new number was entered
int answer = JOptionPane.showConfirmDialog(null,"You are about to remove the home number for "+name[i]+".\nAre you sure you would like to remove the home number for this contact?","Please confirm the following",JOptionPane.YES_NO_OPTION);
if(answer == JOptionPane.YES_OPTION) // user wishes to remove old number and leave no number in place
home[i] = newHome; // new number is saved into the array
else // user does not wish to remove number
home[i] = oldHome; // keep the old number
else // just replace the number with new one as everything seems fine
home[i] = newHome;
//To change the cell number
String oldCell = cell[i];
String newCell = JOptionPane.showInputDialog(null,"Please enter a new cell number if you would like to change the cell number for "+name[i]+". Or press cancel to exit");
if(newCell == null)
cell[i] = oldCell; // if user clicks cancel keep old value
finish();
if((oldCell.length()>0) && newCell.length()<=0) // if number existed but no new number was entered
int answer = JOptionPane.showConfirmDialog(null,"You are about to remove the Cell number for "+name[i]+".\nAre you sure you would like to remove the cell number for this contact?","Please confirm the following",JOptionPane.YES_NO_OPTION);
if(answer == JOptionPane.YES_OPTION) // user wishes to remove old number and leave no number in place
cell[i] = newCell; // new number is saved into the array
else // user does not wish to remove number
cell[i] = oldCell; // keep the old number
else // just replace the number with new one as everything seems fine
cell[i] = newCell;
found = true;
addTextToTextPane();
if(found == false)
JOptionPane.showMessageDialog(null,"No contact with that name found.","No result found",JOptionPane.INFORMATION_MESSAGE);
sort(name);
addTextToTextPane();
catch(BadLocationException ble)
System.err.println("Could not insert text.");
} // end of searchForName()
// finish method for cancel button
public void finish()
JOptionPane.showMessageDialog(null,"This program will now close and automatically save all data entered. You may restart the program to modify any changes.","Information Message",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
// method to save data to file
public void save()
try
for(int i=0; i < name.length; i++)
output.writeUTF(name[i]);
output.writeUTF(surname[i]);
output.writeUTF(work[i]);
output.writeUTF(home[i]);
output.writeUTF(cell[i]);
JOptionPane.showMessageDialog(null,"Data succesfully saved to file.","Information message",JOptionPane.INFORMATION_MESSAGE);
catch(IOException io)
System.exit(1);
public static void main(String[] args)
{ // start of main()
// Set look and feel of interface
try
{ // start of try block
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} // end of try block
catch(Exception e)
{ // start of catch block
JOptionPane.showMessageDialog(null,"There was an error in setting the look and feel of this application","Error",JOptionPane.INFORMATION_MESSAGE);
} // end of catch block
ContactsListInterface cli = new ContactsListInterface();
cli.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
cli.setJMenuBar(cli.createMenuBar());
cli.setContentPane(cli.createContentPane());
cli.setSize(520,500);
cli.setVisible(true);
cli.setResizable(false);
} // end of main()
} //end of classBefore thinking I am lazy I dont want you to correct my code. Just give me a few pointers on how to get my arrays back from the file and how to set my strings to a non null value that wont show when my program starts.
Edited by: Yucca on Mar 24, 2008 7:24 PMYucca wrote:
It's pretty easy to write objects to file, but it depends on what you want to do with that file. Do you want it to be a human-readable text file? Is it only to be used by your program? The file is to be used by my program to save to and to read from. But I understand now that saving each entry as a string and not writing it to an array may be easier. Do I use the buffered reader instead of InputStreamReader? Oh sorry I forgot to mention that the file I save to will later be used when I convert my application to a database type/SQL tyype aplication.
Edited by: Yucca on Mar 24, 2008 8:06 PMIt sounds to me like object serialization would be the easiest for what you want to do. Read through this:
http://java.sun.com/developer/technicalArticles/Programming/serialization/
And these apis:
http://java.sun.com/j2se/1.5.0/docs/api/java/io/ObjectOutputStream.html
http://java.sun.com/j2se/1.5.0/docs/api/java/io/ObjectInputStream.html -
Hello LabVIEW group,
This is more of an excel question than a LabVIEW question, but I'm hoping
one of you has run into this before. I'm saving array data going to an XY
graph into an .xls file that has the correct deliminators to be read
properly by MS Excel. This works very well for me because I can read this
data and display it onto my XY graph later. However, when I open up excel,
I have to go through the motions of selecting the proper rows and columns
and graph wizards to re-create the graph in the excel program.
Does anyone know of a way to use a template so that I don't have to do this.
When I collect graph data, I collect dozens of graphs at a time and having
to go into excel and re-create all these graphs is time consuming. An
y info
would be great.
Thanks
George Callara
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----Anything you want with Excel is possible. Your choices include:
1. Use a template file that uses the INDIRECT function to extract data from another file
2. Use ActiveX to write data directly to a template file with the graphs
3. Use an Excel macro to create the graphs from the data
4. Copy and paste the data into a template file with the graphs
Your best bet is choice #1. Create a template with data on Sheet1 and your graphs on a separate
sheet. Then create formulas for the data array in sheet1 to find each data point in the other
file. A1 = INDIRECT("Datafile!A1"). You can then Define a Cell Name to "Datafile" and enter the
name of the file to display. When you change the name, the graphs updates instantly.
Michael Munroe Mailto:mmunroe@abcdefirm.
com
A Better Complete Development Engineering Firm
San Mateo, CA 94403 http://www.abcdefirm.com
"George M. Callara" wrote:
> Hello LabVIEW group,
>
> This is more of an excel question than a LabVIEW question, but I'm hoping
> one of you has run into this before. I'm saving array data going to an XY
> graph into an .xls file that has the correct deliminators to be read
> properly by MS Excel. This works very well for me because I can read this
> data and display it onto my XY graph later. However, when I open up excel,
> I have to go through the motions of selecting the proper rows and columns
> and graph wizards to re-create the graph in the excel program.
>
> Does anyone know of a way to use a template so that I don't have to do this.
> When I collect graph data, I collect dozens of graphs at a time and having
> to go into excel and re-create all these graphs is time consuming. Any info
> would be great.
>
> Thanks
>
> George Callara
>
> -----------== Posted via Newsfeeds.Co
m, Uncensored Usenet News ==----------
> http://www.newsfeeds.com The Largest Usenet Servers in the World!
> ------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
Michael Munroe, ABCDEF
Certified LabVIEW Developer, MCP
Find and fix bad VI Properties with Property Inspector -
How do I correct a build error while saving "Calculate Color Index Array.vi"?
I have an application that takes some data and then periodically generates a nifty 3d graph. When trying to compile this application to run on a stand-alone machine, i get an error message that crashes the build. This is the information that is generated for the error:
An error occurred while saving the following file:
C:\National Instruments\LabVIEW 2009\vi.lib\Math Plots\3D Math Plots\3D Surface\3D Surface Datatype\Protected\Create Plot Data\Calculate Color Index Array.vi
Invoke Node in AB_Source_VI.lvclass:Close_Reference.vi->AB_Build.lvclass:Copy_Files.vi->AB_Application.lvclass:Copy_Files.vi->AB_EXE.lvclass:Copy_Files.vi->AB_Build.lvclass:Build.vi->AB_Application.lvclass:Build.vi->AB_EXE.lvclass:Build.vi->AB_Build.lvclass:Build_from_Wizard.vi->AB_UI_Frmwk_Build.lvclass:Build.vi->AB_UI_FRAMEWORK.vi->AB_Item_OnDoProperties.vi->AB_Item_OnDoProperties.vi.ProxyCaller
<APPEND>
Method Name: <b>Save:Target Instrument</b>
Details:
Error 6 occurred at AB_Source_VI.lvclass:Close_Reference.vi -> AB_Build.lvclass:Copy_Files.vi -> AB_Application.lvclass:Copy_Files.vi -> AB_EXE.lvclass:Copy_Files.vi -> AB_Build.lvclass:Build.vi -> AB_Application.lvclass:Build.vi -> AB_EXE.lvclass:Build.vi -> AB_Build.lvclass:Build_from_Wizard.vi -> AB_UI_Frmwk_Build.lvclass:Build.vi -> AB_UI_FRAMEWORK.vi -> AB_Item_OnDoProperties.vi -> AB_Item_OnDoProperties.vi.ProxyCaller
Can anyone help me understand why the 3D Surface Datatype.lvclass keeps booching on my compile?
Thanks!Check this
-
Saving modifled ARGB values in an Integer array to a jpeg file?
Hi,
I have searched sites and forums and it seems that the key to this is to use BufferedImage and Graphics's drawImage(). But how can I use the drawImage when I only have an array of integer values?
I went through the docs and seems that BufferedImage class's setRGB() method may suit my purpose but the results were negative. The saved jpeg was just painted black instead of the photo.
Does my code below make any sense or am I missing out something here? Any help will be greatly appreciated!
//from my code, oneDPix is an int[] array containing modified ARGB values
BufferedImage buff = new BufferedImage(imgCols,imgRows,BufferedImage.TYPE_INT_ARGB);
Graphics2D g = buff.createGraphics();
buff.setRGB(0,0,imgCols,imgRows,oneDPix,0,imgCols);
try {
String targetFile = "/Users/cover.jpg";
ImageIO.write(buff,"jpg", new File(targetFile));
} catch (IOException ex) {
ex.printStackTrace();
}hi, if your array has the right values, then you could use the createImage method of the class Toolkit and teh class MemoryImageSource for making the image before, something like this:
Image ima = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(numOfColumns, numOfRows, ColorModel.getRGBdefault(), array, 0, numOfColumns));
BufferedImage bi = new BufferedImage(numOfColumns, numOfRows, BufferedImage.TYPE_INT_RGB);
Graphics g = bi.getGraphics();
g.drawImage(ima, 0, 0, null);
g.dispose();
ImageIO.write(bi,"jpg",new File(targetFile));hope this helps -
Saving and loading 1D array to/from file
Hi,
i have some problems with my NI application. for the first, i have case structure with two cases: true and false.
FALSE: in this case i have a for loop with 100 samples. i catch signal from my DAQ (now just Simulate Signal) and what i want is to save it in a 1D array and at the end of the loop the COMPLETE array into one text file. Problem in my vi: just the values from the last iteration are saved.
TRUE: now i have while loop. AT THE BEGINN of the loop i need to load my array from the file and not in the middle of the loop. Why? The data from the file are needed during the loop.
thanx in advance
Vedran Divkovic
RUB GERMANY
Attachments:
Regelsystem.vi 1494 KBAccording to your code, what you are saving is an array of means (one from each iteration), and NOT the last iteration. If you want to keep the entire data, it would be a 2D array.
Why are you generating an entire waveform at each iteration? Shouldn't you just generate one point?
LabVIEW Champion . Do more with less code and in less time .
Maybe you are looking for
-
HT2534 How can i download from two different store with the same account?
I live in both countries but my credit card is registered in a french bank, therefore it is not recognised by the Aussie store on itunes. There are apps or music i want to get form the Aussie store as well as music and other apps from the french one.
-
HT201303 how do you get your password back if you forget it?
How do you get your password back for the ipod? I need to know! I forgot my password. Is their a a way i can get it back by by my apple account? ! Please someone answer my question
-
FUTA Changes Effective 1st July 2011 - Not self Adjusting***Critical
Hello As we know the FUTA rate was chnaged effective 1st July 2011 from 0.8% to 0.6%(after SUTA offset), we have noticed that currently in the SAP the FUTA contribution is not self adjusting. As illustrated in below example OCT 2011 Earnings 2008.13
-
What is the latest ios for I phone 4s?
My Iphone4s is currently in IOS 7.0.3, but I want to make sure it is on 7.0.4- is there a way to get it to download that version instead of IOS7?
-
Query that EXCLUDES keywords?
Is it possible to create a smart album query that EXCLUDES certain keywords? Example: I want the album to include all pictures with keywords "red", "yellow", "blue", but not include those that have keywords "red", "yellow", "blue" and "green". If it