Showing results 1 to 4 of 4

Thread: Array with custom datatype and C#

  1. #1
    Join Date
    27.10.2011
    Location
    Verona
    Posts
    29

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

  2. #2
    Join Date
    27.10.2011
    Location
    Verona
    Posts
    29

    Default Re: Array with custom datatype and C#

    I've forgotten to specify one thing:

    in my custom datatype these are the primitive datatype

    Modem
    L Child 1 ->Index (INT)
    L Child 2 ->Name (STRING)
    L Child 3 ->Telephone (STRING)
    L Child 4 ->MsgReceived (STRING)

  3. #3
    Join Date
    13.08.2013
    Posts
    57

    Default Re: Array with custom datatype and C#

    Try "ModemArray[" + i.ToString() + "].Telephone" etc.

    should work

    Best Regards
    Sigi

  4. #4
    Join Date
    27.10.2011
    Location
    Verona
    Posts
    29

    Default Re: Array with custom datatype and C#

    The only one solution found is to use OnlineVariables container, in that way I've read variables ;-)
    Thx everyone for help!

Similar Threads

  1. Report Viewer. Custom Assemblies
    By slaff in forum zenon Supervisor
    Replies: 4
    Last Post: 3rd April 2014, 08:06
  2. Editing structure datatype
    By yolovs in forum zenon Supervisor
    Replies: 2
    Last Post: 8th July 2013, 14:22
  3. Login with custom keyboard screen
    By batabaha in forum zenon Supervisor
    Replies: 1
    Last Post: 15th April 2012, 23:33
  4. Different drivers in one structure datatype
    By stolyarov_as in forum zenon Supervisor
    Replies: 2
    Last Post: 13th December 2011, 08:30
  5. Program access to structure datatype variables
    By stolyarov_as in forum VBA
    Replies: 2
    Last Post: 8th August 2011, 14:21

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •