home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / View_HTML_47064172002.psc / mod_HTML.bas < prev    next >
Encoding:
BASIC Source File  |  2002-01-07  |  8.4 KB  |  348 lines

  1. Attribute VB_Name = "mod_HTML"
  2. 'Various Subs for Working With HTML TAGS
  3.  
  4. Public Function GetHTMLEle(Origin As String, Sep1 As String, Sep2 As String) As String
  5. 'Parses a Line of text
  6. On Error GoTo EH
  7. Dim Bpos As Long
  8. Dim Epos As Long
  9. Dim SPacePOS As Long
  10.  
  11. Bpos = InStr(1, Origin, Sep1, vbBinaryCompare)
  12. If Bpos = 0 Then Exit Function
  13. Epos = InStr(Bpos + Len(Sep1), Origin, Sep2, vbBinaryCompare)
  14. SPacePOS = InStr(Bpos + Len(Sep1), Origin, " ", vbBinaryCompare)
  15.  
  16. If Epos = 0 Then
  17.  If SPacePOS = 0 Then Exit Function
  18.  Epos = SPacePOS
  19. End If
  20. If SPacePOS < Epos Then
  21. Epos = SPacePOS
  22. End If
  23. Bpos = Bpos + Len(Sep1)
  24. If Epos > 0 Then
  25. GetHTMLEle = Mid(Origin, Bpos, Epos - Bpos)
  26. Else
  27. GetHTMLEle = Mid(Origin, Bpos, Len(Origin))
  28. End If
  29. Exit Function
  30. EH:
  31. GetHTMLEle = ""
  32. Exit Function
  33. End Function
  34.  
  35. Public Function StripHTML(sHTML As String) As String
  36.     Dim sTemp As String, lSpot1 As Long, lSpot2 As Long, lSpot3 As Long
  37.     sTemp$ = sHTML$
  38.  
  39.  
  40.     Do
  41.         lSpot1& = InStr(lSpot3& + 1, sTemp$, "<")
  42.         lSpot2& = InStr(lSpot1& + 1, sTemp$, ">")
  43.         
  44.         If lSpot1& = lSpot3& Or lSpot1& < 1 Then Exit Do
  45.         If lSpot2& < lSpot1& Then lSpot2& = lSpot1& + 1
  46.         sTemp$ = Left$(sTemp$, lSpot1& - 1) + Right$(sTemp$, Len(sTemp$) - lSpot2&)
  47.         lSpot3& = lSpot1& - 1
  48.     Loop
  49.     StripHTML$ = sTemp$
  50. End Function
  51.  
  52.  
  53. Public Function GETHex(stColor As Long) As String
  54.   GETHex = "#" & Hex(stColor)
  55. End Function
  56.  
  57. Public Function GETHexOLD(stColor As Long) As String
  58. 'This is Obsolete
  59. On Error Resume Next
  60. 'stColor = m_CurHex
  61.        '     'If r > 255 Then Exit Sub
  62.        '     'If g > 255 Then Exit Sub
  63.        '     'If b > 255 Then Exit Sub
  64.        Dim r, b, g As Long
  65.        
  66.        Dim dts As Variant
  67.        Dim q, w, e As Variant
  68.        Dim qw, we, gq As Variant
  69.        Dim lCol As Long
  70.        lCol = stColor
  71.        r = lCol Mod &H100
  72.        lCol = lCol \ &H100
  73.        g = lCol Mod &H100
  74.        lCol = lCol \ &H100
  75.        b = lCol Mod &H100
  76.        
  77.        '     'Get Red Hex
  78.        q = Hex(r)
  79.  
  80.               If Len(q) < 2 Then
  81.                      qw = q
  82.                      q = "0" & qw
  83.               End If
  84.  
  85.        '     'Get Blue Hex
  86.        w = Hex(b)
  87.  
  88.               If Len(w) < 2 Then
  89.                      we = w
  90.                      w = "0" & we
  91.               End If
  92.  
  93.        '     'Get Green Hex
  94.        e = Hex(g)
  95.  
  96.               If Len(e) < 2 Then
  97.                      gq = e
  98.                      e = "0" & gq
  99.               End If
  100.  
  101.        'GETRGB = "#" & q & e & w
  102.        GETHexOLD = "#" & q & e & w   '"#" &
  103. End Function
  104. Public Function RgbToHsv(r, g, b, h, S, V) As Long
  105.     'Convert RGB to HSV values
  106.     Dim vRed, vGreen, vBlue
  107.     Dim Mx, Mn, Va, Sa, rc, gc, bc
  108.  
  109.     vRed = r / 255
  110.     vGreen = g / 255
  111.     vBlue = b / 255
  112.  
  113.     Mx = vRed
  114.     If vGreen > Mx Then Mx = vGreen
  115.     If vBlue > Mx Then Mx = vBlue
  116.  
  117.     Mn = vRed
  118.     If vGreen < Mn Then Mn = vGreen
  119.     If vBlue < Mn Then Mn = vBlue
  120.  
  121.     Va = Mx
  122.     If Mx Then
  123.         Sa = (Mx - Mn) / Mx
  124.     Else
  125.         Sa = 0
  126.     End If
  127.     If Sa = 0 Then
  128.         h = 0
  129.     Else
  130.         rc = (Mx - vRed) / (Mx - Mn)
  131.         gc = (Mx - vGreen) / (Mx - Mn)
  132.         bc = (Mx - vBlue) / (Mx - Mn)
  133.         Select Case Mx
  134.         Case vRed
  135.             h = bc - gc
  136.         Case vGreen
  137.             h = 2 + rc - bc
  138.         Case vBlue
  139.             h = 4 + gc - rc
  140.          End Select
  141.         h = h * 60
  142.         If h < 0 Then h = h + 360
  143.     End If
  144.  
  145.     S = Sa * 100
  146.     V = Va * 100
  147.     RgbToHsv = r + g + b
  148. End Function
  149.  
  150. Sub HsvToRgb(h, S, V, r, g, b)
  151.     'Convert HSV to RGB values
  152.     Dim Sa, Va, Hue, I, f, P, q, t
  153.  
  154.     Sa = S / 100
  155.     Va = V / 100
  156.     If S = 0 Then
  157.         r = Va
  158.         g = Va
  159.         b = Va
  160.     Else
  161.         Hue = h / 60
  162.         If Hue = 6 Then Hue = 0
  163.         I = Int(Hue)
  164.         f = Hue - I
  165.         P = Va * (1 - Sa)
  166.         q = Va * (1 - (Sa * f))
  167.         t = Va * (1 - (Sa * (1 - f)))
  168.         Select Case I
  169.         Case 0
  170.             r = Va
  171.             g = t
  172.             b = P
  173.         Case 1
  174.             r = q
  175.             g = Va
  176.             b = P
  177.         Case 2
  178.             r = P
  179.             g = Va
  180.             b = t
  181.         Case 3
  182.             r = P
  183.             g = q
  184.             b = Va
  185.         Case 4
  186.             r = t
  187.             g = P
  188.             b = Va
  189.         Case 5
  190.             r = Va
  191.             g = P
  192.             b = q
  193.         End Select
  194.     End If
  195.     
  196.     r = Int(255.9999 * r)
  197.     g = Int(255.9999 * g)
  198.     b = Int(255.9999 * b)
  199. End Sub
  200. Public Sub GETRGB(SColor As Variant)
  201. Dim r, g, b As Integer
  202. r = SColor Mod &H100
  203. g = (SColor \ &H100) Mod &H100
  204. b = (SColor \ &H10000) Mod &H100
  205. frmColor.Text3.Text = r
  206. frmColor.Text4.Text = g
  207. frmColor.Text5.Text = b
  208.  
  209. Dim rr, gg, bb, maincolor As Long
  210.  
  211.  
  212. 'frmColor.BackColor = (r * 255) + (g * 255) + (b * 255)
  213. End Sub
  214.  
  215.  
  216.  
  217. Sub FadeSide2Side(Form As Object, Color1 As Long, Color2 As Long)
  218. Dim X!, x2!, Y%, I%, red1%, green1%, blue1%, red2%, green2%, blue2%, pat1!, pat2!, pat3!, c1!, c2!, c3!
  219. ' find the length of the form and cut it into 80 pieces
  220. x2 = (Form.Width / 80) / 2
  221. Y% = Form.ScaleHeight
  222. ' separating red, green, and blue in each of the two colors
  223. red1% = Color1 And 255
  224. green1% = Color1 \ 256 And 255
  225. blue1% = Color1 \ 65536 And 255
  226. red2% = Color2 And 255
  227. green2% = Color2 \ 256 And 255
  228. blue2% = Color2 \ 65536 And 255
  229. ' cut the difference between the two colors into 100 pieces
  230. pat1 = (red2% - red1%) / 80
  231. pat2 = (green2% - green1%) / 80
  232. pat3 = (blue2% - blue1%) / 80
  233. ' set the c variables at the starting colors
  234. c1 = red1%
  235. c2 = green1%
  236. c3 = blue1%
  237. ' draw 80 different lines on the form
  238. For I% = 1 To 80
  239. Form.Line (X, 0)-(X + x2, Y%), RGB(c1, c2, c3), BF
  240. X = X + x2 ' draw the Next line one step up from the old step
  241. c1 = c1 + pat1 ' make the c variable equal 2 it's Next step
  242. c2 = c2 + pat2
  243. c3 = c3 + pat3
  244.  Next
  245. Form.CurrentX = 0
  246. Form.CurrentY = 0
  247. 'Form.Print "Click And Resize Me!" ' Note: remove this line when making your own projects
  248. End Sub
  249.  
  250. Sub FadeSide2Side2(Form As Object, Color1 As Long, Color2 As Long)
  251. Dim X!, x2!, Y%, I%, red1%, green1%, blue1%, red2%, green2%, blue2%, pat1!, pat2!, pat3!, c1!, c2!, c3!
  252. ' find the length of the form and cut it into 80 pieces
  253. x2 = (Form.Width / 80) / 2
  254. Y% = Form.ScaleHeight
  255. ' separating red, green, and blue in each of the two colors
  256. red1% = Color1 And 255
  257. green1% = Color1 \ 256 And 255
  258. blue1% = Color1 \ 65536 And 255
  259. red2% = Color2 And 255
  260. green2% = Color2 \ 256 And 255
  261. blue2% = Color2 \ 65536 And 255
  262. ' cut the difference between the two colors into 100 pieces
  263. pat1 = (red2% - red1%) / 80
  264. pat2 = (green2% - green1%) / 80
  265. pat3 = (blue2% - blue1%) / 80
  266. ' set the c variables at the starting colors
  267. c1 = red1%
  268. c2 = green1%
  269. c3 = blue1%
  270. ' draw 80 different lines on the form
  271. X = Form.Width / 2 - 55
  272. For I% = 1 To 80
  273. 'picture1.Line
  274. 'Form.Line (x, 0)-(x + x2, y%), RGB(c1, c2, c3), BF
  275. Form.Line (X, 0)-(X + x2, Y%), RGB(c1, c2, c3), BF
  276. X = X + x2 ' draw the Next line one step up from the old step
  277. c1 = c1 + pat1 ' make the c variable equal 2 it's Next step
  278. c2 = c2 + pat2
  279. c3 = c3 + pat3
  280.  Next
  281. Form.CurrentX = 0
  282. Form.CurrentY = 0
  283.  
  284. 'Form.Print "Click And Resize Me!" ' Note: remove this line when making your own projects
  285. End Sub
  286.  
  287. Public Function MakeRGBHex(stColor As Long) As String
  288. On Error GoTo EH
  289. Dim r, b, g As Long
  290. Dim dts As Variant
  291. Dim q, w, e As Variant
  292. Dim qw, we, gq As Variant
  293. Dim lCol As Long
  294. lCol = stColor
  295. r = lCol Mod &H100
  296. lCol = lCol \ &H100
  297. g = lCol Mod &H100
  298. lCol = lCol \ &H100
  299. b = lCol Mod &H100
  300. q = Hex(r)
  301. If Len(q) < 2 Then
  302. qw = q
  303. q = "0" & qw
  304. End If
  305. w = Hex(b)
  306. If Len(w) < 2 Then
  307. we = w
  308. w = "0" & we
  309. End If
  310. e = Hex(g)
  311. If Len(e) < 2 Then
  312. gq = e
  313. e = "0" & gq
  314. End If
  315. MakeRGBHex = "#" & q & e & w
  316. Exit Function
  317. EH:
  318. MakeRGBHex = "#" & q & e & w
  319. Exit Function
  320. End Function
  321.  
  322. ''''''''''''''''''''''''''''''''''''''''''''''
  323. Public Function MakeHexRGB(sHex As String) As Long
  324. On Error GoTo Errh
  325. Dim Ipos As Integer
  326. Dim tmpStr As String
  327. Dim P1 As String
  328. Dim P2 As String
  329. Dim P3 As String
  330. Dim pFin As String
  331. Ipos = InStr(1, sHex, "#", vbBinaryCompare)
  332. If Ipos = 0 Then
  333. tmpStr = sHex
  334. Else
  335. If Ipos <> 0 Then
  336. tmpStr = Mid(sHex, Ipos + 1, Len(sHex))
  337. End If
  338. End If
  339. P1 = Mid(tmpStr, 1, 2)
  340. P2 = Mid(tmpStr, 3, 2)
  341. P3 = Mid(tmpStr, 5, 2)
  342. pFin = P3 & P2 & P1
  343. MakeHexRGB = CLng("&H" & pFin)
  344. Errh:
  345. Exit Function
  346. End Function
  347.  
  348.