Help with a function to count program's elasped time
I want to add a little function to my program where it counts how long it takes for the program to finish. Essentially, you hit run, then the clock starts counting until the end of the program with an indicator so the user can see how long its been/takes to finish.
Thank you.
In this community nugget I presented a re-usable timer component that may meet your needs. I've extracted and attached the Resource Module its enum control type def and a sub-vi that handles the display format. Feel free to look into the nugget for an example of how the module was used.
Jeff
Attachments:
Execution Timer.vi 32 KB
Exec Timer Meth.ctl 11 KB
Format Rel Time (STR).vi 12 KB
Similar Messages
-
Need help with search function in my program
Hello all, some of you may remeber me from my previous inventory programs. Well I am finally on my last one and I need to add a search option to the code. Here is the class that will contain that option.
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Inventory2 extends JFrame implements ActionListener {
//Utility class for displaying the picture
//If we are going to use a class/method/variable inside that class only, we declare it private in that class
private class MyPanel extends JPanel {
ImageIcon image = new ImageIcon("Sample.jpg");
int width = image.getIconWidth();
int height = image.getIconHeight();
long angle = 30;
public MyPanel(){
super();
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
g2d.rotate (Math.toRadians(angle), 60+width/2, 60+height/2);
g2d.drawImage(image.getImage(), 60, 60, this);
g2d.dispose();
}//end class MyPanel
int currentIndex; //Currently displayed Item
Product[] supplies = new Product[4];
JLabel name ;
JLabel number;
JLabel rating;
JLabel quantity;
JLabel price;
JLabel fee;
JLabel totalValue;
JTextField nameField = new JTextField(20);
JTextField numberField = new JTextField(20);
JTextField ratingField = new JTextField(20);
JTextField quantityField = new JTextField(20);
JTextField priceField = new JTextField(20);
JPanel display;
JPanel displayHolder;
JPanel panel;
boolean locked = false; //Notice how I've used this flag to keep the interface clean
public Inventory2() {
makeTheDataItems();
setSize(700, 500);
setTitle("Inventory Program");
//make the panels
display = new JPanel();
JPanel other = new JPanel();
other.setLayout(new GridLayout(2, 1));
JPanel picture = new MyPanel();
JPanel buttons = new JPanel();
JPanel centerPanel = new JPanel();
displayHolder = new JPanel();
display.setLayout(new GridLayout(7, 1));
//other.setLayout(new GridLayout(1, 1));
//make the labels
name = new JLabel("Name :");
number = new JLabel("Number :");
rating = new JLabel("Rating :");
quantity = new JLabel("Quantity :");
price = new JLabel("Price :");
fee = new JLabel("Restocking Fee (5%) :");
totalValue = new JLabel("Total Value :");
//Use the utility method to make the buttons
JButton first = makeButton("First");
JButton next = makeButton("Next");
JButton previous = makeButton("Previous");
JButton last = makeButton("Last");
JButton search = makeButton("Search");
//Other buttons
JButton add = makeButton("Add");
JButton modify = makeButton("Modify");
JButton delete = makeButton("Delete");
JButton save = makeButton("Save");
JButton exit = makeButton("Exit");
//Add the labels to the display panel
display.add(name);
display.add(number);
display.add(rating);
display.add(quantity);
display.add(price);
display.add(fee);
//add the buttons to the buttonPanel
buttons.add(first);
buttons.add(previous);
buttons.add(next);
buttons.add(last);
buttons.add(search);
//Add the picture panel and display to the centerPanel
displayHolder.add(display);
centerPanel.setLayout(new GridLayout(2, 1));
centerPanel.add(picture);
centerPanel.add(displayHolder);
other.add(buttons);
JPanel forAdd = new JPanel(); // add the other buttons to this panel
forAdd.add(add);
forAdd.add(modify);
forAdd.add(delete);
forAdd.add(save);
forAdd.add(exit);
other.add(forAdd);
//Add the panels to the frame
getContentPane().add(centerPanel, "Center");
getContentPane().add(other, "South");
this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
setVisible(true);
private void makeTheDataItems () {
Product p1 = new DVD("The one", 001, 200, 100, "The one");
Product p2 = new DVD("Once upon a time in China V", 002, 500, 10000, "Once upon a time in China V");
Product p3 = new DVD("Rat Race", 003, 100, 3000, "Rat Race");
Product p4 = new DVD("The Man in the Iron Mask", 004, 3000, 9000, "The Man in the Iron Mask");
supplies[0] = p1;
supplies[1] = p2;
supplies[2] = p3;
supplies[3] = p4;
//Utility method for creating and dressing buttons
private JButton makeButton(String label) {
JButton button = new JButton(label);
button.setPreferredSize(new Dimension(100, 25));
button.setActionCommand(label);
button.addActionListener(this);
return button;
private void addItem() {
panel = new JPanel();
JPanel add = new JPanel();
add.setLayout(new GridLayout(7, 2));
JButton addIt = makeButton("Add Item");
JLabel name = new JLabel("Name :");
JLabel rating = new JLabel("Rating :");
JLabel quantity = new JLabel("Quantity :");
JLabel price = new JLabel("Price :");
add.add(name); add.add(nameField);
add.add(rating); add.add(ratingField);
add.add(quantity); add.add(quantityField);
add.add(price); add.add(priceField);
panel.add(add);
JPanel forAddIt = new JPanel();
forAddIt.add(addIt);
panel.add(forAddIt);
displayHolder.remove(display);
displayHolder.add(panel);
//display = panel;
this.setVisible(true);
public static void main( String args[]) {
new Inventory2().displayFirst(); //The main method should not have too much code
} // end main method
public void actionPerformed(ActionEvent event) {
String command = event.getActionCommand(); //This retrieves the command that we set for the button
//Always compare strings using the .equals method and not using ==
if(command.equals("First")) {
if(!locked) {
displayFirst();
else if(command.equals("Next")) {
if(!locked) {
displayNext();
else if(command.equals("Previous")) {
if(!locked) {
displayPrevious();
else if(command.equals("Last")) {
if(!locked) {
displayLast();
else if(command.equals("Exit")) {
this.dispose();
System.exit(0);
else if(command.equals("Add")) {
if(!locked) {
addItem();
locked = true;
else if(command.equals("Add Item")) {
addItemToArray();
else if(command.equals("Modify")) {
if(!locked) {
modify();
locked = true;
else if(command.equals("Update")) {
if(!locked) {
modifyItemInArray();
locked = true;
else if(command.equals("Delete")) {
if(!locked) {
DVD dvd = (DVD)supplies[currentIndex];
int confirm = JOptionPane.showConfirmDialog(this, "Are you sure you want to delete item "+dvd.getItemNumber());
if(confirm == JOptionPane.YES_OPTION) {
removeItemAt(currentIndex);
displayFirst();
private void modify() {
DVD dvd = (DVD)supplies[currentIndex];
panel = new JPanel();
JPanel add = new JPanel();
add.setLayout(new GridLayout(7, 2));
JButton update = makeButton("Update");
JLabel number = new JLabel("Number :");
JLabel name = new JLabel("Name :");
JLabel rating = new JLabel("Rating :");
JLabel quantity = new JLabel("Quantity :");
JLabel price = new JLabel("Price :");
add.add(number);
numberField.setText(""+dvd.getItemNumber()); numberField.setEditable(false); add.add(numberField);
add.add(name);
nameField.setText(dvd.getItemName()); add.add(nameField);
ratingField.setText(dvd.getRating()); ratingField.setEditable(false);
add.add(rating); add.add(ratingField);
add.add(quantity);
quantityField.setText(""+dvd.getStockQuantity());
add.add(quantityField);
add.add(price);
add.add(priceField); priceField.setText(""+dvd.getItemPrice());
panel.add(add);
JPanel forAddIt = new JPanel();
forAddIt.add(update);
panel.add(forAddIt);
displayHolder.remove(display);
displayHolder.add(panel);
//display = panel;
this.setVisible(true);
private void addItemToArray() {
Product p = new DVD(nameField.getText(), supplies.length + 1, Long.parseLong(quantityField.getText()),
Double.parseDouble(priceField.getText()), ratingField.getText());
//Extend size of array by one first
Product[] ps = new Product[supplies.length + 1];
for(int i = 0; i < ps.length-1; i++) {
ps[i] = supplies;
ps[supplies.length] = p;
supplies = ps;
displayHolder.remove(panel);
displayHolder.add(display);
displayLast();
this.setVisible(false);
this.setVisible(true);
//Utility method to ease the typing and reuse code
//This method reduces the number of lines of our code
private void displayItemAt(int index) {
DVD product = (DVD)supplies[index];
name.setText("Item Name: "+ product.getItemName());
number.setText("Item Number: "+ product.getItemNumber());
rating.setText("Rating: "+ product.getRating());
quantity.setText("Quantity In Stock: "+ product.getStockQuantity());
price.setText("Item Price: "+ product.getItemPrice());
totalValue.setText("Total: " + product.calculateInventoryValue());
fee.setText("Restocking Fee (5%) :"+product.calculateRestockFee());
locked = false;
this.repaint();
this.setVisible(true);
private void modifyItemInArray() {
Product p = new DVD(nameField.getText(), supplies.length + 1, Long.parseLong(quantityField.getText()),
Double.parseDouble(priceField.getText()), ratingField.getText());
supplies[currentIndex] = p;
displayHolder.remove(panel);
displayHolder.add(display);
displayItemAt(currentIndex);
this.setVisible(false);
this.setVisible(true);
private void removeItemAt(int index) {
Product[] temp = new Product[supplies.length-1];
int counter = 0;
for(int i = 0; i < supplies.length;i++) {
if(i == index) { //skip the item to delete
else {
temp[counter++] = supplies[i];
supplies = temp;
public void displayFirst() {
displayItemAt(0);
currentIndex = 0;
public void displayNext() {
if(currentIndex == supplies.length-1) {
displayFirst();
currentIndex = 0;
else {
displayItemAt(currentIndex + 1);
currentIndex++;
public void displayPrevious() {
if(currentIndex == 0) {
displayLast();
currentIndex = supplies.length-1;
else {
displayItemAt(currentIndex - 1);
currentIndex--;
public void displayLast() {
displayItemAt(supplies.length-1);
currentIndex = supplies.length-1;
}//end class Inventory2
I am not sure where to put it and how to set it up. If you guys need the other two classes let me know. Thanks in advanced.Here are the other two classes:
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class Product implements Comparable {
String name;
int number;
long stockQuantity;
double price;
public Product() {
name = "";
number = 0;
stockQuantity = 0L;
price = 0.0;
public Product(String name, int number, long stockQuantity, double price) {
this.name = name;
this.number = number;
this.stockQuantity = stockQuantity;
this.price = price;
public void setItemName(String name) {
this.name = name;
public String getItemName() {
return name;
public void setItemNumber(int number) {
this.number = number;
public int getItemNumber() {
return number;
public void setStockQuantity(long quantity) {
stockQuantity = quantity;
public long getStockQuantity() {
return stockQuantity;
public void setItemPrice(double price) {
this.price = price;
public double getItemPrice() {
return price;
public double calculateInventoryValue() {
return getItemPrice() * getStockQuantity();
public int compareTo (Object o) {
Product p = (Product)o;
return name.compareTo(p.getItemName());
public String toString() {
return "Name :"+getItemName() + "\nNumber"+number+"\nPrice"+price+"\nQuantity"+stockQuantity + "\nValue :"+calculateInventoryValue();
class DVD extends Product implements Comparable {
private String rating;
public DVD() {
super(); //Call the constructor in Product
rating = ""; //Add the additonal attribute
public DVD(String name, int number, long stockQuantity, double price, String rating) {
super(name, number, stockQuantity, price); //Call the constructor in Product
this.rating = rating; //Add the additonal attribute
public void setRating(String rating) {
this.rating = rating;
public String getRating() {
return rating;
public double calculateInventoryValue() {
return getItemPrice() * getStockQuantity() + getItemPrice()*getStockQuantity()*0.05;
public double calculateRestockFee() {
return getItemPrice() * 0.05;
public int compareTo (Object o) {
Product p = (Product)o;
return getItemName().compareTo(p.getItemName());
public String toString() {
return "Name :"+getItemName() + "\nNumber"+getItemNumber()+"\nPrice"+getItemPrice()+"\nQuantity"+getStockQuantity() +"\nRating :"+getRating()+"\nValue"+calculateInventoryValue();
}You should be able to search through these items, and any other items that have been added to the program. -
Hi...I was wondering if I could get help with this function. How do i write a function to return hours between a begin date and an end date for an employee. Thanks so much
EdStevens wrote:
AlexeyDev wrote:
sb92075 wrote:
select (date2-date1)*24 from dual;not as above but as below
select (date2-date1)/24 from dual;date2-date1 is amount of days. Divide it by 24 and what? if you multiply it on 24 you will have a chance to know how many hours between these two dates. :-)Don't forget that a DATE type also includes a time component.I suppose it doesn't matter if you did a difference between two dates. The result is always number of days. -
Looking for help with movie loading in a different spot every time page reloads.
Hello,
I have a Flash movie that I need to jump to a one of 6 chosen frames when say a user hits the back button or home in the site. I just dont want the same user seeing the flash movie replay in the same spot everytime they go back to home.
ANY help with this is appreciated.
Thanks ahead of time.
-Ann
Here is what I have scripted:
var numbers:Array = [2,114,415,687,960,1195,1485];
_root.firstTime = true;
if(firstTime) {
firstTime = false;
var frame:Number = Math.floor(Math.random() * numbers.Length);
gotoAndPlay(numbers[frame]);
I have also tried this:
Array.prototype.shuffle = function() {
for (var ivar = this.length-1; ivar>=0; ivar--) {
var p = random(ivar+1);
var t = this[ivar];
this[ivar] = this[p];
this[p] = t;
ASSetPropFlags(Array.prototype, ["shuffle"], 1, 1);
var Array_ar:Array = new Array(2,114,415,687,960,1195,1485);
Array_ar.shuffle();
index = 0;
function load_random() {
gotoAndPlay(Array_ar[index++]);
if (index == Array_ar.length) {
(index=0);
load_random();
But this keep jumping to frame 1 each time i hit back or refresh.
Thanks again.That did not work. It loops back to the frame that it first loaded to not to frame 1 the beginning.
It tried putting gotoAndPlay(numbers[frame]); on the very last frame, then I made a new keyframe after the very last frame and neither worked.
You can see the swf here:
http://www.shared-vision.net/testsites/edi/EDIflashtest2.html
Thank you for your help.
-Ann -
Hi again forum:
I have a program and i need to pass basic functionality to a set of funtion module.
I have a description of a internal table in the program, that i need to use in the function-module
Example:
PROGRAM
" In the top of the program i declared.
"This the actual version
TYPES: BEGIN OF t1
END OF t1.
DATA: it_some TYPE STANDARD TABLE of t1 with header line.
SELECT *
FROM
INTO TABLE it_some.
FUNCTION MODULE
Now in the new version i need to declare an output paramter of type t1 in the exports parameters of the function ZMY_FUNCTION, and t1 is an internal_table, what can i do forum ?..
The thing is that how can i declare an export parameter that is not know?
please help
Thanks
Joshuahi,
we can pass internal table to FM by using CHANGING or TABLE options.
regards,
AshokReddy. -
Hallow experts,
I'm doing an interface from sap into anther application and in this interface (log interface) I use two function below in program and I have to send to customer in text file in which field of infotype change was made
This to function helping me but I miss the action like insert was made or update or delete
Did dome one can help me with that?
HREIC_GET_LOGGED_INFTY_CHANGES
HR_INFOTYPE_LOG_GET_DETAIL
Best Regardshi Naveen Bathini
thankes for your answer
i thihk u dont understand me ,
HR_INFOTYPE_LOG_GET_DETAIL bring table fields with all the field that change
but i dont now if user create new infotype for employee or just take one field and change it like from infotype 0006 just change street or postal code
i wont to now if it is an insert (create new infotype ) or update or delete fields from infotype.
Best regards -
Help with Sort function in Terminal
Hello all... this is my first post on here as I'm having some trouble with some Termianl commands. I'm trying to learn Terminal at the moment as it is but I would appreciate some help with this one....
I'm trying to sort a rather large txt file into alphabetical order and also delete any duplicates. I've been using the following command in Terminal:
sort -u words.txt > words1.txt
but after a while I get the following error
sort: string comparison failed: Illegal byte sequence
sort: Set LC_ALL='C' to work around the problem.
sort: The strings compared were `ariadnetr\345dens\r' and `ariadnetr\345ds\r'.
What should my initial command be? What is Set LC_ALL='C'?
Hope you guys can help?Various languages distinct sorting - collation - sequences.
The characters can and variously do sort differently, depending on what language is involved.
Languages here can include the written languages of humans, and a few settings associated with programming languages. This is all part of what is known as internationalization and localization, and there are are various documents around on that topic.
The LC_ALL environment variable sets all of the locale-related settings en-mass, including the collation sequence that is established via LC_COLLATE et al, and the sort tool is suggesting selecting the C language collation.
Here, the tool is suggesting the following syntax:
LC_ALL=C sort -u words.txt > words1.txt
This can also be done by exporting the LC_ALL, but it's probably better to just do this locally before invoking the tool.
Also look at the lines of text in question within the files, and confirm the character encoding of the file.
Files can have different character encodings, and there's no reliable means to guess the encoding. For some related information, see the file command:
file words.txt
...and start reading some of the materials on internationalization and localization that are posted around the 'net. Here's Apple's top-level overview.
In this case, it looks like there's an "odd" character and probably an å character on that line and apparently the Svenska ariadnetrådens.
Switching collation can help here, or - if the character is not necessary - removing it via tr or replacing it via sed can be equally effective solutions.
Given it appears to be Svenska, it might work better to switch to Svenska collation thanto the suggested C collation.
I think that's going to be sv_SE, which would make the command:
LC_ALL=sv_SE sort -u words.txt > words1.txt
This is all generic bash shell scripting stuff, and not specific to OS X. If you haven't already seen them, the folks over at tldp have various guides including a bash guide for beginners, and an advanced bash scripting guide - both can be worth skimming. They're not exactly the same as bash on OS X and some specific commands and switches can differ, and as bash versions can differ, but bash is quite similar across all the platforms. -
Hi all,
I need some help with ASO mdx function.
Avg({Leaves([Employees].Currentmember)}, [Calculated_Field]). This will give me the average for Calculated_Field for all levels of Employees. But i want to add more dimensions like Region and year.
Please advice how can I achieve this.
Thanks
Andyyou have to use cross join in order to add more dimension members to the formula.This will give you some idea
Re: Writing formula in Outline??????
Regards,
RSG -
I need help with Analytic Function
Hi,
I have this little problem that I need help with.
My datafile has thousands of records that look like...
Client_Id Region Countries
[1] [1] [USA, Canada]
[1] [2] [Australia, France, Germany]
[1] [3] [China, India, Korea]
[1] [4] [Brazil, Mexico]
[8] [1] [USA, Canada]
[9] [1] [USA, Canada]
[9] [4] [Argentina, Brazil]
[13] [1] [USA, Canada]
[15] [1] [USA]
[15] [4] [Argentina, Brazil]
etc
My task is is to create a report with 2 columns - Client_Id and Countries, to look something like...
Client_Id Countries
[1] [USA, Canada, Australia, France, Germany, China, India, Korea, Brazil, Mexico]
[8] [USA, Canada]
[9] [USA, Canada, Argentina, Brazil]
[13] [USA, Canada]
[15] [USA, Argentina, Brazil]
etc.
How can I achieve this using Analytic Function(s)?
Thanks.
BDFHi,
That's called String Aggregation , and the following site shows many ways to do it:
http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php
Which one should you use? That depends on which version of Oracle you're using, and your exact requirements.
For example, is order importatn? You said the results shoudl include:
CLIENT_ID COUNTRIES
1 USA, Canada, Australia, France, Germany, China, India, Korea, Brazil, Mexicobut would you be equally happy with
CLIENT_ID COUNTRIES
1 Australia, France, Germany, China, India, Korea, Brazil, Mexico, USA, Canadaor
CLIENT_ID COUNTRIES
1 Australia, France, Germany, USA, Canada, Brazil, Mexico, China, India, Korea?
Mwalimu wrote:
... How can I achieve this using Analytic Function(s)?The best solution may not involve analytic functions at all. Is that okay?
If you'd like help, post your best attempt, a little sample data (CREATE TABLE and INSERT statements), the results you want from that data, and an explanation of how you get those results from that data.
Always say which version of Oracle you're using.
Edited by: Frank Kulash on Aug 29, 2011 3:05 PM -
Help with InsertPages Function
I am attempting to combine multiple .RTF files into a single PDF file. In the VBA code below, the InsertPages function causes a compile error. Can anyone tell me what I am doing wrong?
Dim AVDoc As Object
Dim AVDocAdd As Object
Dim PDDoc As Object
Dim PDDocAdd As Object
Dim iLastPage As Long
Dim iAddPages As Long
Set AVDoc = CreateObject("AcroExch.AVDoc")
Set AVDocAdd = CreateObject("AcroExch.AVDoc")
Dim rtfFiles() As String
rtfFiles = Split("doc1.rtf,doc2.rtf,doc3.rtf", ",")
AVDoc.Open rtfFiles(0), ""
Set PDDoc = AVDoc.GetPDDoc
For i = 1 To UBound(rtfFiles) Step 1
iLastPage = PDDoc.GetNumPages
AVDocAdd.Open rtfFiles(i), ""
Set PDDocAdd = AVDocAdd.GetPDDoc
iAddPages = PDDocAdd.GetNumPages
PDDoc.InsertPages(iLastPage, PDDocAdd, 0, iAddPages, False)
PDDocAdd.Close
AVDocAdd.Close (1)
Next
If PDDoc.Save(PDSaveFull, "Tables.pdf") = True Then
PDDoc.Close
End If
AVDoc.Close (1)
Set AVDoc = Nothing
Set AVDocAdd = Nothing
Set PDDoc = Nothing
Set PDDocAdd = NothingCould you give me a code snippet? I am not certain by what you mean when you say "open a new folder, be careful with duplicates"
If I had a problem with duplicates wouldn't it surface at run time and not compile time? The InsertPages function is giving me a compile time error. -
Help with bash function(set background=dark/light in vimrc)
I couldn't find any gvimrc files so I guess it uses the regular one. And since I work pretty much in X too I thought it would be nice with a function that sets background=light if I'm in X an background=dark if not. Is that possible?
/Richardvimrc configuration is not the same as bash.
You probably want something like this in your ~/.vimrc:
if has('gui_running')
set background=light
else
set background = dark
endif -
Well guys, I have a problem here and I didn't find any solutions
So maybe someone of you, can help me!
My problem is:
I have 2 numbers (100 and -200) and I have to plot the greater value.
The problem is for me the signal of -(minus) doesn't means nothing....
For the program I'm making, the -200 is greater than 100
So I tryed put bouth as absolute value, but when I have the "answer" only appears the "200"
and I need it appears -200
So I thought about something like that:
I use a select function and maybe do something like that:
So I have to make something at True or False value at S to make this work!
If true I receive 100, if is false I receive -200
Thanks!I dont know why is in this section. I posted it on LabVIEW part!
Well Dennis I make it like that:
But now I have a problem
I do the same calc for 3 differents variables like A, B, C
and after that I have to calc which value is the "greater"
But my problem is, If I have the values "-350 300 -400"
the greater will be "300" but for me the "minus" don't mean anything
so I need the greater value is "400"
For all positive values, its works fine!
I compare A and B, after that the greater is compared with C and have a result!
but When I have negative values and positive values... I got that problem...
and When I have only negative values I have a problem too.
"-300 -400 -500" for me the greater value have to be "-500" but labview shows "-300"
because -300 is greater than -500 in algebriac.
And If I use absolute values I will always have a positive value... but I need to know if the value is negative or positive
Anyone, can help me with that?
Thanks
Message Edited by EduU on 10-29-2009 11:06 AM -
Help with quit function and elapsed time function.
I have this annoying assignment game here and I am almost finished with it. I got two problems, the first is that the quit function partly works it quits from the game but it is giving me a "Guess is to high" message. I've tried so many things but nothing seems to work.
The other problem is that the elapsed time " *(long f = System.currentTimeMillis()/1000;)* " starts to count before you actually write something for example if you run the program without writing something for 5 minutes, the highscore list will show your time you finished the game + these 5 minutes.
If somebody could give me a hint or could explain to me how I could fix these problems I would be very thankful.
import java.util.*;
class Game {
public static void main(String[] arg) {
int RAN,Entered_number=0,count=0;
String guess1[] = new String[1];
int guess2[] = new int[1];
int time[] = new int[1];
String NP1[];
int NP2[];
int NP3[];
int j=0;
Scanner scan=new Scanner(System.in);
Scanner kb = new Scanner(System.in);
Random myRandomizer = new Random();
RAN= Math.abs(myRandomizer.nextInt() % 1000) + 1;
System.out.println("\t\t\t"+"Hello and welcome to this guessing game!");
System.out.println("\t\t\t"+"Start guessing, it's a number between 1 and 1000...");
System.out.print("--------------------------------------------------");
System.out.println("-----------------------------");
System.out.println("please enter your number:");
String control="";//control is just a name for the variable. it's used to read in the whole line if you have written something that is not a number.
String name="";
String answer="";
boolean okgame=true;//is used so that you can play the game as long as the variable okgame is true.
long f = System.currentTimeMillis()/1000;
while((Entered_number!=RAN) && okgame)//controls if the number is different then RAN and that okgame is true.
System.out.print(RAN);
System.out.print(">");
if(scan.hasNextInt())//checks in advance that what you have written is a number, if so then it can read it as Entered_number.
Entered_number=scan.nextInt();
else
control=scan.nextLine();//Reads int the whole line to control what has been written in.
if(control.equalsIgnoreCase("quit"))//if control is = quit, then compare to will return 0.
okgame=false; //if you have written quit okgame, you put in false to quit the game.
// Entered_number=0;//initiates entered_number all over again to show message stupid guess i wont count that.
if(okgame)//as long as okgame is true it will show the result otherwise you go to else to show that the game is finished.
if((Entered_number>RAN)&&(Entered_number>=1)&&(Entered_number<=1000))
System.out.println("Guess is too high!");
count++;
else if((Entered_number<RAN)&&(Entered_number>=1)&&(Entered_number<=1000))
System.out.println("Guess is too low!");
count++;
else if((Entered_number>1000)||(Entered_number<1))
System.out.println("Stupid guess! I won't count that...");
else if (Entered_number==RAN)
long p = System.currentTimeMillis()/1000;
count++;
System.out.println("****Guess is CORRECT!");
System.out.print("****You guessed it in"+" "+count+" guesses and ");
System.out.print(p - f);
System.out.println(" seconds.");
System.out.println("please enter your name:");
System.out.print(">");
name=kb.next();
System.out.println("Do you want to play again ?(y/n)");
System.out.print(">");
answer=kb.next();
if(answer.equalsIgnoreCase("n"))
System.out.println("**** The game is over.");
okgame=false;
if(answer.equalsIgnoreCase("y"))
Random myRandom = new Random();
RAN = Math.abs(myRandom.nextInt() % 1000) + 1;
System.out.println("current high score list:");
long ttime = p-f;
int ta = (int)ttime;
j++;
if (j > 1){
NP1 = new String[j];
NP2 = new int[j];
NP3 = new int[j];
for (int n = 1; n < j; n++){
NP1[n-1] = guess1[n-1];
NP2[n-1] = guess2[n-1];
NP3[n-1] = time[n-1];
NP1[j-1] = name;
NP2[j-1] = count;
NP3[j-1] = ta;
guess1 = new String[j];
guess1 = NP1;
time = new int[j];
guess2 = new int[j];
guess2 = NP2;
time = NP3;
for (int w = 1; w < guess2.length; w++) {
for (int x = 1; x < guess2.length; x++) {
if (guess2[x] < guess2[x-1]) {
int z4, z5,z6,z7;
String z2, z3;
z4 = guess2[x];
z5 = guess2[x-1];
guess2[x] = z5;
guess2[x-1] = z4;
z2 = guess1[x];
z3 = guess1[x-1];
guess1[x] = z3;
guess1[x-1] = z2;
z6 = time[x];
z7 = time[x-1];
time[x] = z7;
time[x-1] = z6;
for (int al = 1; al < time.length; al++) {
for (int o = 1; o < time.length; o++) {
if (guess2[o] == guess2[o-1]) {
if (time[o] < time[o-1]) {
int z4, z5, z6 ,z7;
String z2, z3;
z2 = guess1[o]; z3 = guess1[o-1];
z4 = guess2[o]; z5 = guess2[o-1];
z6 = time[o]; z7 = time[o-1];
guess1[o] = z3; guess1[o-1] = z2;
guess2[o] = z5; guess2[o-1] = z4;
time[o] = z7; time[o-1] = z6;
else {
guess1[j-1] = name;
guess2[j-1] = count;
time[j-1] = ta;
System.out.println("Number\t\tName\t\tHigh Score\tTime (Seconds)");
System.out.println("------\t\t----\t\t----------\t--------------");
for (int h = 0; h < j; h++) {
System.out.println(" " + (h+1) + "\t\t" + guess1[h] + "\t\t" + guess2[h] + "\t\t" + time[h]);
System.out.println("");
System.out.println("Start guessing, it's a number between 1 and 1000...");
count=0;
//-----------------------------------------------------------------------------------------------------------------------------------------------------PS I'm not done with the comments yet so that could be a little confusing for you guys =P
Thanks!
/chillelse {
guess1[j-1] = name;
guess2[j-1] = count;
time[j-1] = ta;
System.out.println("Number\t\tName\t\tHigh Score\tTime (Seconds)");
System.out.println("------\t\t----\t\t----------\t--------------");
for (int h = 0; h < j; h++) {
System.out.println(" " + (h+1) + "\t\t" + guess1[h] + "\t\t" + guess2[h] + "\t\t" + time[h]);
System.out.println("");
System.out.println("Start guessing, it's a number between 1 and 1000...");
f=System.currentTimeMillis()/1000;////////////include this line here
count=0;
} -
Hi all,
I need some help in getting rid of a very slow cursor operation.
I have three tables:
1. Consignments
2. Labels
3. ConsignmentReferences
Labels table has a foreign key to Consignments. ConsginmentReferences also has a foreign key to Consginments.
I need to 'manufacture' a relationship between ConsgnmentReferences and the Labels table. Probably best shown with some example data:
Note: my solution must work on SQL 2008R2 which does not support SUM OVER ORDER BY
USE tempdb;
CREATE TABLE Consignments (
ConsignmentID Int Primary Key
GO
CREATE TABLE Labels (
LabelID BigInt Identity Primary Key,
LabelNo varchar (20),
SequenceNo Int,
ConsignmentID Int Foreign Key References Consignments (ConsignmentID)
GO
CREATE TABLE ConsignmentReferences (
ConsignmentReferenceID Int Identity,
ConsignmentID Int Foreign Key References Consignments (ConsignmentID),
NumberOfItems Int,
SequenceNo Int)
GO
/* INSERT THREE CONSIGNMENTS */
INSERT INTO Consignments
VALUES (1) ;
INSERT INTO Consignments
VALUES (2) ;
INSERT INTO Consignments
VALUES (3) ;
/* INSERT 6 LABELS AGAINST CONSIGNMENT # 1 */
INSERT INTO Labels
VALUES ('Label1', 1, 1);
INSERT INTO Labels
VALUES ('Label2', 2, 1);
INSERT INTO Labels
VALUES ('Label3', 3, 1);
INSERT INTO Labels
VALUES ('Label4', 4, 1);
INSERT INTO Labels
VALUES ('Label5', 5, 1);
INSERT INTO Labels
VALUES ('Label6', 6, 1);
/* INSERT THREE REFERENCE LINES
Note: Reference line 2 has no items, therefore, freight labels will not be 'allocated' to this reference line
INSERT INTO ConsignmentReferences
VALUES (1, 2, 1);
INSERT INTO ConsignmentReferences
VALUES (1, 0, 2);
INSERT INTO ConsignmentReferences
VALUES (1, 4, 3);
/* INSERT 6 LABELS AGAINST CONSIGNMENT # 1 */
INSERT INTO Labels
VALUES ('Label1', 1, 2);
INSERT INTO Labels
VALUES ('Label2', 2, 2);
INSERT INTO Labels
VALUES ('Label3', 3, 2);
INSERT ONE REFERENCE LINE FOR CONSIGNMENT # 2
INSERT INTO ConsignmentReferences
VALUES (2, 3, 1);
/* THREE LABELS FOR CONSGINMENT # 3 */
INSERT INTO Labels
VALUES ('Label1', 1, 3);
INSERT INTO Labels
VALUES ('Label2', 2, 3);
INSERT INTO Labels
VALUES ('Label3', 3, 3);
/* FOUR CONSGINMENT REFERENCES ON CONSIGNMENT # 3 */
INSERT INTO ConsignmentReferences
VALUES (3, 1, 1);
INSERT INTO ConsignmentReferences
VALUES (3, 0, 2);
INSERT INTO ConsignmentReferences
VALUES (3,1, 3);
INSERT INTO ConsignmentReferences
VALUES (3,1, 4);
SELECT L.*
FROM Consignments C
JOIN Labels L ON C.ConsignmentID = L.ConsignmentID;
SELECT CR.*
FROM Consignments C
JOIN ConsignmentReferences CR ON CR.ConsignmentID = C.ConsignmentID;
IF OBJECT_ID('ConsignmentReferences', 'U') IS NOT NULL
DROP TABLE ConsignmentReferences;
GO
IF OBJECT_ID('Labels', 'U') IS NOT NULL
DROP TABLE Labels;
GO
IF OBJECT_ID('Consignments', 'U') IS NOT NULL
DROP TABLE Consignments;
GO
For each consignment reference I need to x labels, where x is the ConsignmentReference's NumberOfItems.
For example, if Consignment Reference line 1 has NumberOfItems = 3, then the first three Labels are assigned to ConsignmentReference line 1.
Here is the desired output:
ConsignmentID
Label Number
Consignment Reference Sequence Number
1
Label1
1
1
Label2
1
1
Label3
3
1
Label4
3
1
Label5
3
1
Label6
3
2
Label1
1
2
Label2
1
2
Label3
1
3
Label1
1
3
Label2
3
3
Label3
4
Thanks for reading.
Cheers, Clay>> I need some help in getting rid of a very slow cursor operation. <<
No you have a bad design. So bad I cannot use it in a book because nobody would believe it! You used IDENTITY, everything is NULL-able, properly designed identifiers would be fixed length, etc – in short garbage data!
There is no such crap as a “sequence_nbr” in a valid data model, we can have a “<something>_seq” but NEVER that stupid generic! Why do you not know basics?
A count is a property of a set (duh!)
CREATE TABLE Consignments
(consignment_id INTEGER NOT NULL PRIMARY KEY,
item_cnt INTEGER NOT NULL -
– WRONG!!!!!!
CHECK (item_cnt > 0));
But a count is computed from a set! (table)
CREATE TABLE Labels
(label_nbr CHAR (20) NOT NULL PRIMARY KEY,
consignment_id INTEGER NOT NULL
REFERENCES Consignments (consignment_id)
ON DELETE UPDATE);
REFERENCES has a precise meaning in RDBMS. Your silly Consignment_References makes no sense.
You did not even know the INSERTION statement syntax!
/* insert three consignments */
INSERT INTO Consignments
VALUES (1), (2), (3) ;
Would you like to try again? You might be able to get help that would cost you $$$$ if you had to pay for it :)
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
Please help with 'Pricing' function module
Hi!
I am trying to use function module 'Pricing' but the table it_komv is still empty even after calling. I am basically trying to print some free of charge items on invoice sapscript and hence I am using 'Pricing' function in the print program. I am passing the below parameters. Please tell me whatelse I need to pass/not to pass.
wa_komk-mandt = sy-mandt.
wa_komk-kalsm = vbdkr-kalsm.
wa_komk-kappl = 'V'.
wa_komk-waerk = vbdkr-waerk.
wa_komk-knumv = vbdkr-knumv.
wa_komk-knuma = vbdkr-knuma.
wa_komk-vbtyp = vbdkr-vbtyp.
wa_komk-land1 = vbdkr-land1.
wa_komk-vkorg = vbdkr-vkorg.
wa_komk-vtweg = vbdkr-vtweg.
wa_komk-spart = vbdkr-spart.
wa_komk-prsdt = vbdkr-erdat.
wa_komk-kurst = vbdkr-kurst.
wa_komk-kurrf = vbdkr-kurrf.
wa_komk-kurrf_dat = vbdkr-kurrf_dat.
wa_komp-kposn = vbdpr-posnr.
wa_komp-kursk = vbdpr-kursk.
wa_komp-kursk_dat = vbdpr-kursk_dat.
wa_komp-werks = vbdpr-werks.
CALL FUNCTION 'PRICING'
EXPORTING
CALCULATION_TYPE = 'A'
comm_head_i = wa_komk
comm_item_i = wa_komp
PRELIMINARY = ' '
NO_CALCULATION = ' '
IMPORTING
comm_head_e = wa_komk
comm_item_e = wa_komp
TABLES
tkomv = it_komv
SVBAP =
CHANGING
REBATE_DETERMINED = ' '
Thanks a lot!Hi,
Check this example..
tables: vbdkr.
data: s_komk type KOMK.
data: s_komp type komp.
data: t_komv like KOMV occurs 0 with header line.
data: t_komvd like komvd occurs 0 with header line.
Input
s_komk-mandt = sy-mandt.
s_komk-knumv = vbdkr-knumv.
CALL FUNCTION 'RV_PRICE_PRINT_ITEM'
EXPORTING
comm_head_i = s_komk
comm_item_i = s_komp
tables
tkomv = t_komv
tkomvd = t_komvd
You can check the program RVADIN01 for a sample..
Hope this helps..
Thanks,
Naren
Maybe you are looking for
-
Stuck at the verification part of creative cloud
I didn't verificative my emailadres within the 72 hours, since the emailadres adobe has is wrong. I noticed it says hotmail whereas i have outlook. I don't receive any codes, thus I can't even log in into creative cloud. what should i do now?
-
I am having trouble connecting to 4g. I am always getting a sad face cannot connect to network
-
I've been messing around with Aperture 3 for a while now and decided it was time to try playing with the new HD video support. On Apple's Aperture "New Features" page http://www.apple.com/aperture/features/#video it states: "Video Support Import, bro
-
How do I get a java game from my pc to my mobile - I have a wire!
I hava a sony ericsson t610 and I have a wire that connects my phone to my computer but the standard sony ericsson software does allow you to send games to the phone. Is there and software I could get to do this?
-
[Sorting Problem In The GridView]
I'm using the oracle 10.2.02 beta client with the VisualStudio.NET 2005. The problem is that the sorting function in the GridView doesn't work. Is there any way to "connect" the SqlDataSource tool with the oracle connection through a DataSet ? That i