Difference between revisions of "Repository.Variable.AddVariable"

From ReliaWiki
Jump to navigation Jump to search
m (Protected "Repository.AddVariable" ([edit=sysop] (indefinite) [move=sysop] (indefinite)) [cascading])
 
(19 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Template:APIClass|Repository Class|Repository}}
+
{{Template:API}}{{Template:APIBreadcrumb|.[[Repository Class|Repository]]}}
Saves a new Variable
 
== Method Syntax==
 
{{APIName|'''AddVariable'''(}}
 
{{APIPrefix|ByVal}}
 
{{APIName|var}}
 
{{APIPrefix|As}}
 
{{APIName|[[cVariable Class|cVariable]])}}
 
{{APIPrefix|As Boolean}}<br>
 
{{APIComment|Saves a new Variable in the repository.}}
 
  
== Usage Example ==
 
{{APIComment|Declare a new repository connection class.}}
 
        Private WithEvents MyRepository As New Repository
 
  
{{APIComment|Connect to the Synthesis repository.}}
+
<onlyinclude>Adds a new variable resource to the current project. Returns a '''Boolean''' value; when true, indicates a successful save.</onlyinclude> 
        Dim Success As Boolean = False
 
        Success = MyRepository.ConnectToRepository("RepositoryFileNamePath")
 
  
{{APIComment|Declare a new cVariable.}}
 
        Dim newVariable As New cVariable("NewVariable1")
 
  
{{APIComment|Add the new variable to the repository.}}
+
'''Remarks''': If a variable with the same name already exists in the project, the name will be incremented automatically. For example, if "Var1" already exists, the new variable might be renamed to "Var2," "Var3," etc.
        Dim SuccessAddVariable As Boolean
+
 
        SuccessAddVariable = MyRepository.AddVariable(newVariable)
+
== Syntax ==
 +
'''.Variable.AddVariable'''(''var'')
 +
 
 +
=== Parameters ===
 +
''var''
 +
:Required. The [[CVariable Class|cVariable]] object that represents the variable resource to be added.
 +
 
 +
 
 +
== Example ==
 +
This example creates a new variable resource, and then saves it in the first available project in a Synthesis repository.
 +
'''VBA'''
 +
 +
{{APIComment|'Declare a new Repository object and connect to a Synthesis repository.}}
 +
  {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
 +
  MyRepository.ConnectToAccessRepository({{APIString|"C:\RSRepository1.rsr10"}})
 +
 +
  {{APIComment|'Create a new variable. The following example creates a variable named "MyNewVariable."}}
 +
  {{APIPrefix|Dim}} newVariable {{APIPrefix|As New}} cVariable
 +
  NewVariable.Name = {{APIString|"MyNewVariable"}}
 +
 +
{{APIComment|'Add the new variable to project #1.}}
 +
  MyRepository.Project.SetCurrentProject(1) 
 +
  {{APIPrefix|Call}} MyRepository.Variable.AddVariable(NewVariable)
 +
 
 +
'''VB.NET'''
 +
 +
{{APIComment|'Declare a new Repository object and connect to a Synthesis repository.}}
 +
  {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
 +
  MyRepository.ConnectToAccessRepository({{APIString|"C:\RSRepository1.rsr10"}})
 +
 
 +
{{APIComment|'Create a new variable. The following example creates a variable named "MyNewVariable."}}
 +
  {{APIPrefix|Dim}} newVariable {{APIPrefix|As New}} cVariable ({{APIString|"MyNewVariable"}})
 +
 +
{{APIComment|'Add the new variable to project #1.}}
 +
  MyRepository.Project.SetCurrentProject(1) 
 +
  MyRepository.Variable.AddVariable(newVariable)

Latest revision as of 20:37, 18 August 2016

APIWiki.png


Member of: SynthesisAPI.Repository


Adds a new variable resource to the current project. Returns a Boolean value; when true, indicates a successful save.


Remarks: If a variable with the same name already exists in the project, the name will be incremented automatically. For example, if "Var1" already exists, the new variable might be renamed to "Var2," "Var3," etc.

Syntax

.Variable.AddVariable(var)

Parameters

var

Required. The cVariable object that represents the variable resource to be added.


Example

This example creates a new variable resource, and then saves it in the first available project in a Synthesis repository.

VBA

 'Declare a new Repository object and connect to a Synthesis repository. 
  Dim MyRepository As New Repository
  MyRepository.ConnectToAccessRepository("C:\RSRepository1.rsr10")

  'Create a new variable. The following example creates a variable named "MyNewVariable." 
  Dim newVariable As New cVariable
  NewVariable.Name = "MyNewVariable"

 'Add the new variable to project #1. 
  MyRepository.Project.SetCurrentProject(1)   
  Call MyRepository.Variable.AddVariable(NewVariable)
VB.NET

 'Declare a new Repository object and connect to a Synthesis repository. 
  Dim MyRepository As New Repository
  MyRepository.ConnectToAccessRepository("C:\RSRepository1.rsr10")
 
 'Create a new variable. The following example creates a variable named "MyNewVariable." 
  Dim newVariable As New cVariable ("MyNewVariable")

 'Add the new variable to project #1. 
  MyRepository.Project.SetCurrentProject(1)   
  MyRepository.Variable.AddVariable(newVariable)