home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 January / dppcpro0199a.iso / January / Fp98 / SDK / Wizards / Vb / Botgen.bas < prev    next >
Encoding:
BASIC Source File  |  1997-09-18  |  10.8 KB  |  449 lines

  1. Attribute VB_Name = "BOTGEN"
  2. ' -------------------------------------------------------------------
  3. ' File: BOTGEN.BAS
  4. ' Copyright (c) 1995 Vermeer Technologies, Inc.  All rights reserved.
  5. ' -------------------------------------------------------------------
  6.  
  7. Option Explicit
  8.  
  9. ' definitions for Vermeer Bots
  10. Const VBOTL_OPEN = "<!--VERMEER BOT="
  11. Const VBOTL_INDENT = "    "
  12. Const VBOTL_CLOSE = "-->"
  13.  
  14. Const DATEBOT_EDIT = "EDITED"
  15. Const DATEBOT_REGEN = "REGENERATED"
  16.  
  17. Sub BotAddParameter(s As String, bvar As String, bval As String)
  18.  
  19.     Dim nl As String
  20.     Dim q As String
  21.  
  22.     nl = Chr$(13) & Chr$(10)
  23.     q = Chr$(34) ' double quote
  24.  
  25.     s = s & VBOTL_INDENT & bvar & "=" & q & bval & q & nl
  26.  
  27. End Sub
  28.  
  29. Function BotCheckImageVal(ImgFile As String) As Integer
  30.  
  31.     ' tell us if ImgFile could reasonably be expected
  32.     ' to hold the name of an image file (GIF or JPEG)
  33.  
  34.     Dim tmp As String
  35.     Dim dloc As Integer
  36.     Dim slen As Integer
  37.  
  38.     If ImgFile = "" Then
  39.         BotCheckImageVal = False
  40.         Exit Function
  41.     End If
  42.  
  43.     tmp = LCase$(ImgFile)
  44.     slen = Len(tmp)
  45.  
  46.     If InStr(tmp, ".gif") = (slen - 3) Then
  47.         BotCheckImageVal = True
  48.         Exit Function
  49.     End If
  50.     If InStr(tmp, ".GIF") = (slen - 3) Then
  51.         BotCheckImageVal = True
  52.         Exit Function
  53.     End If
  54.  
  55.     If InStr(tmp, ".jpg") = (slen - 3) Then
  56.         BotCheckImageVal = True
  57.         Exit Function
  58.     End If
  59.     If InStr(tmp, ".JPG") = (slen - 3) Then
  60.         BotCheckImageVal = True
  61.         Exit Function
  62.     End If
  63.  
  64.     If InStr(tmp, ".jpe") = (slen - 3) Then
  65.         BotCheckImageVal = True
  66.         Exit Function
  67.     End If
  68.     If InStr(tmp, ".JPE") = (slen - 3) Then
  69.         BotCheckImageVal = True
  70.         Exit Function
  71.     End If
  72.  
  73.     If InStr(tmp, ".jpeg") = (slen - 4) Then
  74.         BotCheckImageVal = True
  75.         Exit Function
  76.     End If
  77.     If InStr(tmp, ".JPEG") = (slen - 4) Then
  78.         BotCheckImageVal = True
  79.         Exit Function
  80.     End If
  81.  
  82.     BotCheckImageVal = False
  83.  
  84. End Function
  85.  
  86. Function BotCheckIncludeVal(IncFile As String) As Integer
  87.  
  88.     ' tell us if IncFile could reasonably be expected
  89.     ' to hold the name of an include file (.htm or .html)
  90.  
  91.     Dim tmp As String
  92.     Dim dloc As Integer
  93.     Dim slen As Integer
  94.  
  95.     If IncFile = "" Then
  96.         BotCheckIncludeVal = False
  97.         Exit Function
  98.     End If
  99.  
  100.     tmp = LCase$(IncFile)
  101.     slen = Len(tmp)
  102.  
  103.     If InStr(tmp, ".htm") = (slen - 3) Then
  104.         BotCheckIncludeVal = True
  105.         Exit Function
  106.     End If
  107.     If InStr(tmp, ".HTM") = (slen - 3) Then
  108.         BotCheckIncludeVal = True
  109.         Exit Function
  110.     End If
  111.  
  112.     If InStr(tmp, ".html") = (slen - 4) Then
  113.         BotCheckIncludeVal = True
  114.         Exit Function
  115.     End If
  116.     If InStr(tmp, ".HTML") = (slen - 4) Then
  117.         BotCheckIncludeVal = True
  118.         Exit Function
  119.     End If
  120.  
  121.     BotCheckIncludeVal = False
  122.  
  123. End Function
  124.  
  125. Sub BotClose(s As String)
  126.  
  127.     s = s & VBOTL_CLOSE  ' no terminating newline
  128.  
  129. End Sub
  130.  
  131. Function BotMakeBoolVal(truth As Integer) As String
  132.  
  133.     If truth Then
  134.         BotMakeBoolVal = "True"
  135.     Else
  136.         BotMakeBoolVal = "False"
  137.     End If
  138.  
  139. End Function
  140.  
  141. Function BotMakeDateVal(reqdate As Variant) As String
  142.  
  143.     ' NOTE: create the date parameter using
  144.     ' DateSerial and TimeSerial functions, or
  145.     ' DateValue and TimeValue functions,
  146.     ' and then add them together:
  147.     '
  148.     ' reqdate = DateSerial(10,17,88) + TimeSerial(9,35,0)
  149.     ' reqdate = DateValue("10/17/88") + TimeValue("09:35:00")
  150.     '
  151.  
  152.     Dim dstr As String
  153.     Dim tstr As String
  154.     
  155.     If VarType(reqdate) <> 7 Then
  156.         ' ERROR
  157.         MsgBox "ERROR: BotMakeDateVal given non-date parameter."
  158.         BotMakeDateVal = ""
  159.         Exit Function
  160.     End If
  161.  
  162.     ' TODO: deal with time zone conversion
  163.     BotMakeDateVal = Format$(reqdate, "dd mmm yyyy hh:mm:ss")
  164.  
  165. End Function
  166.  
  167. Function BotMakeIntVal(i As Integer)
  168.  
  169.     BotMakeIntVal = CStr(i)
  170.  
  171. End Function
  172.  
  173. Function BotMakeStrVal(s As String) As String
  174.  
  175.     BotMakeStrVal = HTMLString(s)
  176.  
  177. End Function
  178.  
  179. Sub BotOpen(s As String, botname As String)
  180.  
  181.     Dim nl As String
  182.  
  183.     nl = Chr$(13) & Chr$(10)
  184.  
  185.     s = VBOTL_OPEN & botname & nl
  186.  
  187. End Sub
  188.  
  189. Sub BotReOpen(s As String)
  190.  
  191.     Dim slen As Integer
  192.  
  193.     slen = Len(VBOTL_CLOSE)
  194.  
  195.     If Right$(s, slen) = VBOTL_CLOSE Then
  196.         s = Left$(s, Len(s) - slen)
  197.     End If
  198.     
  199. End Sub
  200.  
  201. Sub CreateDateBot(s As String, dtype As String, sformat As String)
  202.  
  203.     ' create Bot inside passed string
  204.  
  205.     ' use DATEBOT_EDIT or DATEBOT_REGEN constants for dtype param
  206.  
  207.     Dim tmp As String
  208.  
  209.     Select Case dtype
  210.         Case DATEBOT_EDIT
  211.             ' ok
  212.         Case DATEBOT_REGEN
  213.             'ok
  214.         Case Else
  215.             ' error
  216.             MsgBox "ERROR: CreateDateBot given bad date type parameter."
  217.             Exit Sub
  218.     End Select
  219.  
  220.     BotOpen s, "TimeStamp"  ' XXX - new name
  221.     
  222.     tmp = BotMakeStrVal(dtype)
  223.     BotAddParameter s, "S-TYPE", tmp
  224.  
  225.     If sformat <> "" Then
  226.         tmp = BotMakeStrVal(sformat)
  227.         BotAddParameter s, "S-FORMAT", tmp
  228.     End If
  229.  
  230.     BotClose s
  231.  
  232. End Sub
  233.  
  234. Sub CreateIncludeBot(s As String, IncFile As String)
  235.  
  236.     ' create Bot inside passed string
  237.  
  238.     Dim tmp As String
  239.  
  240.     If IncFile = "" Then
  241.         MsgBox "ERROR: CreateIncludeBot given empty include file."
  242.         Exit Sub
  243.     End If
  244.  
  245.     If Not BotCheckIncludeVal(IncFile) Then
  246.         MsgBox "ERROR: CreateIncludeBot given bad HTML file name."
  247.         Exit Sub
  248.     End If
  249.  
  250.     BotOpen s, "Include"
  251.     
  252.     tmp = BotMakeStrVal(IncFile)
  253.     BotAddParameter s, "U-INCLUDE", IncFile
  254.  
  255.     BotClose s
  256.  
  257. End Sub
  258.  
  259. Sub CreateMacroBot(s As String, varname As String)
  260.  
  261.     ' create Bot inside passed string
  262.  
  263.     Dim tmp As String
  264.  
  265.     If varname = "" Then
  266.         MsgBox "ERROR: CreateMacroBot given empty name."
  267.         Exit Sub
  268.     End If
  269.  
  270.     BotOpen s, "Substitution"  ' xxx - new name
  271.     
  272.     tmp = BotMakeStrVal(varname)
  273.     BotAddParameter s, "S-VARIABLE", varname
  274.  
  275.     BotClose s
  276.  
  277. End Sub
  278.  
  279. Sub CreatePlaceholderBot(s As String, AuthorText As String, UserText As String)
  280.  
  281.     ' create Bot inside passed string
  282.  
  283.     Dim tmp As String
  284.  
  285.     If AuthorText = "" Then
  286.         MsgBox "ERROR: CreatePlaceholderBot given empty AuthorText parameter."
  287.         Exit Sub
  288.     End If
  289.  
  290.     BotOpen s, "PurpleText"
  291.     
  292.     tmp = BotMakeStrVal(AuthorText)
  293.     BotAddParameter s, "PREVIEW", tmp
  294.  
  295.     If UserText <> "" Then
  296.         tmp = BotMakeStrVal(UserText)
  297.         BotAddParameter s, "S-VIEWABLE", tmp
  298.     End If
  299.  
  300.     BotClose s
  301.  
  302. End Sub
  303.  
  304. Sub CreateSearchBot(s As String, indexname As String, textsource As String)
  305.  
  306.     ' create Bot inside passed string
  307.  
  308.     Dim tmp As String
  309.  
  310.     BotOpen s, "Search"     ' xxx - new name
  311.     
  312.     If indexname <> "" Then
  313.         tmp = BotMakeStrVal(indexname)
  314.         BotAddParameter s, "S-INDEX", tmp
  315.     Else
  316.         BotAddParameter s, "S-INDEX", "All"
  317.     End If
  318.  
  319.     If textsource <> "" Then
  320.         tmp = BotMakeStrVal(textsource)
  321.         BotAddParameter s, "S-DSN", tmp
  322.     End If
  323.  
  324.     BotClose s
  325.  
  326. End Sub
  327.  
  328. Sub CreateTimedImageBot(s As String, ImgFile As String, ElseImgFile As String, AltText As String, ElseAltText As String, StartDate As Variant, EndDate As Variant)
  329.  
  330.     ' create Bot inside passed string
  331.  
  332.     ' NOTE: create the date parameters using
  333.     ' DateSerial and TimeSerial functions, or
  334.     ' DateValue and TimeValue functions,
  335.     ' and then add them together:
  336.     '
  337.     ' reqdate = DateSerial(10,17,88) + TimeSerial(9,35,0)
  338.     ' reqdate = DateValue("10/17/88") + TimeValue("09:35:00")
  339.     '
  340.  
  341.     Dim tmp As String
  342.  
  343.     If Not BotCheckImageVal(ImgFile) Then
  344.         MsgBox "ERROR: CreateTimedImageBot given bad image file."
  345.         Exit Sub
  346.     End If
  347.     If ElseImgFile <> "" Then
  348.         If Not BotCheckImageVal(ElseImgFile) Then
  349.             MsgBox "ERROR: CreateTimedImageBot given bad else-image file."
  350.             Exit Sub
  351.         End If
  352.     End If
  353.     If VarType(StartDate) <> 7 Or VarType(EndDate) <> 7 Then
  354.         MsgBox "ERROR: CreateTimedImageBot given non-date parameter(s)."
  355.         Exit Sub
  356.     End If
  357.     If DateDiff("s", StartDate, EndDate) < 0 Then
  358.         MsgBox "ERROR: CreateTimedImageBot given start date greater than end date."
  359.         Exit Sub
  360.     End If
  361.  
  362.     BotOpen s, "ScheduledImage"  ' xxx - new name
  363.  
  364.     tmp = BotMakeStrVal(ImgFile)
  365.     BotAddParameter s, "U-SRC", tmp
  366.  
  367.     If ElseImgFile <> "" Then
  368.         tmp = BotMakeStrVal(ElseImgFile)
  369.         BotAddParameter s, "U-ELSE-SRC", tmp
  370.     End If
  371.  
  372.     If AltText <> "" Then
  373.         tmp = BotMakeStrVal(AltText)
  374.         BotAddParameter s, "S-ALT", tmp
  375.     End If
  376.  
  377.     If ElseAltText <> "" Then
  378.         ' don't provide ElseAltText unless ElseImgFile has been provided
  379.         If ElseImgFile <> "" Then
  380.             tmp = BotMakeStrVal(ElseAltText)
  381.             BotAddParameter s, "S-ELSE-ALT", tmp
  382.         End If
  383.     End If
  384.  
  385.     tmp = BotMakeDateVal(StartDate)
  386.     BotAddParameter s, "D-START-DATE", tmp
  387.  
  388.     tmp = BotMakeDateVal(EndDate)
  389.     BotAddParameter s, "D-END-DATE", tmp
  390.  
  391.     BotClose s
  392.  
  393. End Sub
  394.  
  395. Sub CreateTimedIncludeBot(s As String, IncFile As String, ElseIncFile As String, StartDate As Variant, EndDate As Variant)
  396.  
  397.     ' create Bot inside passed string
  398.  
  399.     ' NOTE: create the date parameters using
  400.     ' DateSerial and TimeSerial functions, or
  401.     ' DateValue and TimeValue functions,
  402.     ' and then add them together:
  403.     '
  404.     ' reqdate = DateSerial(10,17,88) + TimeSerial(9,35,0)
  405.     ' reqdate = DateValue("10/17/88") + TimeValue("09:35:00")
  406.     '
  407.  
  408.     Dim tmp As String
  409.  
  410.     If Not BotCheckIncludeVal(IncFile) Then
  411.         MsgBox "ERROR: CreateTimedIncludeBot given bad include file."
  412.         Exit Sub
  413.     End If
  414.     If ElseIncFile <> "" Then
  415.         If Not BotCheckIncludeVal(ElseIncFile) Then
  416.             MsgBox "ERROR: CreateTimedIncludeBot given bad else-include file."
  417.             Exit Sub
  418.         End If
  419.     End If
  420.     If VarType(StartDate) <> 7 Or VarType(EndDate) <> 7 Then
  421.         MsgBox "ERROR: CreateTimedIncludeBot given non-date parameter(s)."
  422.         Exit Sub
  423.     End If
  424.     If DateDiff("s", StartDate, EndDate) < 0 Then
  425.         MsgBox "ERROR: CreateTimedIncludeBot given start date greater than end date."
  426.         Exit Sub
  427.     End If
  428.  
  429.     BotOpen s, "ScheduledInclude"  ' xxx - new name
  430.  
  431.     tmp = BotMakeStrVal(IncFile)
  432.     BotAddParameter s, "U-INCLUDE", tmp
  433.  
  434.     If ElseIncFile <> "" Then
  435.         tmp = BotMakeStrVal(ElseIncFile)
  436.         BotAddParameter s, "U-ELSE-INCLUDE", tmp
  437.     End If
  438.  
  439.     tmp = BotMakeDateVal(StartDate)
  440.     BotAddParameter s, "D-START-DATE", tmp
  441.  
  442.     tmp = BotMakeDateVal(EndDate)
  443.     BotAddParameter s, "D-END-DATE", tmp
  444.  
  445.     BotClose s
  446.  
  447. End Sub
  448.  
  449.