I can not achieve if statement in my code
-
HI, I have arraylist and the first item in array represent time , the number of message in array may be reach up to 10,000 messages , so if I have messages reached to 2000 message the message number 20001 is set to 0 and when I try to get the total time I have problem because the total is the final element. some issues :- - if message set to zero after number of message I will consider the past time is 3640 seconds and so on. total time = 3640 + the last element in the last in the next items. - if number of message not set to zero the end item will represent the total time.
for (int j = 0; j < numberOfMessagesInSection; j++) { nextValue = int.Parse(MessageTimeAssociation[next + 1].messagebytes[0]); if (nextValue >= int.Parse(MessageTimeAssociation[j].messagebytes[0])) { totalSectionTime = int.Parse(MessageTimeAssociation[numberOfMessagesInSection - 1].messagebytes[0]); } else { totalSectionTime += 3640; }
this my code but my problems appears in this cases :- if the arraylist contains few messages the total time should be the final element but this code not achieve it. -
HI, I have arraylist and the first item in array represent time , the number of message in array may be reach up to 10,000 messages , so if I have messages reached to 2000 message the message number 20001 is set to 0 and when I try to get the total time I have problem because the total is the final element. some issues :- - if message set to zero after number of message I will consider the past time is 3640 seconds and so on. total time = 3640 + the last element in the last in the next items. - if number of message not set to zero the end item will represent the total time.
for (int j = 0; j < numberOfMessagesInSection; j++) { nextValue = int.Parse(MessageTimeAssociation[next + 1].messagebytes[0]); if (nextValue >= int.Parse(MessageTimeAssociation[j].messagebytes[0])) { totalSectionTime = int.Parse(MessageTimeAssociation[numberOfMessagesInSection - 1].messagebytes[0]); } else { totalSectionTime += 3640; }
this my code but my problems appears in this cases :- if the arraylist contains few messages the total time should be the final element but this code not achieve it.This has a bad code smell about it that can be detected from the moon, and that's made of cheese.
Honeyboy_20 wrote:
I have problem because the total is the final element.
So don't do that then. The main problem with this is how you are representing your data:
ArrayList
has almost zero use since generics came out. You might need aList<_Message_>
orHashSet<_Message_>
or possiblyQueue<_Message_>
it depends on what you are doing, even then other collections might be more appropriate. In any case storing multiple object types the way you have described it in anArrayList
is a recipe for disaster, you should:Create a new class to store your data
Add the appropriate Generic collection as a property (make the property read-only: you can still add items externally)
Add properties to store any timings you need
I don't fully understand your problem, but whatever it is this should provide a start.
Sort of a cross between Lawrence of Arabia and Dilbert.[^]
-Or-
A Dead ringer for Kate Winslett[^] -
This has a bad code smell about it that can be detected from the moon, and that's made of cheese.
Honeyboy_20 wrote:
I have problem because the total is the final element.
So don't do that then. The main problem with this is how you are representing your data:
ArrayList
has almost zero use since generics came out. You might need aList<_Message_>
orHashSet<_Message_>
or possiblyQueue<_Message_>
it depends on what you are doing, even then other collections might be more appropriate. In any case storing multiple object types the way you have described it in anArrayList
is a recipe for disaster, you should:Create a new class to store your data
Add the appropriate Generic collection as a property (make the property read-only: you can still add items externally)
Add properties to store any timings you need
I don't fully understand your problem, but whatever it is this should provide a start.
Sort of a cross between Lawrence of Arabia and Dilbert.[^]
-Or-
A Dead ringer for Kate Winslett[^]I ask about condition as logical if you can help ok or stop.
-
I ask about condition as logical if you can help ok or stop.
His answer is valid. Your code doesn't make any sense at all and your description of the problem only adds to the confusion. How does the number of bytes in a message relate to a time value? Why?
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
This has a bad code smell about it that can be detected from the moon, and that's made of cheese.
Honeyboy_20 wrote:
I have problem because the total is the final element.
So don't do that then. The main problem with this is how you are representing your data:
ArrayList
has almost zero use since generics came out. You might need aList<_Message_>
orHashSet<_Message_>
or possiblyQueue<_Message_>
it depends on what you are doing, even then other collections might be more appropriate. In any case storing multiple object types the way you have described it in anArrayList
is a recipe for disaster, you should:Create a new class to store your data
Add the appropriate Generic collection as a property (make the property read-only: you can still add items externally)
Add properties to store any timings you need
I don't fully understand your problem, but whatever it is this should provide a start.
Sort of a cross between Lawrence of Arabia and Dilbert.[^]
-Or-
A Dead ringer for Kate Winslett[^]Keith Barrow wrote:
that's made of cheese
limburger? ;P ;P Peter
Software rusts. Simon Stephenson, ca 1994.
-
I ask about condition as logical if you can help ok or stop.
He was being helpful. Keith is one of the good guys. I wouldn't have been as gentle. Rather than throwing a hissy fit, you should ask yourself why he replied in this manner. Perhaps then you could actually learn and grow as a developer.
Forgive your enemies - it messes with their heads
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility
-
HI, I have arraylist and the first item in array represent time , the number of message in array may be reach up to 10,000 messages , so if I have messages reached to 2000 message the message number 20001 is set to 0 and when I try to get the total time I have problem because the total is the final element. some issues :- - if message set to zero after number of message I will consider the past time is 3640 seconds and so on. total time = 3640 + the last element in the last in the next items. - if number of message not set to zero the end item will represent the total time.
for (int j = 0; j < numberOfMessagesInSection; j++) { nextValue = int.Parse(MessageTimeAssociation[next + 1].messagebytes[0]); if (nextValue >= int.Parse(MessageTimeAssociation[j].messagebytes[0])) { totalSectionTime = int.Parse(MessageTimeAssociation[numberOfMessagesInSection - 1].messagebytes[0]); } else { totalSectionTime += 3640; }
this my code but my problems appears in this cases :- if the arraylist contains few messages the total time should be the final element but this code not achieve it. -
HI, I have arraylist and the first item in array represent time , the number of message in array may be reach up to 10,000 messages , so if I have messages reached to 2000 message the message number 20001 is set to 0 and when I try to get the total time I have problem because the total is the final element. some issues :- - if message set to zero after number of message I will consider the past time is 3640 seconds and so on. total time = 3640 + the last element in the last in the next items. - if number of message not set to zero the end item will represent the total time.
for (int j = 0; j < numberOfMessagesInSection; j++) { nextValue = int.Parse(MessageTimeAssociation[next + 1].messagebytes[0]); if (nextValue >= int.Parse(MessageTimeAssociation[j].messagebytes[0])) { totalSectionTime = int.Parse(MessageTimeAssociation[numberOfMessagesInSection - 1].messagebytes[0]); } else { totalSectionTime += 3640; }
this my code but my problems appears in this cases :- if the arraylist contains few messages the total time should be the final element but this code not achieve it.I was confused when I read this question the first time. Then I was even more confused when I read it the second time. I don“t like to read this question a third time.
I cannot remember: What did I before google?
-
I ask about condition as logical if you can help ok or stop.
Thats one of the things I like about the code project, you might not get the answer you want but someone will give you the answer you need. I doubt anyone will understand what you wanted, it certainly isn't clear from the code. When this happens, irrespective of who writes it, it means than more than likely the code has a design flaw. Fix the design flaw first and quite often the problem you are having dissapears or become easy to spot.
Sort of a cross between Lawrence of Arabia and Dilbert.[^]
-Or-
A Dead ringer for Kate Winslett[^] -
I ask about condition as logical if you can help ok or stop.
Stop being an ass hat...
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997