Wsw_CompareVersions

Top  Previous  Next

Sub Wsw_CompareVersions(Handle, ByRef sMemWeb, ByRef sMemLocal, ByRef sStatusMessage, ByRef iStatusCode)

 

This function is called to compare the web version of a page with the locally saved version. You can filter the content and decide when a bookmark should alert an update, for example when a specific price in the web version is lower than in the locally saved version. The parameter iStatusCode is a numeric value and indicates if a page has been changed or if an error has occurred.

 

Parameters

 

Handle ... Bookmark handle.
sMemWeb ... String expression. Page source code of the web version.
sMemLocal ... String expression. Page source code of the locally saved version.
sStatusMessage ... String expression. Status message that will be displayed in the status column. Default value is an empty string.
iStatusCode ... Integer value. Indicates if a page has been changed or if an error has occurred. Default value is 0.

 

Valid values of iStatusCode:

0 ...

OK, page is unchanged.

Default value, must not be assigned manually.

1 ...

OK, page has been changed.

Bookmark will be marked as updated.

2 ...

Error.

If 2 is returned, then the check of that bookmark will be aborted with an error.

 

Example:

Sub ExtractPrice(sMem, ByRef nPrice)

 

 Dim p, nLen

 

   nPrice = -1

   sMem = DeleteHtmlTags(sMem)

   ' Extract price without decimal places

   If FindRegex(sMem, "Price:\s*EUR\s*\d+,", p, nLen) Then

      sMem = ExtractDigits(Copy(sMem, p, nLen))

      nPrice = StrToIntDef(sMem, -1)

   End If

End Sub

 

'*******************************************************************************

 

Sub Wsw_CompareVersions(Handle, ByRef sMemWeb, ByRef sMemLocal, ByRef sStatusMessage, ByRef iStatusCode)

 

 Dim nPriceNew , nPriceOld, nPriceRef

 

   ' Define reference price (100 EUR)

   nPriceRef = 100

 

   ' Extract price from new/local version

   ExtractPrice(sMemWeb, nPriceNew)

   ExtractPrice(sMemLocal, nPriceOld) ' only needed to speed up several WSW routines

 

   ' Return only price - speed up several WSW routines, eg. "Test filter" dialog or "Analyze" functionality

   sMemWeb = IntToStr(nPriceNew)

   sMemLocal = IntToStr(nPriceOld)

 

   If nPriceNew = -Then

      iStatusCode = 2

      sStatusMessage = "Error extracting price"

   ElseIf (nPriceNew <> nPriceOld) And (nPriceNew <= nPriceRef) Then

      iStatusCode = 1

      sStatusMessage = "Price changed and lower than EUR " + IntToStr(nPriceNew)

   ElseIf (nPriceNew <> nPriceOld) And (nPriceNew > nPriceRef) Then

      iStatusCode = 0

      sStatusMessage = "Price too high"

   Else

      iStatusCode = 0

      sStatusMessage = "Price unchanged"

   End If

End Sub