home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD14417222001.psc / modWebsiteTools.bas < prev    next >
Encoding:
BASIC Source File  |  2001-01-19  |  4.0 KB  |  113 lines

  1. Attribute VB_Name = "modWebsiteTools"
  2. Option Explicit
  3.  
  4. '
  5. ' Website Tools Module (modWebsiteTools.bas)
  6. '
  7. ' Part of the Amazon Book Searcher Project.
  8. ' --------------------------------------------
  9. '
  10. ' Purpose: Holds the Subs and Functions which are used as
  11. ' "Tools" in handling website activities (Such as loading url's,
  12. ' encoding url's and such).
  13. '
  14.  
  15.  
  16. '
  17. ' Public Cosntants.
  18. '
  19.  
  20. ' Results Per Page of a Book Results Page.
  21. Public Const RESULTS_PER_PAGE As Integer = 25
  22. ' Various Constants related to the Search URL.
  23. Public Const AMAZON_URL As String = "http://www.amazon.com"
  24. Public Const SEARCH_URL_PREFIX As String = "/exec/obidos/search-handle-url/ix=books&rank=%2Bamzrank&fqp="
  25. Public Const SEARCH_URL_SUFFIX As String = "&sz=25&pg=<Page Number>/ref=s_b_np/002-0029107-7786404"
  26. Public Const BOOK_PAGE_URL As String = "http://www.amazon.com/exec/obidos/ASIN/<ISBN>/qid=979490648/sr=2-1/ref=sc_b_1/002-0029107-7786404"
  27.  
  28. Public Const SW_SHOW = 5
  29. Public Const SYNCHRONIZE = &H100000
  30. Public Const INFINITE = -1&
  31.  
  32.  
  33. '
  34. ' API Declarations
  35. '
  36.  
  37. Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  38. Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
  39. Public Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
  40. Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  41.  
  42. Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
  43. Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
  44. Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
  45.  
  46.  
  47. '
  48. ' Public Variables.
  49. '
  50.  
  51.  
  52. ' An Array of the Books found by the book search.
  53. Public gclsBooks() As clsBook
  54. ' The Number of Matches found.
  55. Public glngResultsCount As Long
  56. ' The Current Results Page and Book Page being downloaded.
  57. Public gintCurrentPage As Long, glngCurrentBook As Integer
  58. ' The Number of Results Pages.
  59. Public gintResultPageCount As Integer
  60. ' A Global flag variable used for stopping the search.
  61. Public gblnStopSearch As Boolean
  62.  
  63.  
  64. '
  65. ' Public Subs.
  66. '
  67.  
  68.  
  69. '
  70. ' Opens a URL in the default web browser.
  71. '
  72. Public Sub OpenURL(ParentHwnd As Long, ByVal URL As String)
  73.     'Call ShellExecute(0&, vbNullString, URL, vbNullString, vbNullString, SW_SHOW)
  74.     ShellExecute ParentHwnd, "open", URL, vbNullString, vbNullString, SW_SHOW
  75. End Sub
  76.  
  77. '
  78. ' Parses an Amazon Book Search Results Page, and
  79. ' retrieves the info of the books found.
  80. ' These Books (and their info's) are saved in a
  81. ' global variable array.
  82. '
  83. Public Sub ParseResultPage(ByVal HTML As String)
  84. ' A List Item used when adding a book entry to
  85. ' the Book Results ListView.
  86. Dim itmBook As ListItem
  87. ' The Tag Tokenizer used for parsing the search results page.
  88. Dim clsTT As clsTagTokenizer
  89. ' Holds the number of the current resulting book
  90. ' and the number of first book of the result page.
  91. Dim intCurrentBook As Integer, intStartBook As Integer
  92. ' Counter Variables.
  93. Dim i As Integer, c As Integer
  94. ' Temp Variable used for parsing.
  95. Dim s1 As String, s2() As String
  96. ' A Flag Variable used for telling if a book has
  97. ' already been found by the search.
  98. Dim blnDuplicateBook As Boolean
  99.  
  100.     On Error GoTo ErrHandler
  101.     
  102.     ' See if we found any matches before even
  103.     ' starting to parse the HTML code.
  104.     i = InStr(1, HTMLnlString
  105. ' A Flag Variable used for telling if a book has
  106. ' already been found by the search.
  107. Dim blnDuplicateBook As Boolean
  108.  
  109.     On Error GoTo ErrHandler
  110.     
  111.     ' See if we found any matches before even
  112.     ' starting to parse the HTML code.
  113.     i,/