Creating an Invisible Object

In the preceding section, Visual Basic was used to access and program a form-based interface for the Hello sample. The Hello Application object was started as invisible, and was later displayed when its Visible property was set to True. Some objects are not visible, and some objects are never displayed to the user.

For example, a word-processing application may expose its spelling checker engine as an object. This object might support a method called CheckWord that takes a string as an argument. If the string is spelled correctly, the method returns True; otherwise, the method returns False. If the string is spelled incorrectly, it could be passed to another (hypothetical) method called SuggestWord that returns a suggestion for its correct spelling. The code might look something like this.

Sub CheckSpelling ()
    Dim ObjVar As New SpellChecker
    Dim MyWord, Result

    MyWord = "potatoe"

    ' Check the spelling.
    Result = ObjVar.CheckWord MyWord
    ' If False, get suggestion.
    If Not Result Then
        MyWord = ObjVar.SuggestWord MyWord
    End If
End Sub

In this example, the spelling checker is never displayed to the user. Its capabilities are exposed through the properties and methods of the spelling checker object.

As shown in the example, invisible objects can be created and referenced in the same way as any other type of object.