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.




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 ...


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




Simple example to see if the filtered page content has been changed.

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


   ' Apply the defined filter definitions

   sMemWeb = Bookmark_ApplyFilter(Handle, sMemWeb)

   sMemLocal = Bookmark_ApplyFilter(Handle, sMemLocal)


   ' Check if the page has been changed by comparing the filtered content

   If sMemWeb <> sMemLocal Then

      iStatusCode = 1 ' updates detected


      iStatusCode = 0 ' no updates available

   End If


End Sub


More advanced example to detect price changes and alert if a price is lower than a pre-defined value. This price extraction is dependent from the page, you can use the code below as a starting point.

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"


      iStatusCode = 0

      sStatusMessage = "Price unchanged"

   End If

End Sub