Scripts where the main action is executed elsewhere

Build 1501 on 14/Nov/2017  This topic last edited on: 25/Aug/2014, at 11:42

Scripts where the main action is executed elsewhere are a particular case of scripts, a bit more difficult to understand.

An example is NewFredArticle, whose main action is not executed within its body, but elsewhere - in the FredUtils.CreateNewFredArticle(sPredefName).

Such approach is often the only way to avoid duplication of code. If more script execute very similar actions, you define the action, generalized as needed, elsewhere, and then make your scripts call that action.

In this example, NewFredArticle calls FredUtils.CreateNewFredArticle, and that's where the main action takes place.

Moreover, NewFredArticle calls also FredUtils.SelectAndLinkArticle. That's another main action, executed elsewhere.

Public Sub NewFredArticle()

  Dim sPredefName As String = Nothing

  Using New WinUI.Controls.BusyCursor

    If SystemUserOptions.T_AutoName Then

      Dim lgEdDate As Integer = 4

       <snip>

    End If

  End Using

  Dim articleId As Integer = FredUtils.CreateNewFredArticle(sPredefName)

  If articleId <> Common.DBDesc.InvalidId Then

    FredUtils.SelectAndLinkArticle(articleId)

  End If

End Sub

To understand the main action, you have to locate its code. Instructions are in Locating called script code.