Showing results 1 to 9 of 9

Thread: Delete structured tag

  1. #1
    Join Date
    17.12.2007
    Posts
    35

    Default Delete structured tag

    me again

        VarTypeIndex = 0
        For Index = zPRJ.VarTypes.Count - 1 To 0 Step -1
            Name = zPRJ.VarTypes.Item(Index).Name
            If Right(Name, 13) = ".InternalData" Or _
            Right(Name, 9) = ".MathData" Or _
            Right(Name, 9) = ".NodeData" Or _
            Right(Name, 13) = ".WriteTrigger" Then
                VarTypeID(VarTypeIndex) = CInt(zPRJ.VarTypes.Item(Index).ID)
                VarTypeIndex = VarTypeIndex + 1
            End If
        Next Index
        
        For Index = zPRJ.Variables.Count - 1 To 0 Step -1
            Set zVAR = zPRJ.Variables.Item(Index)
            Name = zVAR.Name
            ID = zVAR.DynProperties("ID_DataTyp")
            For Index2 = 0 To VarTypeIndex - 1
                If ID = VarTypeID(Index2) Then
                    If Name <> "ICON2K" And _
                    Name <> "ICON2Ki" And _
                    Name <> "ICON2Km" And _
                    Name <> "ICON2K.WriteTrigger" And _
                    Name <> "NET" And _
                    Name <> "NETi" And _
                    Name <> "ROUTERA" And _
                    Name <> "ROUTERAi" And _
                    Name <> "ROUTERB" And _
                    Name <> "ROUTERBi" And _
                    Name <> "LOOPi" And _
                    Name <> "LOOPm" Then
                        If zPRJ.Variables.DeleteVar(Name) = False Then
                            AddLogInfo "Variable: " & Index & " " & Name & " error while deleting"
                        End If
                        AddLogInfo "Variable: " & Index & " " & Name & " deleted"
                    End If
                    Exit For
                End If
            Next Index2
        Next Index

    with this code, I want to delete all the structured tag (all of them has more then one item), build on 4 specified datatype.
    Everything look run good, but on delete action code return me an error.
    I tried a lot of solution:
    descrease "Index" based on subitem number
    deactivate all subitem before delete the tag
    and many other
    probably there is something that I don't know
    could you help me?
    hoping to be clear enought .....
    thank you

  2. #2
    robertf Gast

    Default Re: Delete structured tag

    Hi fabios!

    I found a problem in your code, maybe this is the cause of the error message...
    I have not tested it, because therefor i would need your project too.

    It is possible, that the error comes up, because you already have an pointer (object) to the variable you want to delete...

    VarTypeIndex = 0
        For Index = zPRJ.VarTypes.Count - 1 To 0 Step -1
            Name = zPRJ.VarTypes.Item(Index).Name
            If Right(Name, 13) = ".InternalData" Or _
            Right(Name, 9) = ".MathData" Or _
            Right(Name, 9) = ".NodeData" Or _
            Right(Name, 13) = ".WriteTrigger" Then
                VarTypeID(VarTypeIndex) = CInt(zPRJ.VarTypes.Item(Index).ID)
                VarTypeIndex = VarTypeIndex + 1
            End If
        Next Index
     
        For Index = zPRJ.Variables.Count - 1 To 0 Step -1
            Set zVAR = zPRJ.Variables.Item(Index)
            Name = zVAR.Name
            ID = zVAR.DynProperties("ID_DataTyp")
    
            '!!!release the variable object!!!
            Set zVAR = Nothing
            '---------------------------------
    
            For Index2 = 0 To VarTypeIndex - 1
                If ID = VarTypeID(Index2) Then
                    If Name <> "ICON2K" And _
                    Name <> "ICON2Ki" And _
                    Name <> "ICON2Km" And _
                    Name <> "ICON2K.WriteTrigger" And _
                    Name <> "NET" And _
                    Name <> "NETi" And _
                    Name <> "ROUTERA" And _
                    Name <> "ROUTERAi" And _
                    Name <> "ROUTERB" And _
                    Name <> "ROUTERBi" And _
                    Name <> "LOOPi" And _
                    Name <> "LOOPm" Then
                        If zPRJ.Variables.DeleteVar(Name) = False Then
                            AddLogInfo "Variable: " & Index & " " & Name & " error while deleting"
                        End If
                        AddLogInfo "Variable: " & Index & " " & Name & " deleted"
                    End If
                    Exit For
                End If
            Next Index2
        Next Index

    please try it, if this does not work, we have to take a closer look on that problem...

  3. #3
    Join Date
    17.12.2007
    Posts
    35

    Default Re: Delete structured tag

    Robert
    I'll let you know
    THANK

  4. #4
    Join Date
    17.12.2007
    Posts
    35

    Default Re: Delete structured tag

    Robert
    I test your suggestion but the problem is the same

  5. #5
    robertf Gast

    Default Re: Delete structured tag

    Hi fabios!

    I have done some testing with the sample below, and it works...
    Sub DeleteAllVars()
    Dim zVAR As Variable
    Dim i As Integer
    Dim Name As String
      
      For i = MyWorkspace.ActiveDocument.Variables.Count - 1 To 0 Step -1
        Set zVAR = MyWorkspace.ActiveDocument.Variables.Item(i)
        Name = zVAR.Name
        If MyWorkspace.ActiveDocument.Variables.DeleteVar(Name) = False Then
            Debug.Print "Variable: " & Name & " error while deleting"
        Else
            Debug.Print "Variable: " & Name & " deleted"
        End If
      Next i
    End Sub

    What error Message do you get?
    Do you have a multiuser project?

  6. #6
    Join Date
    17.12.2007
    Posts
    35

    Default Re: Delete structured tag

    Robert
    My project is not multiuser
    I'm using V6.21 SP1 build0
    Did you test that code with structured tag?
    In my case tag that I want delete has a lot of subitem.
    Looping back, and deleting a tag with 10 subitem, in the cycle after delete Index is not correct.
    How I explain you yesterday, I try to modify Index (subtracting subitem number) after delete.
    I try too to deactivate all subitem and then delete a tag.
    Everytime something is wrong.
    If Index is not updated error code is (Object variable or with block variavle not set), normal for me.
    If I try to modify Index, code could looping for minutes.

  7. #7
    robertf Gast

    Default Re: Delete structured tag

    Hi fabios!

    I have created a procedure and a function from your code, maybe this works better.
    I was not able to test it, because of the project, so please try it...

    Now it runs through all variables and checks the DataTypeID for a specific Name...
    After the ID check the Name will be checked and if all criterias match,the variable will be deleted...

    Dim zPRJ As Project
    
    Sub DeleteVariables()
    Dim nIndex As Integer
    Dim nID As Integer
    Dim sName As String
    Dim zVAR As Variable
    
        Set zPRJ = MyWorkspace.ActiveDocument
    
        For nIndex = zPRJ.Variables.Count - 1 To 0 Step -1
            Set zVAR = zPRJ.Variables.Item(nIndex)
            sName = zVAR.Name
            nID = zVAR.DynProperties("ID_DataTyp")
     
            '!!!release the variable object!!!
            Set zVAR = Nothing
            '---------------------------------
            
            If IsVarTypeID(nID) Then
                If sName <> "ICON2K" And _
                sName <> "ICON2Ki" And _
                sName <> "ICON2Km" And _
                sName <> "ICON2K.WriteTrigger" And _
                sName <> "NET" And _
                sName <> "NETi" And _
                sName <> "ROUTERA" And _
                sName <> "ROUTERAi" And _
                sName <> "ROUTERB" And _
                sName <> "ROUTERBi" And _
                sName <> "LOOPi" And _
                sName <> "LOOPm" Then
                    If zPRJ.Variables.DeleteVar(sName) = False Then
                        Debug.Print "Variable: " & nIndex & " " & sName & " error while deleting"
                    Else
                        Debug.Print "Variable: " & nIndex & " " & sName & " deleted"
                    End If
                End If
            End If
        Next nIndex
    End Sub
    
    Function IsVarTypeID(nID As Integer) As Boolean
    Dim nIndex As Integer
    Dim sName As String
    
        For nIndex = 0 To zPRJ.VarTypes.Count - 1
            sName = zPRJ.VarTypes.Item(nIndex).Name
            If Right(sName, 13) = ".InternalData" Or _
            Right(sName, 9) = ".MathData" Or _
            Right(sName, 9) = ".NodeData" Or _
            Right(sName, 13) = ".WriteTrigger" Then
                If nID = CInt(zPRJ.VarTypes.Item(nIndex).ID) Then
                  IsVarTypeID = True
                  Exit Function
                End If
            End If
        Next nIndex
    End Function
    Last edited by robertf : 24th July 2008 at 07:30

  8. #8
    Join Date
    17.12.2007
    Posts
    35

    Default Re: Delete structured tag

    Hi Robert
    I test your code but I have the same problem.
    Your is better than mine but the philosophy is the same.
    After delete the first variable (if this is structured variable), Index is not correct and VBA return an error of "" Object variable or With block variable not set.

  9. #9
    robertf Gast

    Default Re: Delete structured tag

    Hi fabios!

    I tried several times to reproduce your problem, but it always works...

    Do you always use the same zenon project?
    If YES, please try to use a new zenon project with the same variables (structures)

    When it works with a new (other) project, the problem may come from the project itself...

    In this case you can give a backup of your zenon project and the VBA-Wizard to the Support-Team, that they are able to reproduce the problem.

    In this case send a Mail with the problem to Support@copadata.com and attach your project and the VBA Code...

    I'm sorry, but I don't have any more ideas why it may not work...

Similar Threads

  1. Delete item in a combobox
    By fabios in forum VBA
    Replies: 2
    Last Post: 11th July 2008, 10:43

Posting Rules

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