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
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
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