Skip to main content
Jan 20, 2023 3:02 PM UTC
Solved

Dictonary variable

I want to update the parameter of my dictonary . How can i achieve it? .add adds the value in the dictonary. Is there any update function to update the value of that key in dictonary

Dim params2 As New Dictionary(Of String, String)
params2.Add("Entity_param_db","E001" )

For Each MemberOfList As MemberInfo In Nonstreamproduct
             params2.Add("Entity_param_db",MemberOfList.Member.Name)
             BRApi.Utilities.StartDataMgmtSequence(si,dataMgmtSeq2, params2)
Next

Employee - Sage
Jan 20, 2023 4:26 PM UTC

Two ways:

' Explicit
myDict.Item("myKey") = newValue
' Shortcut
myDict("myKey") = newValue

For more help, have a look at https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2?view=netframework-4.7.2.

4 replies

Employee - Sage
Jan 20, 2023 4:26 PM UTC

Two ways:

' Explicit
myDict.Item("myKey") = newValue
' Shortcut
myDict("myKey") = newValue

For more help, have a look at https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2?view=netframework-4.7.2.

OS_PizzaAuthor
Jan 23, 2023 9:50 AM UTC

Thanks for this. I eneded up using removing the key value before iterating next loop and then adding it back.

 

Member
Jan 27, 2023 9:55 PM UTC

Hi, to handle duplicated or non-existing keys, I would suggest you to use a couple of nifty extended dictionary methods available in OneStream: XFGetValue and XFSetValue.

Dim params As New Dictionary(Of String, String)
params.XFSetValue("sameKey", "A")
params.XFSetValue("sameKey", "AB")
Dim sValue As String = params.XFGetValue("noKey", "defaultValue")