Attribute VB_Name = "ex_Metadata"
'================ Модуль для работы с данными документа =============
' Shared module version: 20210506
' Depends on:
' Required reference: Scripting
Option Private Module
Option Explicit

Public Function MetadataExists(iDoc As Object, varName$) As Boolean
  Dim aVar As Variant
  For Each aVar In iDoc.Variables
    If aVar.Name = varName Then
      MetadataExists = True
      Exit Function
    End If
  Next aVar
  MetadataExists = False
End Function

Public Function GetMetadata(iDoc As Object, varName$) As Variant
  Dim aVar As Variant
  For Each aVar In iDoc.Variables
    If aVar.Name = varName Then
      GetMetadata = aVar.Value
      Exit Function
    End If
  Next aVar
  GetMetadata = ""
End Function

Public Function SetMetadata(iDoc As Object, varName$, val As Variant)
  Dim aVar As Variant
  For Each aVar In iDoc.Variables
    If aVar.Name = varName Then
      aVar.Value = val
      Exit Function
    End If
  Next aVar
  Call iDoc.Variables.Add(varName, val)
End Function
