Development‎ > ‎VBScript‎ > ‎

Persisting values


'*********************************************************************************
'* Function signature: gen_pushData(sData)
'* Description:
'*                  
'*
'* Parameters
'* sData - Coma-separated list of the parameters to be exported to the environment
'*         variable which is defined in the constant PARAMETERS_ENV
'*
'*
'* Return Value
'* True or False depending on whether it was successful or not
'*********************************************************************************
Function gen_pushData(sData)
      'Create some objects
      Dim oShell : Set oShell = CreateObject("WScript.Shell")
      Dim oEnvVars : Set oEnvVars = oShell.Environment("USER")

      if (sData <> "") then
            oEnvVars(PARAMETERS_ENV) = sData
            gen_reportEvent micInfo, "Data push", "Data: "& Chr(34) & sData & Chr(34) &" has been exportert to the environment variable."
            gen_pushData = True 'Report that this was successfull
      else
            gen_reportEvent micWarning, "Data push", "There was no data to export to the environment. Parameter passed to the function (gen_pushData) is empty."
            gen_pushData = False ' Report an error
      end if
 
      'Clean up
      Set oShell = Nothing
      Set oEnvVars = Nothing
End Function
 

The above can be reverset with the following code:

'*********************************************************************************
'* Function signature: gen_popData()
'* Description:
'*                  
'*
'* Parameters
'* sData - Coma-separated list of the parameters to be exported to the environment
'*         variable which is defined in the constant PARAMETERS_ENV
'*
'*
'* Return Value
'* Returns an array with the parameters
'*********************************************************************************
Function gen_popData()
      'Create some objects
      Dim oShell : Set oShell = CreateObject("WScript.Shell")
      Dim oEnvVars : Set oEnvVars = oShell.Environment("USER")
      Dim sData 'This variable will keep the data taken from the environment variable
     
      'Get the data from the environment variable
      sData = oEnvVars(PARAMETERS_ENV)
      gen_checkPositive (sData <> ""), "Data pop", "Data: " & Chr(34) & replace(sData,",",", ") & Chr(34) & " has been imported from the environment variable.", True


      'Clean up
      oEnvVars.Remove PARAMETERS_ENV
      Set oShell = Nothing
      Set oEnvVars = Nothing

      gen_popData = split(sData, ",") ' Return an array with the parameters
End Function



Comments