Array with custom datatype and C#

Array with custom datatype and C#

Hi everybody, I need a hand with a code snippet that I can't overcome.
First of all I've created a custom datatype as follow
Modem
L Child 1 ->Index
L Child 2 ->Name
L Child 3 ->Telephone
L Child 4 ->MsgReceived
Then I've created an array of that Datatype with 50 objects, so I've got variables like these:
ModemArray[1].Index
ModemArray[1].Name
ModemArray[1].Telephone
ModemArray[1].MsgReceived
ModemArray[2].Index
ModemArray[2].Name
ModemArray[2].Telephone
ModemArray[2].MsgReceived
...
ModemArray[50].Index
ModemArray[50].Name
ModemArray[50].Telephone
ModemArray[50].MsgReceived
Now my problem is that in some moments I need to know the Name of the modem that sent me a message. I've got the Telephone Numbers saved in an internal variable.
Then I need to write a for cycle to run trought variables, but I'm not understanding how to use the correct object model.
My procedure is this
C# Code:

public void MacroSMSInput()
{
string TelefonoMittente = Convert.ToString(Variables().Item("Modem/Global/NumeroMittente").get_Value(0)).Remove(0,3);
string TelefonoArray = string.Empty;
string NomeVarAggiornato = string.Empty;
string NomeVarMessaggio = string.Empty;
for (int i = 1; i <= 50; i++)
{
// my problem starts here, I'm not able to using the correct objectmodel to get the value of the structured array
TelefonoArray = Convert.ToString(Variables().Item("ModemArray[" + i + "].Telephone").get_Value(0));
NomeVarAggiornato = "ModemArray[" + i + "].Aggiornato";
NomeVarMessaggio ="ModemArray[" + i + "].MsgReceived";
if (TelefonoArray == TelefonoMittente)
{
///Operation to do when I've found the correct modem
}
}
}

Another question: why do I have to force the conversion to string in this row
C# Code:
TelefonoArray = Convert.ToString(Variables().Item("ModemArray[" + i + "].Telephone").get_Value(0));

The VSTA variable TelefonoArray is a String and the Zenon variable si a string too, so why do I have to convert it?
Thank you for any useful information

This is a migrated post! Originally posted on 24.06.2014 by user luca.bardon. Please be aware that information can be outdated.

    Disclaimer

    This document governs the use of our Community Forum. By registering and using the platform, you accept these conditions.

    The COPA-DATA Community Forum serves to encourage the exchange of information and experience about the zenon software between forum users respectively zenon users.

    Please mind that any published information on the Community Forum is the subjective opinion and view based on the experience and the level of knowledge of the author. COPA-DATA does not overtake any responsibility for the content and the accuracy of the shared information.

    Users of the Community Forum are encouraged to share only well-founded experiences and to point out any risks associated with the implementation of proposed solutions to problems. COPA-DATA at its absolute discretion, reserves the right to moderate the forum. In this connection COPA-DATA may remove any information containing false facts, potentially dangerous solutions, bad language or content that may insult, degrade or discriminate others. COPA-DATA may block a non-complying user from forum access if the user violated this provision.

    COPA-DATA reserves the right to change this document from time to time at own discretion.


    Ing. Punzenberger COPA-DATA GmbH
    Karolingerstraße 7b · 5020 Salzburg · Austria
    www.copadata.com