Showing results 1 to 4 of 4

Thread: 1. Modify BitAddr of variable, 2. edit SubItems of variable

  1. #1

    Frage 1. Modify BitAddr of variable, 2. edit SubItems of variable

    Hello,
    I have two questions:
    1. how can I edit the BitAddr of a variable (see remark in code below)?
    2. how to access properties of Variable.SubItem?
    i.e. zVar.SubItemName(inc) is working, but zVar.SubItem(inc).Name throws an exception saying: "Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt."
    same with zVar.SubItem(inc).BitAddr = 1;

    please look at this code:
    Code:
    zenOn.IVariable zVar = myVariables.CreateArrayVarEx(VarName, zDriver, kanalType, zVarType, editedStartIdx, idxEnd, 0, 0, 0, true);
                if (zVar != null)
                {
                    zVar.NetAddr = netAddress;
                    zVar.DataBlock = dataBlock;
                    zVar.Offset = Offset;
    
                    //setting BitAddress ist not possible, Exception = "Beim Aufruf einer COM-Komponente wurde ein HRESULT E_FAIL-Fehler zurückgegeben."
                    zVar.BitAddr = BitAddr;
    
                    for (int inc = 0; inc < zVar.SubItemCount(); inc++)
                    {
                        zVar.ActivateSubItem(inc);
                    }
                }

  2. #2
    Join Date
    16.05.2016
    Posts
    10

    Default Re: 1. Modify BitAddr of variable, 2. edit SubItems of variable

    Quote Originally Posted by professor_hubert_farnsworth View Post
    Hello,
    I have two questions:
    1. how can I edit the BitAddr of a variable (see remark in code below)?
    2. how to access properties of Variable.SubItem?
    i.e. zVar.SubItemName(inc) is working, but zVar.SubItem(inc).Name throws an exception saying: "Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt."
    same with zVar.SubItem(inc).BitAddr = 1;

    please look at this code:
    Code:
    zenOn.IVariable zVar = myVariables.CreateArrayVarEx(VarName, zDriver, kanalType, zVarType, editedStartIdx, idxEnd, 0, 0, 0, true);
                if (zVar != null)
                {
                    zVar.NetAddr = netAddress;
                    zVar.DataBlock = dataBlock;
                    zVar.Offset = Offset;
    
                    //setting BitAddress ist not possible, Exception = "Beim Aufruf einer COM-Komponente wurde ein HRESULT E_FAIL-Fehler zurückgegeben."
                    zVar.BitAddr = BitAddr;
    
                    for (int inc = 0; inc < zVar.SubItemCount(); inc++)
                    {
                        zVar.ActivateSubItem(inc);
                    }
                }

    Hi,

    I think you need to define the "zVar" as "IVariable" object that pointing to the created variable. And also the arguments for "myVariables.CreateArrayVar()" method need to be correct.

    You can try as below. I got it worked on my workspace script.


    zenOn.IVariables myVariables = this.myZenWork.ActiveDocument.Variables();

    myVariables.CreateArrayVarEx(VarName, zDriver, kanalType, zVarType, editedStartIdx, idxEnd, 0, 0, true, false, false);

    zenOn.IVariable zVar = myVariables.Item(VarName);

    if (zVar != null)
    {
    zVar.NetAddr = netAddress;
    zVar.DataBlock = dataBlock;
    zVar.Offset = Offset;

    for (int inc = 0; inc < zVar.SubItemCount(); inc++)
    {
    zVar.ActivateSubItem(inc);
    zVar.SubItem(inc).BitAddr = inc;
    bitname[inc] = zVar.SubItem(inc).Name;
    }
    }
    Last edited by huybbc : 17th January 2017 at 14:06

  3. #3

    Daumen hoch Re: 1. Modify BitAddr of variable, 2. edit SubItems of variable

    Hi huybbc,

    Now it is working. Hooray!
    My code was mostly correct (I'm using zenOn V6.51, maybe the parameters of CreateArrayVarEx have changed in the newer versions), the only thing that was not correct was that it seems that you have to activate the variable first before you can access properties this way: zVar.SubItem(inc).Name.
    Thank you for giving the crucial hint *clap*clap*

  4. #4
    Join Date
    16.05.2016
    Posts
    10

    Default Re: 1. Modify BitAddr of variable, 2. edit SubItems of variable

    Hi professor_hubert_farnsworth,

    Great to know that you get it worked. Sorry I did not notice the difference between zenOn version I am using 7.20.

    Cheer!

Similar Threads

  1. Modify Variable properties in VSTA
    By huybbc in forum VSTA
    Replies: 1
    Last Post: 9th January 2017, 14:13
  2. Edit variable in Editor from VBA
    By natali in forum VBA
    Replies: 20
    Last Post: 11th April 2013, 15:57
  3. Replies: 1
    Last Post: 2nd August 2011, 10:21
  4. Edit Variable limit (Delay)
    By rloureiro in forum VBA
    Replies: 5
    Last Post: 12th September 2008, 09:25

Posting Rules

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