Forum Discussion

Anagramma's avatar
14 years ago

How to determine the availability of Log in UserForm with ScriptExtensions

Hi!

Sorry for my English.

I have a function in my scriptextensions and they work.



There is a UserForm in scriptextensions.

The script is checked, for example, the existence of an object and recording errors in the log.

Activated form from panel causes an error: Wrong number of arguments or invalid property assignment: 'Log'



How do I check whether I can write anything in the log?



if aqObject.IsSupported (Log, "Error") then

or

if IsObject (Log) then

give tighter error Wrong number of arguments or invalid property assignment​​: 'Log'

Help!

1 Reply

  • Hi Anagramma,



    Testing the availability of the Log object from VBScript is nontrivial, because it has the same name as VBScript's built-in Log function. So, the Log identifier is always defined in VBScript; it just has another meaning depending on the context.



    The code you posted shows an error, because when TestComplete's Log object is unavailable, Log is treated as a function call and, therefore, requires parameters, e.g: Log(100).



    To avoid the error, you can use the following code instead to perform the check:

    Function IsLogObjectAvailable

      On Error Resume Next

      Dim i : i = Log(100)

      If Err.Number <> 0 Then

        IsLogObjectAvailable = True

        Err.Clear

      Else

        IsLogObjectAvailable = False

      End If

    End Function


    When the Log object is unavailable, you can display error messages using the aqDlg object methods such as aqDlg.ShowError. For example:

    If IsLogObjectAvailable Then

      Log.Error "error"

    Else

      aqDlg.ShowError "error"

    End If


    Hope this helps!