IQdvEnvironment.UserData Property

Gets a collection of additional user-defined data for the current QDV session.
ReadOnly Property UserData() As IDictionary(Of String, Object)
This language is not supported or no code example is available.
IDictionary<string, object> UserData {get;}
This language is not supported or no code example is available.

Property Value

IDictionary<string, object>

A collection of user-defined key/value pairs. The default is an empty collection.

Remarks
 

This is a shared global data storage that is accessible from any user code, such as macros or external clients. This data is not persisted, it's only valid during the current application lifetime.

The main purpose is to share data among macros. For example, you can pass data from a macro called in one event to a macro called in another event.

If you need to scope your data to a specific estimate, create a unique key for it, e.g. use the estimate full path in it.

This property is useful if you need to pass some data between two unrelated macro calls. In such a case, you cannot use ICommonCallingContext.UserDefinedObject, which can be applied only if the macro that receives the data is called from a sending macro with IEstimate.RunQdvMacro.

Example
 

Counting macro calls

The following macro code will display how many times it was called in the current application session.

' The user data keys, one for this estimate and one global.
 Dim thisEstimateCallCounterKey As String = Es.FullPath & "_" & "MyMacroCallCounter"
 Dim anyEstimateCallCounterKey As String = "MyMacroCallCounter"
 ' Get stored data, if any.
 Dim thisEstimateCallCounter As Integer = 1
 If Context.QdvManager.Environment.UserData.ContainsKey(thisEstimateCallCounterKey) Then
  thisEstimateCallCounter = CType(Context.QdvManager.Environment.UserData.Item(thisEstimateCallCounterKey), Integer)
  thisEstimateCallCounter += 1
 End If
 Dim anyEstimateCallCounter As Integer = 1
 If Context.QdvManager.Environment.UserData.ContainsKey(anyEstimateCallCounterKey) Then
  anyEstimateCallCounter = CType(Context.QdvManager.Environment.UserData.Item(anyEstimateCallCounterKey), Integer)
  anyEstimateCallCounter += 1
 End If
 Dim msg As String = "This macro was called" & vbCrLf
 msg &= thisEstimateCallCounter.ToString() & " times from this estimate" & vbCrLf
 msg &= anyEstimateCallCounter.ToString() & " times from any estimate"
 MessageBox.Show(msg)
 ' Store the data.
 Context.QdvManager.Environment.UserData.Item(thisEstimateCallCounterKey) = thisEstimateCallCounter
 Context.QdvManager.Environment.UserData.Item(anyEstimateCallCounterKey) = anyEstimateCallCounter					
This language is not supported or no code example is available.

Passing data between two events

Let's say you want to send some data from Before_Drag_Set event to After_Drop_Set event in a database of sets. Create two macros. One named SetUserData that you will call in the Before_Drag_Set event. The second one will be named GetUserData that you will call in the After_Drop_Set event.

SetUserData:

Dim dataKey As String = setDB.FullPathToDatabase & "_" & "MyData"
 Context.QdvManager.Environment.UserData.Item(dataKey) = "Hello World!"					
This language is not supported or no code example is available.

GetUserData:

Dim dataKey As String = setDB.FullPathToDatabase & "_" & "MyData"
 Dim data As String = Context.QdvManager.Environment.UserData.Item(dataKey)
 MessageBox.Show(data)					
This language is not supported or no code example is available.
Version
 
Available since QDV 7.18.678.

.NET Framework

Supported in: 4.8, 4.7, 4.6, 4.5.2

In this article

Definition