Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. I can not achieve if statement in my code

I can not achieve if statement in my code

Scheduled Pinned Locked Moved C#
data-structureshelp
10 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Honeyboy_20
    wrote on last edited by
    #1

    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.

    K G T 3 Replies Last reply
    0
    • H Honeyboy_20

      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.

      K Offline
      K Offline
      Keith Barrow
      wrote on last edited by
      #2

      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 a List<_Message_> or HashSet<_Message_> or possibly Queue<_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 an ArrayList 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[^]

      H P 2 Replies Last reply
      0
      • K Keith Barrow

        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 a List<_Message_> or HashSet<_Message_> or possibly Queue<_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 an ArrayList 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[^]

        H Offline
        H Offline
        Honeyboy_20
        wrote on last edited by
        #3

        I ask about condition as logical if you can help ok or stop.

        D P K realJSOPR 4 Replies Last reply
        0
        • H Honeyboy_20

          I ask about condition as logical if you can help ok or stop.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • K Keith Barrow

            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 a List<_Message_> or HashSet<_Message_> or possibly Queue<_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 an ArrayList 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[^]

            P Offline
            P Offline
            Peter_in_2780
            wrote on last edited by
            #5

            Keith Barrow wrote:

            that's made of cheese

            limburger? ;P ;P Peter

            Software rusts. Simon Stephenson, ca 1994.

            1 Reply Last reply
            0
            • H Honeyboy_20

              I ask about condition as logical if you can help ok or stop.

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • H Honeyboy_20

                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.

                G Offline
                G Offline
                Groulien
                wrote on last edited by
                #7

                Where did the 'next' and 'numberOfMessagesInSection' come from? You're using it in the statment but none of us know how they are declared or how they're being used.

                1 Reply Last reply
                0
                • H Honeyboy_20

                  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.

                  T Offline
                  T Offline
                  Thomas Krojer
                  wrote on last edited by
                  #8

                  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?

                  1 Reply Last reply
                  0
                  • H Honeyboy_20

                    I ask about condition as logical if you can help ok or stop.

                    K Offline
                    K Offline
                    Keith Barrow
                    wrote on last edited by
                    #9

                    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[^]

                    1 Reply Last reply
                    0
                    • H Honeyboy_20

                      I ask about condition as logical if you can help ok or stop.

                      realJSOPR Offline
                      realJSOPR Offline
                      realJSOP
                      wrote on last edited by
                      #10

                      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

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups