variable names
-
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
-
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
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
-
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
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.
-
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
-
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.
-
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.
-
Could you use an IEnumerable collection here?
There's nothing left in my right brain and nothing right in my left brain.
could you give me a little sample of using IEnumerable in my above code? thanks
-
could you give me a little sample of using IEnumerable in my above code? thanks
-
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.
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();
-
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();
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]. = "...." etcThere's nothing left in my right brain and nothing right in my left brain.
-
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]. = "...." etcThere's nothing left in my right brain and nothing right in my left brain.
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?)
-
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]. = "...." etcThere's nothing left in my right brain and nothing right in my left brain.
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
-
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();
[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>
isIEnumerable
, 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
-
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.
What is it you're
foreach
ing? -
What is it you're
foreach
ing?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(); }