Sample scripts with APIs for strong data types

This topic presents two sample scripts that use API strong data types. The first is a sample form script. The second is a sample global script.

Sample form script

Public Sub TestDatesNumbersScriptAPIs()
 Application.ShowMessage("TestDatesNumbersScriptAPIs()")
 Dim PropertyName As String = "MyProperty"
 Dim MyInt As Integer = 555
 Dim MyString As String = "123"
 Dim MyBoolean As Boolean = True
 Dim MyDecimal As Decimal = 555
 Dim MyLong As Long = 555
 Dim MyDate As Date = Date.Today
 Dim MyColl As IWSIDOCollection = ThisForm.PrimaryIDOCollection
 MyColl.First()
 If Not MyColl.IsEOF Then
 Application.ShowMessage("Testing row-independent Property APIs...")
 For MyPropNumber As Integer = 0 To MyColl.GetNumProperties - 1
 PropertyName = MyColl.GetPropertyName(MyPropNumber)
 'If PropertyName = String.Empty Then Exit For
 'Application.ShowMessage(String.Format("Working on Property: {0}", PropertyName))
 Dim MyProp As IWSIDOProperty = MyColl.Items(0).Properties(PropertyName)
 If MyProp.GetDefault <> MyColl.GetPropertyDefault(PropertyName) Then _
 MsgBox(String.Format("Problem with GetDefault of {0}", PropertyName))
 If MyProp.GetLabel(False) <> MyColl.GetLabelForProperty(PropertyName, False) Then _
 MsgBox(String.Format("Problem with GetLabel of {0}", PropertyName))
 If MyProp.GetLength <> MyColl.GetPropertyLength(PropertyName) Then _
 MsgBox(String.Format("Problem with GetLength of {0}", PropertyName))
 If MyProp.IsIdentity <> MyColl.IsPropertyIdentity(PropertyName) Then _
 MsgBox(String.Format("Problem with IsIdentity of {0}", PropertyName))
 If MyProp.IsKey <> MyColl.IsPropertyKey(PropertyName) Then _
 MsgBox(String.Format("Problem with IsKey of {0}", PropertyName))
 If MyProp.IsLinkBy <> MyColl.IsPropertyLinkBy(PropertyName) Then _
 MsgBox(String.Format("Problem with IsLinkBy of {0}", PropertyName))
 If MyProp.IsNullable <> MyColl.IsPropertyNullable(PropertyName) Then _
 MsgBox(String.Format("Problem with IsNullable of {0}", PropertyName))
 If MyProp.IsNumeric <> MyColl.IsPropertyNumeric(PropertyName) Then _
 MsgBox(String.Format("Problem with IsNumeric of {0}", PropertyName))
 If MyProp.IsNumSortedChar <> MyColl.IsPropertyNumSortedChar(PropertyName) Then _
 MsgBox(String.Format("Problem with IsNumSortedChar of {0}", PropertyName))
 If MyProp.IsProtected <> MyColl.IsPropertyProtected(PropertyName) Then _
 MsgBox(String.Format("Problem with IsProtected of {0}", PropertyName))
 If MyProp.IsQuotable <> MyColl.IsPropertyQuotable(PropertyName) Then _
 MsgBox(String.Format("Problem with IsQuotable of {0}", PropertyName))
 If MyProp.IsReadOnly <> MyColl.IsPropertyReadOnly(PropertyName) Then _
 MsgBox(String.Format("Problem with IsReadOnly of {0}", PropertyName))
 If MyProp.IsRequired <> MyColl.IsPropertyRequired(PropertyName) Then _
 MsgBox(String.Format("Problem with IsRequired of {0}", PropertyName))
 If MyProp.IsUppercase <> MyColl.IsPropertyUppercase(PropertyName) Then _
 MsgBox(String.Format("Problem with IsUppercase of {0}", PropertyName))
 If MyProp.IsBoundByComponent(False) <> MyColl.IsPropertyBoundByComponent(PropertyName, False) Then _
 MsgBox(String.Format("Problem with IsBoundByComponent of {0}", PropertyName))
 MyPropNumber = MyPropNumber + 1
 Next
 Application.ShowMessage("Testing row-dependent Property APIs...")
 For Row As Integer = 0 To MyColl.GetNumEntries - 1
 For MyPropNumber As Integer = 0 To MyColl.GetNumProperties - 1
 PropertyName = MyColl.GetPropertyName(MyPropNumber)
 If Not PropertyName.StartsWith("_") Then
 Dim MyProp As IWSIDOProperty = MyColl(Row)(PropertyName)
 If MyProp.GetBinaryLength <> MyColl.GetObjectPropertyBinaryLength(PropertyName, Row) Then _
 MsgBox(String.Format("Problem with GetBinaryLength of {0} in Row {1}", PropertyName, Row))
 If MyProp.Modified <> MyColl.IsObjectPropertyModified(PropertyName, Row) Then _
 MsgBox(String.Format("Problem with Modified of {0} in Row {1}", PropertyName, Row))
 If MyProp.Value <> MyColl.GetObjectPropertyInternal(PropertyName, Row) Then _
 MsgBox(String.Format("Problem with Value of {0} in Row {1}", PropertyName, Row))
 ThisForm.PrimaryIDOCollection(Row)(PropertyName).Modified = MyBoolean
 Try
 MyDecimal = ThisForm.PrimaryIDOCollection(0)(PropertyName).GetValue(Of Decimal)()
 Catch ex As System.Exception
 MsgBox(String.Format("Failed GetValue for {0} [{1}]", PropertyName, MyProp.Value))
 End Try
 Try
 MyLong = MyProp.GetValueOfLong(MyLong)
 Catch ex As System.Exception
 If ex.Message <> "Object reference not set to an instance of an object." Then
 MsgBox(String.Format("Caught Exception during GetValueOfLong(555): {0}", ex.Message))
 End If
 End Try
 Try
 Dim MyNullableInt As Nullable(Of Integer)
 MyNullableInt = ThisForm.PrimaryIDOCollection(0)(PropertyName).GetNullableValue(Of Integer)()
 Catch ex As System.Exception
 MsgBox(String.Format("Failed GetNullableValue for {0} [{1}]", PropertyName, MyProp.Value))
 End Try
 'Exit For
 ThisForm.PrimaryIDOCollection(Row)(PropertyName).SetValue(MyLong)
 ThisForm.PrimaryIDOCollection(Row)(PropertyName).SetValue(MyDate)
 ThisForm.PrimaryIDOCollection(Row)(PropertyName).SetValuePlusModifyRefresh(MyDecimal)
 ThisForm.PrimaryIDOCollection(Row)(PropertyName).SetValuePlusModifyRefreshInternal(MyInt)
 ThisForm.PrimaryIDOCollection(Row)(PropertyName).Value = MyString
 End If
 Next
 Next
 MyColl.Last()
 MyColl.CurrentItem(PropertyName).Value = String.Empty
 If MyColl.CurrentItem(PropertyName).IsNull Then
 MyColl.CurrentItem(PropertyName).SetValue(MyDate)
 Try
 Dim MyDate2 As Date
 MyDate2 = ThisForm.PrimaryIDOCollection(0)(PropertyName).GetValue(Of Date)()
 If MyDate2 <> MyDate Then _
 MsgBox(String.Format("GetValue resulted in {0} after SetValue({1})", MyDate2, MyDate))
 Catch ex As System.Exception
 MsgBox(String.Format("Failed GetValue for {0} [{1}]", PropertyName, ThisForm.PrimaryIDOCollection(0)(PropertyName).Value))
 End Try
 End If
 MyColl.RefreshCurrentObject()
 Else
 Application.ShowMessage("Unable to test new Property APIs because primary collection is empty!")
 End If
 Application.ShowMessage("Testing new Variable APIs...")
 Dim GoodVar As String = "InitialCommand"
 Dim BadVar As String = "NoSuchVariable!"
 Dim NewVar As String = "NewVariable"
 MyString = ThisForm.Variables(GoodVar).Value
 ThisForm.Variables(NewVar).SetValue(MyDate)
 Try
 Dim MyDate2 As Date
 MyDate2 = ThisForm.Variables(NewVar).GetValue(Of Date)()
 If MyDate2 <> MyDate Then _
 MsgBox(String.Format("GetValue resulted in {0} after SetValue({1})", MyDate2, MyDate))
 Catch ex As System.Exception
 MsgBox(String.Format("Failed GetValue for {0} [{1}]", NewVar, ThisForm.Variables(NewVar).Value))
 End Try
 If ThisForm.Variables(BadVar).IsNull() Then
 MsgBox(String.Format("We know that {0} is Null, so we will not try GetValue()", BadVar))
 Dim MyNullableLong As Nullable(Of Long) = ThisForm.Variables(BadVar).GetNullableValue(Of Long)()
 Else
 Try
 MyDecimal = ThisForm.Variables(BadVar).GetValue(Of Decimal)()
 Catch ex As System.Exception
 MsgBox(String.Format("Failed GetValue for {0} [{1}]", BadVar, ThisForm.Variables(BadVar).Value))
 End Try
 End If
 MyString = "123"
 Application.ShowMessage("Testing new Component APIs...")
 For Each CompName As String In ThisForm.Components.Keys
 'Application.ShowMessage(String.Format("Working on Component: {0}", CompName))
 Try
 MyDecimal = ThisForm.Components(CompName).GetValue(Of Decimal)()
 Catch ex As System.Exception
 MsgBox(String.Format("Failed GetValue for {0} [{1}]", CompName, ThisForm.Components(CompName).Value))
 End Try
 Try
 MyDecimal = ThisForm.Components(CompName).GetValueOfDecimal(0)
 Catch ex As System.Exception
 MsgBox(String.Format("Failed GetValueOfDecimal for {0} [{1}]", CompName, ThisForm.Components(CompName).Value))
 End Try
 Try
 Dim MyNullableInt As Nullable(Of Integer)
 MyNullableInt = ThisForm.Components(CompName).GetNullableValue(Of Integer)()
 Catch ex As System.Exception
 MsgBox(String.Format("Failed GetNullableValue for {0} [{1}]", CompName, ThisForm.Components(CompName).Value))
 End Try
 'Exit For
 ThisForm.Components(CompName).SetValue(MyLong)
 ThisForm.Components(CompName).SetValue(MyDate)
 ThisForm.Components(CompName).Value = MyString
 Next
 End Sub

Sample global script

Sub Main()
 Dim MyInt As Integer = 555
 Dim MyString As String = "123"
 Dim MyBoolean As Boolean = True
 Dim MyDecimal As Decimal = 555
 Dim MyLong As Long = 555
 Dim MyDate As Date = Date.Today
 Dim MyString2 As String
 If Not Parameters(0).IsNull Then
 MyString2 = Parameters(0).Value
 End If
 MyDate = Parameters(MyInt).GetValue(Of Date)()
 MyDecimal = Parameters(ParameterCount).GetValueOfDecimal(55)
 MyLong = Parameters(3).GetValue(Of Long)()
 Dim MyNullableInt As Nullable(Of Integer) = Parameters(1).GetNullableValue(Of Integer)()
 For i As Integer = 0 To ParameterCount() - 1
 Dim MyParm As IGlobalScriptParm = Parameters(i)
 If MyParm.IsNull() Then
 MsgBox(String.Format("We know that parameter {0} is Null, so we will not try GetValue()", i))
 Dim MyNullableLong As Nullable(Of Long) = MyParm.GetNullableValue(Of Long)()
 Else
 Try
 MyDecimal = MyParm.GetValue(Of Decimal)()
 Catch ex As System.Exception
 MsgBox(String.Format("Failed GetValue for parameter {0} [{1}]", i, MyParm.Value))
 End Try
 End If
 Try
 MyLong = MyParm.GetValueOfLong(MyLong)
 Catch ex As System.Exception
 If ex.Message <> "Object reference not set to an instance of an object." Then
 MsgBox(String.Format("Caught Exception during GetValueOfLong(555): {0}", ex.Message))
 End If
 End Try
 Try
 Dim MyNullableInt2 As Nullable(Of Integer)
 MyNullableInt2 = MyParm.GetNullableValue(Of Integer)()
 Catch ex As System.Exception
 MsgBox(String.Format("Failed GetNullableValue for parameter {0} [{1}]", i, MyParm.Value))
 End Try
 Next
 End Sub
Related topics