Welcome Guest ( Login | Register )



All times are UTC - 7 hours [ DST ]



Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: copy a "Tag" array into a "C#" array
PostPosted: Thu Sep 24, 2015 8:14 am 

Joined: Tue Nov 13, 2012 12:25 pm
Posts: 15

Offline
Hello,
how can i copy a "Tag" array into a "C#" array?
I tried so:
LocalFormArray = Globals.Tags.TagArray.Value;
LocalFormArray = Globals.Tags.TagArray[].Value;
LocalFormArray = Globals.Tags.TagArray.Values;
LocalFormArray = Globals.Tags.TagArray[].Values;

but none of these worked.

Thanks!


 Profile  
 
 Post subject: Re: copy a "Tag" array into a "C#" array
PostPosted: Wed Sep 30, 2015 3:31 am 

Joined: Tue Sep 08, 2015 1:32 pm
Posts: 15

Offline
Can you clarify exactly what you are trying to achieve and what type of array you are declaring in C#?

This will work but not sure if it's what you're looking for:

VariantValue[] cArray = new VariantValue[Globals.Tags.GlobalDataItems.Count];
int index = 0;
foreach (GlobalDataItem gdi in Globals.Tags.GlobalDataItems)
{
cArray[index++] = gdi.Value;
}


 Profile  
 
 Post subject: Re: copy a "Tag" array into a "C#" array
PostPosted: Thu Oct 01, 2015 12:51 am 

Joined: Tue Nov 13, 2012 12:25 pm
Posts: 15

Offline
What I try to do, if possible, is to copy all the values contained in a Tag array
in a C# array, so declared:
float[] LocalFormArray = new float[8];
in just one code line.
For the moment I do so:
for (int i = 0; i < 8; i++)
{
LocalFormArray[i] = Globals.Tags.TagArray [i].Value;
}
Attachment:
TagArrayDeclaration.png
TagArrayDeclaration.png [ 2.07 KiB | Viewed 8549 times ]


 Profile  
 
 Post subject: Re: copy a "Tag" array into a "C#" array
PostPosted: Mon Oct 05, 2015 6:34 am 

Joined: Tue Sep 08, 2015 1:32 pm
Posts: 15

Offline
If you're only doing it once, I can't see a better way to do it. If you are doing it multiple times you could create a function:

private float[] getArray(GlobalDataItem tag)
{
float[] resultArray;
try
{
resultArray = new float[tag.ArraySize];
for (int i = 0; i < tag.ArraySize; i++)
{
resultArray[i] = tag[i].Value;
}
}
catch
{
resultArray = null;
}

return resultArray;
}

and call it like so:

float[] myArray = getArray(Globals.Tags.TagArray);

I think this should work.


 Profile  
 
 Post subject: Re: copy a "Tag" array into a "C#" array
PostPosted: Tue Oct 06, 2015 2:55 am 

Joined: Tue Nov 13, 2012 12:25 pm
Posts: 15

Offline
Thanks a lot, that was the solution I was looking for.
About your previous post:

VariantValue [] = new CArray VariantValue [Globals.Tags.GlobalDataItems.Count];
int index = 0;
foreach (GlobalDataItem gdi in Globals.Tags.GlobalDataItems)
{
CArray [index ++] = gdi.Value;
}

can you do the same but only for GlobalDataItems which belong to a recipe?
Thanks!!


 Profile  
 
 Post subject: Re: copy a "Tag" array into a "C#" array
PostPosted: Tue Oct 06, 2015 8:01 am 

Joined: Tue Sep 08, 2015 1:32 pm
Posts: 15

Offline
This seems to work:

Tools.Recipe.RecipeItems ris = Globals.Recipe1.RecipeItems;
VariantValue[] cArray = new VariantValue[ris.Count];
int index = 0;
foreach (Tools.Recipe.RecipeItem ri in ris)
{
CArray[index++] = ((GlobalDataItem)ri.DataItem).Value;
}


 Profile  
 
 Post subject: Re: copy a "Tag" array into a "C#" array
PostPosted: Fri Oct 09, 2015 3:26 am 

Joined: Tue Nov 13, 2012 12:25 pm
Posts: 15

Offline
Thanks for your help Greg, it works great!
I ask one more thing, if I can,
how can I create an event that will fire whenever a GlobalDataItam changes of value?
Thanks a lot in advance!


 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 7 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron