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. variable names

variable names

Scheduled Pinned Locked Moved C#
tutorialquestion
15 Posts 6 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.
  • B Offline
    B Offline
    benjamin yap
    wrote on last edited by
    #1

    Hi, I want to create an Annotation object inside a foreach loop with different name for it. Example

    foreach(...)
    {
    Annotation anno_1 = charts[0].CreateAnnotation();
    }

    How can i create the name of the Annotation foreach item.. example anno_1, anno_2, anno_3.. thanks

    OriginalGriffO K P 3 Replies Last reply
    0
    • B benjamin yap

      Hi, I want to create an Annotation object inside a foreach loop with different name for it. Example

      foreach(...)
      {
      Annotation anno_1 = charts[0].CreateAnnotation();
      }

      How can i create the name of the Annotation foreach item.. example anno_1, anno_2, anno_3.. thanks

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

      At a stab:

      List<Annotation> annotations = new List<Annotation>();

      foreach(var chart in charts)
      {
      Annotations.Add(chart.CreateAnnotation());
      }

      CCC solved so far: 2 (including a Hard One!) 37!?!! - Randall, Clerks

      1 Reply Last reply
      0
      • B benjamin yap

        Hi, I want to create an Annotation object inside a foreach loop with different name for it. Example

        foreach(...)
        {
        Annotation anno_1 = charts[0].CreateAnnotation();
        }

        How can i create the name of the Annotation foreach item.. example anno_1, anno_2, anno_3.. thanks

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        Why? How are you going to refer to them again? (without confusing the code with reflection of your running stuff?) Why not just keep them in a list like everyone else?

        All those who believe in psycho kinesis, raise my hand.

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        1 Reply Last reply
        0
        • B benjamin yap

          Hi, I want to create an Annotation object inside a foreach loop with different name for it. Example

          foreach(...)
          {
          Annotation anno_1 = charts[0].CreateAnnotation();
          }

          How can i create the name of the Annotation foreach item.. example anno_1, anno_2, anno_3.. thanks

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          Choose a different language. You can do that in DCL[^]. :-D But, seriously, use System.Collections.Generic.List<Annotation>.

          B 1 Reply Last reply
          0
          • P PIEBALDconsult

            Choose a different language. You can do that in DCL[^]. :-D But, seriously, use System.Collections.Generic.List<Annotation>.

            B Offline
            B Offline
            benjamin yap
            wrote on last edited by
            #5

            actually this is the code i want to run inside the foreach loop

                    // Add annotation to the line chart.
                    Annotation aonnotation = m\_ChartControl.Charts\[0\].AnnotationList.CreateAnnotation();
            
                    // Bind annotation to the first category in the last series (Volume).
                    // X coordinate is category
                    // Y coordinate is series
                    aonnotation.Location.TypeX = LengthType.Bound;
                    aonnotation.Location.X = 6;
                    aonnotation.Location.TypeY = LengthType.Bound;
                    aonnotation.Location.Y = 0;
            
                    // Set annotation properties
                    aonnotation.Data = "     ";
                    aonnotation.Font.Size = 4;
                    aonnotation.Font.Bold = false;
                    aonnotation.Color = Color.FromArgb(1, 1, 1);
            
                    modulePath = this.GetType().Module.FullyQualifiedName;
                    moduleDir = Path.GetDirectoryName(modulePath);
                    aonnotation.ImageFile = Path.Combine(moduleDir, "ArrUp.png");
            

            This code will be create in each loop, but i cannot use the same variable name aonnotation because i need different name to generate annotations onto my chart.

            A P 2 Replies Last reply
            0
            • B benjamin yap

              actually this is the code i want to run inside the foreach loop

                      // Add annotation to the line chart.
                      Annotation aonnotation = m\_ChartControl.Charts\[0\].AnnotationList.CreateAnnotation();
              
                      // Bind annotation to the first category in the last series (Volume).
                      // X coordinate is category
                      // Y coordinate is series
                      aonnotation.Location.TypeX = LengthType.Bound;
                      aonnotation.Location.X = 6;
                      aonnotation.Location.TypeY = LengthType.Bound;
                      aonnotation.Location.Y = 0;
              
                      // Set annotation properties
                      aonnotation.Data = "     ";
                      aonnotation.Font.Size = 4;
                      aonnotation.Font.Bold = false;
                      aonnotation.Color = Color.FromArgb(1, 1, 1);
              
                      modulePath = this.GetType().Module.FullyQualifiedName;
                      moduleDir = Path.GetDirectoryName(modulePath);
                      aonnotation.ImageFile = Path.Combine(moduleDir, "ArrUp.png");
              

              This code will be create in each loop, but i cannot use the same variable name aonnotation because i need different name to generate annotations onto my chart.

              A Offline
              A Offline
              Abhinav S
              wrote on last edited by
              #6

              Could you use an IEnumerable collection here?

              There's nothing left in my right brain and nothing right in my left brain.

              B 1 Reply Last reply
              0
              • A Abhinav S

                Could you use an IEnumerable collection here?

                There's nothing left in my right brain and nothing right in my left brain.

                B Offline
                B Offline
                benjamin yap
                wrote on last edited by
                #7

                could you give me a little sample of using IEnumerable in my above code? thanks

                A 1 Reply Last reply
                0
                • B benjamin yap

                  could you give me a little sample of using IEnumerable in my above code? thanks

                  A Offline
                  A Offline
                  Abhinav S
                  wrote on last edited by
                  #8

                  foreach(...){IEnumerable anno = charts[0].CreateAnnotation();} You can then access each of the annotation objects like an array. anno[0]. = "...." etc.

                  There's nothing left in my right brain and nothing right in my left brain.

                  B 1 Reply Last reply
                  0
                  • A Abhinav S

                    foreach(...){IEnumerable anno = charts[0].CreateAnnotation();} You can then access each of the annotation objects like an array. anno[0]. = "...." etc.

                    There's nothing left in my right brain and nothing right in my left brain.

                    B Offline
                    B Offline
                    benjamin yap
                    wrote on last edited by
                    #9

                    hmm i get this error Error 21 Cannot implicitly convert type 'Manco.Chart.CF.Layout.Annotation' to 'System.Collections.IEnumerable'. An explicit conversion exists (are you missing a cast?) I tried doing this also cant work IEnumberable anno = m_ChartControl.Charts[0].AnnotationList.CreateAnnotation();

                    A K 2 Replies Last reply
                    0
                    • B benjamin yap

                      hmm i get this error Error 21 Cannot implicitly convert type 'Manco.Chart.CF.Layout.Annotation' to 'System.Collections.IEnumerable'. An explicit conversion exists (are you missing a cast?) I tried doing this also cant work IEnumberable anno = m_ChartControl.Charts[0].AnnotationList.CreateAnnotation();

                      A Offline
                      A Offline
                      Abhinav S
                      wrote on last edited by
                      #10

                      Apologies. This may work. IEnumerable<Annotation> anno; foreach(...){ anno.Add(charts[0].CreateAnnotation());} You can then access each of the annotation objects like an array. anno[0]. = "...." etc

                      There's nothing left in my right brain and nothing right in my left brain.

                      B L 2 Replies Last reply
                      0
                      • A Abhinav S

                        Apologies. This may work. IEnumerable<Annotation> anno; foreach(...){ anno.Add(charts[0].CreateAnnotation());} You can then access each of the annotation objects like an array. anno[0]. = "...." etc

                        There's nothing left in my right brain and nothing right in my left brain.

                        B Offline
                        B Offline
                        benjamin yap
                        wrote on last edited by
                        #11

                        hmm now i get this error Error 21 'System.Collections.Generic.IEnumerable<Manco.Chart.CF.Layout.Annotation>' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'System.Collections.Generic.IEnumerable<Manco.Chart.CF.Layout.Annotation>' could be found (are you missing a using directive or an assembly reference?)

                        1 Reply Last reply
                        0
                        • A Abhinav S

                          Apologies. This may work. IEnumerable<Annotation> anno; foreach(...){ anno.Add(charts[0].CreateAnnotation());} You can then access each of the annotation objects like an array. anno[0]. = "...." etc

                          There's nothing left in my right brain and nothing right in my left brain.

                          L Offline
                          L Offline
                          Luc Pattyn
                          wrote on last edited by
                          #12

                          of course that should work. and so would a List<Annotation> as has been said earlier. I suggest you read up on the List class and some generic stuff, it is really powerful, and you can use it as an array (and more). :)

                          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                          I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                          1 Reply Last reply
                          0
                          • B benjamin yap

                            hmm i get this error Error 21 Cannot implicitly convert type 'Manco.Chart.CF.Layout.Annotation' to 'System.Collections.IEnumerable'. An explicit conversion exists (are you missing a cast?) I tried doing this also cant work IEnumberable anno = m_ChartControl.Charts[0].AnnotationList.CreateAnnotation();

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

                            [Edited to clarify my rubbish English] The problem is, judging from your code, m_ChartControl.Charts[0].AnnotationList.CreateAnnotation(); creates an individual annotation not a collection of annotations. This is causing the error you are getting. In my earlier post, List<Annotation> is IEnumerable, and it shows you how to add individual annotations. The problem you are experiencing in getting an answer here is because what you asked for in your original post is highly unusual in c# (though possible in laguages that follow a different paradigm). The normal c# practise is to create a in instance of a collection type such as list, array or collection (or their generic equivalents which are better) and add objects to the collection (rather than trying to create paremeters for each). You can the iterate over the collection as required. What is the reason for trying to create a parameter-per-annotation?

                            CCC solved so far: 2 (including a Hard One!) 37!?!! - Randall, Clerks

                            1 Reply Last reply
                            0
                            • B benjamin yap

                              actually this is the code i want to run inside the foreach loop

                                      // Add annotation to the line chart.
                                      Annotation aonnotation = m\_ChartControl.Charts\[0\].AnnotationList.CreateAnnotation();
                              
                                      // Bind annotation to the first category in the last series (Volume).
                                      // X coordinate is category
                                      // Y coordinate is series
                                      aonnotation.Location.TypeX = LengthType.Bound;
                                      aonnotation.Location.X = 6;
                                      aonnotation.Location.TypeY = LengthType.Bound;
                                      aonnotation.Location.Y = 0;
                              
                                      // Set annotation properties
                                      aonnotation.Data = "     ";
                                      aonnotation.Font.Size = 4;
                                      aonnotation.Font.Bold = false;
                                      aonnotation.Color = Color.FromArgb(1, 1, 1);
                              
                                      modulePath = this.GetType().Module.FullyQualifiedName;
                                      moduleDir = Path.GetDirectoryName(modulePath);
                                      aonnotation.ImageFile = Path.Combine(moduleDir, "ArrUp.png");
                              

                              This code will be create in each loop, but i cannot use the same variable name aonnotation because i need different name to generate annotations onto my chart.

                              P Offline
                              P Offline
                              PIEBALDconsult
                              wrote on last edited by
                              #14

                              What is it you're foreaching?

                              B 1 Reply Last reply
                              0
                              • P PIEBALDconsult

                                What is it you're foreaching?

                                B Offline
                                B Offline
                                benjamin yap
                                wrote on last edited by
                                #15

                                well.. basically this is wat i am foreaching

                                    public void AddAnnotations()
                                    {
                                        string toa = "calls";
                                        while (true)
                                        {
                                
                                            XmlDocument xmlPlogs = getAllPlogs(toa);
                                            XmlNodeList plogs = xmlPlogs.SelectNodes("/PlogList/Plog");
                                
                                            Annotation\[\] anno = null;
                                            int countA = 0;
                                            int arrayIndex = 0;
                                            foreach (XmlNode plog in plogs)
                                            {
                                                XmlNodeList receivers = plog.SelectNodes("PlogUnique/Message/Receiver");
                                
                                                foreach (DateTime dt in dateArray)
                                                {
                                                    DateTime newDT = Convert.ToDateTime(plog.SelectSingleNode("PlogCommon/TimeOfOccurrence").InnerText);
                                                    newDT = Convert.ToDateTime(newDT.ToString("dd MMM"));
                                                    String content = plog.SelectSingleNode("PlogUnique/Message/Content").InnerText;
                                                    if((content.Contains(stockQuote)) && (newDT.ToString() == dt.ToString()))
                                                    {
                                                        for (int i = 0; i < dateArray.Length; i++)
                                                        {
                                                            if (dateArray\[i\] == newDT)
                                                            {
                                                                arrayIndex = i;
                                                            }
                                                        }
                                                        anno\[countA\] = m\_ChartControl.Charts\[0\].AnnotationList.CreateAnnotation();
                                                        anno\[countA\].Location.TypeX = LengthType.Bound;
                                                        anno\[countA\].Location.X = arrayIndex;
                                                        anno\[countA\].Location.TypeY = LengthType.Bound;
                                                        anno\[countA\].Location.Y = 0;
                                
                                                        anno\[countA\].Data = "     ";
                                                        anno\[countA\].Font.Size = 4;
                                                        anno\[countA\].Font.Bold = false;
                                                        anno\[countA\].Color = Color.FromArgb(1, 1, 1);
                                
                                                        modulePath = this.GetType().Module.FullyQualifiedName;
                                                        moduleDir = Path.GetDirectoryName(modulePath);
                                                        anno\[countA\].ImageFile = Path.Combine(moduleDir, "ArrUp.png");
                                                        countA++;
                                                    }
                                                    
                                                }
                                            }
                                            Thread.Sleep(5 \* 60 \* 1000);
                                            ResetChart();
                                        }
                                
                                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