Components property (WinStudio scripts)

Applies To

IWSForm interface

Definition

Returns a Visual Basic object that references the components on a specified form.

Syntax

varObject = object.Components

OR

varObject = object.Components( "string" )

  Part   Description
varObject Required. A Visual Basic variable that is defined as an object and that references the components on this form object.
object Required. A reference to a valid form object.
string Optional. The name of a component.

Remarks

Use this property to manipulate a form's components by name.

Object references are assigned with the Visual Basic Set instruction.

Example 1

This script was written to run with the Language IDs form.

Sub Main()
    ' Display a series of message boxes that present various information
    ' about the collection and the selected record. 
    Dim oCache As IWSIDOCollection
    Dim oComponent As IWSFormComponent
    Dim oAllComponents As System.Collections.Generic.IDictionary(Of _
       String, Mongoose.Scripting.IWSFormComponent)
    Dim iCurrentRow As Integer
    Dim strFieldValue As String
    ' Set a VB variable to a grid's cache
    oCache = ThisForm.Components("FormCollectionGrid").IDOCollection
    Application.ShowMessage("Number of rows = " & CStr(oCache.GetNumEntries() - 1) _
        & vbLf & "Current row = " & CStr(oCache.GetCurrentObjectIndex() + 1))
    ' Display value of the OutputFormatDescGridCol component in a message box
    Application.ShowMessage("The name of the table for the selected row is """ & _
        ThisForm.Components("StringTableNameGridCol").Text & """.")
    ' Set a VB variable to a particular component
    oComponent = ThisForm.Components("LanguageDescGridCol")
    Application.ShowMessage("The description for row " & _
        CStr(oCache.GetCurrentObjectIndex() + 1) & " is """ & oComponent.Text & """.")
    ' Set a VB variable to the collection of all of a Form's components
    oAllComponents = ThisForm.Components
    iCurrentRow = CInt(oAllComponents("FormCollectionGrid").IDOCollection. _
        GetCurrentObjectIndex() + 1)
    strFieldValue = oAllComponents("LanguageIDGridCol").Text
    Application.ShowMessage("The Language ID for row " & CStr(iCurrentRow) & _
        " is """ & strFieldValue & """.")
End Sub

Example 2

This script runs validators on a component. It takes one input parameter, the name of a form component.

Sub Main()
   On Error GoTo ErrorHandler
   If ThisForm.Components(GetParameter(0)).ValidateData(True) Then
      ReturnValue = "0"
   Else
      ReturnValue = "1"
   End If
Exit Sub
ErrorHandler:
   Application.ShowMessage("RunValidatorsOnComponent: " & Err.Description)
   ReturnValue = "1"
End Sub