[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Reading last value of counter

Posted on 2011-03-13
17
Medium Priority
?
234 Views
Last Modified: 2012-05-11
Please how to read last value in loop counting
if ((now.getTime() - lastReceived.getTime()) > 100L) {
                counter = 1;
            } else {
                counter++;
            }
             o_pos = counter;????// this must be maximum counted value

Open in new window

0
Comment
Question by:gbcbr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
17 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 35121268
Just print it out right before you set it to 1.
You can also set up one more int value at the beginning and then make it equal to counter at the same point right before resetting counter to 1, and then printout this variable later
0
 
LVL 7

Expert Comment

by:wdfdo1986
ID: 35121403
There are no loops in the code given here
initialize a variable before the loop and set value in the last step of the loop.
Post some more code to more help
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35121730
Try the following:
o_pos += (counter + 1);
	if ((now.getTime() - lastReceived.getTime()) > 100L) {
	    counter = 1;
	} else {
	    counter++;
	}

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:objects
ID: 35123720
this will do what you need:

o_pos = ++counter;
if ((now.getTime() - lastReceived.getTime()) > 100L) {
     counter = 1;
}

Points to for_yan who suggested similiar in first comment
0
 

Author Comment

by:gbcbr
ID: 35124417
no, it still shows all counting:
OpenPositionControl o_pos  53
 OpenPositionControl o_pos  2
 OpenPositionControl o_pos  3
 OpenPositionControl o_pos  4
 OpenPositionControl o_pos  5
 OpenPositionControl o_pos  6
 OpenPositionControl o_pos  7
 OpenPositionControl o_pos  8
 OpenPositionControl o_pos  9
 OpenPositionControl o_pos  10
 OpenPositionControl o_pos  11
 OpenPositionControl o_pos  12
 OpenPositionControl o_pos  13
 OpenPositionControl o_pos  14
 OpenPositionControl o_pos  15
 OpenPositionControl o_pos  16
 OpenPositionControl o_pos  17
 OpenPositionControl o_pos  18
 OpenPositionControl o_pos  19
 OpenPositionControl o_pos  20
 OpenPositionControl o_pos  21
 OpenPositionControl o_pos  22
 OpenPositionControl o_pos  23
 OpenPositionControl o_pos  24
 OpenPositionControl o_pos  25
DBFX open positions = RequestForPositionsAck{mAccount='all', mFXCMErrorDetails='null', mFXCMRequestRejectReason=-1, mParties=Parties [Party:3:D:FXCM ID();], mPosReqID='DB_U100D1_DSTkGF2JwKyCFT6dspZQs16Av1VrvzVlRjB7S7XjQdW26Qv9nPVT4u-605', mPosReqResult=PosReqResult:Valid Request (0), mPosReqStatus=PosReqStatus:Completed (0), mText='null', mTotalNumPosReports=26, mTradingSessionID='FXCM', mTradingSessionSubID='DBFXUSDD1', mPosMaintRptID='541484206', mMakingTime=1300061808097}
 OpenPositionControl o_pos  26
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  28
 OpenPositionControl o_pos  29
 OpenPositionControl o_pos  30
 OpenPositionControl o_pos  31
 OpenPositionControl o_pos  32
 OpenPositionControl o_pos  33
 OpenPositionControl o_pos  34
 OpenPositionControl o_pos  35
 OpenPositionControl o_pos  36
 OpenPositionControl o_pos  37
 OpenPositionControl o_pos  38
 OpenPositionControl o_pos  39
 OpenPositionControl o_pos  40
 OpenPositionControl o_pos  41
 OpenPositionControl o_pos  42
 OpenPositionControl o_pos  43
 OpenPositionControl o_pos  44
 OpenPositionControl o_pos  45
 OpenPositionControl o_pos  46
 OpenPositionControl o_pos  47
 OpenPositionControl o_pos  48
 OpenPositionControl o_pos  49
 OpenPositionControl o_pos  50
 OpenPositionControl o_pos  51
 PMDS bidPx[0]   1.39242
DBFX open positions = RequestForPositionsAck{mAccount='all', mFXCMErrorDetails='null', mFXCMRequestRejectReason=-1, mParties=Parties [Party:3:D:FXCM ID();], mPosReqID='DB_U100D1_DSTkGF2JwKyCFT6dspZQs16Av1VrvzVlRjB7S7XjQdW26Qv9nPVT4u-660', mPosReqResult=PosReqResult:Valid Request (0), mPosReqStatus=PosReqStatus:Completed (0), mText='null', mTotalNumPosReports=26, mTradingSessionID='FXCM', mTradingSessionSubID='DBFXUSDD1', mPosMaintRptID='541484206', mMakingTime=1300061810916}
 OpenPositionControl o_pos  52
 OpenPositionControl o_pos  2
 OpenPositionControl o_pos  3
 OpenPositionControl o_pos  4
 OpenPositionControl o_pos  5

Open in new window

but I need only last.
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 35124428
try this:

o_pos = Math.max(opos, ++counter);
if ((now.getTime() - lastReceived.getTime()) > 100L) {
     counter = 1;
}
0
 

Author Comment

by:gbcbr
ID: 35124458
now better, but anyway not only last value:
OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
DBFX open positions = RequestForPositionsAck{mAccount='all', mFXCMErrorDetails='null', mFXCMRequestRejectReason=-1, mParties=Parties [Party:3:D:FXCM ID();], mPosReqID='DB_U100D1_rj0cQTj6PpBi5PFJTXX3vimRSOD7xDZ0dkrglzNW1cItV5pD43iwMC-606', mPosReqResult=PosReqResult:Valid Request (0), mPosReqStatus=PosReqStatus:Completed (0), mText='null', mTotalNumPosReports=25, mTradingSessionID='FXCM', mTradingSessionSubID='DBFXUSDD1', mPosMaintRptID='541484206', mMakingTime=1300062251441}
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27
DBFX open positions = RequestForPositionsAck{mAccount='all', mFXCMErrorDetails='null', mFXCMRequestRejectReason=-1, mParties=Parties [Party:3:D:FXCM ID();], mPosReqID='DB_U100D1_rj0cQTj6PpBi5PFJTXX3vimRSOD7xDZ0dkrglzNW1cItV5pD43iwMC-660', mPosReqResult=PosReqResult:Valid Request (0), mPosReqStatus=PosReqStatus:Completed (0), mText='null', mTotalNumPosReports=26, mTradingSessionID='FXCM', mTradingSessionSubID='DBFXUSDD1', mPosMaintRptID='541484206', mMakingTime=1300062252953}
 OpenPositionControl o_pos  27
 OpenPositionControl o_pos  27

Open in new window

In general, it doesn't damage my system, but field open positions flashing all the time
0
 
LVL 92

Expert Comment

by:objects
ID: 35124470
> now better, but anyway not only last value:

I don't understand. Can you clarify what you mean
0
 

Author Comment

by:gbcbr
ID: 35124485
>>Can you clarify what you mean
Means, before it shows all number from the beginning and now printout sum, 26 times. But I need only one time
0
 
LVL 92

Expert Comment

by:objects
ID: 35124499
That suggests the above calculation of the value is fine then
that sounds more like an issue with your loop or how you are displaying it.
0
 

Author Comment

by:gbcbr
ID: 35124500
I expect only one final result, when calculation finished, means stopped, because interruption interval is exceeded.
0
 
LVL 92

Expert Comment

by:objects
ID: 35124513
thats sounds outside the scope of the code in the question
suggest you open a new question to address that
0
 

Author Comment

by:gbcbr
ID: 35124514
Now I decrease interval down to 50L, so as soon I don't have new messages over 50L, I need just final amount, how many it was. Not permanent counting, only the last.
0
 
LVL 92

Expert Comment

by:objects
ID: 35124517
> Not permanent counting, only the last.

the first snippet I posted did that
0
 
LVL 92

Expert Comment

by:objects
ID: 35124522
open a new question to address how you are using it
0
 

Author Comment

by:gbcbr
ID: 35124523
no, it shows 26 times the same result
0
 

Author Comment

by:gbcbr
ID: 35124524
OK
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question