home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD53704302000.psc / CodeLib_V2 / CLMod1.bas < prev    next >
Encoding:
BASIC Source File  |  2000-01-25  |  11.1 KB  |  356 lines

  1. Attribute VB_Name = "CLMod1"
  2. Public Idx1%, TabIdx%, CodeCount%
  3. Public CLdata(4, 999), Cat$(99)
  4. Public Temp$, Title$, xx%, yy%, t%, ff%, CLnum%, CatIdx%
  5. Public SelCode$, AppendIdx%, ReplaceIdx%
  6. Public Declare Function SendMessageAsLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  7. 'Declarations for ExplodeForm
  8. Type RECT
  9.         Left As Long
  10.         Top As Long
  11.         Right As Long
  12.         Bottom As Long
  13. End Type
  14. Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
  15. Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  16. Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
  17. Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
  18. Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
  19. Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long  'note error in declare
  20. Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
  21. Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
  22. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  23. Public Const WM_RBUTTONDOWN = &H204
  24.  
  25. Public Sub SizeCombo(frm As Form, cbo As ComboBox)
  26.     Dim cbo_left As Integer
  27.     Dim cbo_top As Integer
  28.     Dim cbo_width As Integer
  29.     Dim cbo_height As Integer
  30.     Dim old_scale_mode As Integer
  31. ' Change the Scale Mode on the form to Pixels.
  32.     old_scale_mode = frm.ScaleMode
  33.     frm.ScaleMode = vbPixels
  34. ' Save the ComboBox's Left, Top, and Width values.
  35.     cbo_left = cbo.Left
  36.     cbo_top = cbo.Top
  37.     cbo_width = cbo.Width
  38. ' Set the new height of the combo box.
  39.     cbo_height = 300
  40.     frm.ScaleMode = old_scale_mode
  41. ' Resize the combo box window.
  42.     MoveWindow cbo.hwnd, cbo_left, cbo_top, cbo_width, cbo_height, 1
  43. End Sub
  44.  
  45.  
  46. Public Function CryptText(CrTxt$, CrCode)
  47. Dim CrX%
  48. CrCode = CrCode And &HFF& ' max 255
  49. For CrX = 1 To Len(CrTxt)
  50. If Mid(CrTxt, CrX, 1) <> Chr(13) Then
  51. Mid(CrTxt, CrX, 1) = Chr(Asc(Mid(CrTxt, CrX, 1)) Xor CrCode)
  52. End If
  53. Next CrX
  54. CryptText = CrTxt
  55. End Function
  56.  
  57. Sub ExplodeForm(frm As Form, Steps As Long, Color As Long)
  58.    Dim ThisRect As RECT, RectWidth As Integer, RectHeight As Integer, ScreenDevice As Long, NewBrush As Long, OldBrush As Long, I As Long, X As Integer, Y As Integer, XRect As Integer, YRect As Integer
  59.    If Steps < 20 Then Steps = 20
  60.    'Zooming speed will be different based on machine speed!
  61.    If Color = 0 Then
  62.       Color = frm.BackColor
  63.    End If
  64.    Steps = Steps * 10
  65.    'Get current form window dimensions
  66.    GetWindowRect frm.hwnd, ThisRect
  67.    RectWidth = (ThisRect.Right - ThisRect.Left)
  68.    RectHeight = ThisRect.Bottom - ThisRect.Top
  69.    'Get a device handle for the screen
  70.    ScreenDevice = GetDC(0)
  71.    'Create a brush for drawing to the screen
  72.    'and save the old brush
  73.    NewBrush = CreateSolidBrush(Color)
  74.    OldBrush = SelectObject(ScreenDevice, NewBrush)
  75.    For I = 1 To Steps
  76.       XRect = RectWidth * (I / Steps)
  77.       YRect = RectHeight * (I / Steps)
  78.       X = ThisRect.Left + (RectWidth - XRect) / 2
  79.       Y = ThisRect.Top + (RectHeight - YRect) / 2
  80.       'Incrementally draw rectangle
  81.       Rectangle ScreenDevice, X, Y, X + XRect, Y + YRect
  82.    Next I
  83.    'Return old brush and delete screen device context handle
  84.    'Then destroy brush that drew rectangles
  85.    Call SelectObject(ScreenDevice, OldBrush)
  86.    Call ReleaseDC(0, ScreenDevice)
  87.    DeleteObject (NewBrush)
  88. End Sub
  89.  
  90. Public Function GetLineCount(C As Control)
  91.   Const EM_GETLINECOUNT = 186
  92.   GetLineCount = SendMessageAsLong(C.hwnd, EM_GETLINECOUNT, 0, 0)
  93. End Function
  94.  
  95.  
  96. Public Function Setline(Obj As Object, LineY%, Optional LineStyle As Boolean)
  97. If IsMissing(LineStyle) Then LineStyle = False
  98. If LineStyle = False Then
  99. Obj.Line (0, LineY)-(Obj.ScaleWidth, LineY), RGB(128, 128, 128)
  100. Obj.Line (0, LineY + 1)-(Obj.ScaleWidth, LineY + 1), RGB(240, 240, 240)
  101. Else
  102. Obj.Line (0, LineY)-(Obj.ScaleWidth, LineY), RGB(240, 240, 240)
  103. Obj.Line (0, LineY + 1)-(Obj.ScaleWidth, LineY + 1), RGB(128, 128, 128)
  104. End If
  105. End Function
  106.  
  107. Public Sub LoadCat()
  108. On Error GoTo LoadCat2
  109. CodeLib.Combo1.Clear
  110. ff = FreeFile
  111. Open App.Path & "\Data\Cat.ini" For Input As #ff
  112. xx = 0
  113. Do While Not EOF(1)
  114.  
  115. Line Input #ff, Cat(xx)
  116. If Cat(xx) <> Empty Then
  117. CodeLib.Combo1.AddItem Format(xx, "00") & "  " & Cat(xx)
  118. CodeLib.Combo1.ItemData(CodeLib.Combo1.NewIndex) = xx
  119. End If
  120. xx = xx + 1
  121. Loop
  122. Close #ff
  123. Exit Sub
  124. LoadCat2:
  125. Close #ff
  126. Msbox "There's an error while" & vbCr & "loading the category-data..." & vbCr & vbCr & "Error: " & Err & "  " & Err.Description, Title, mbOkonly, mbCritical
  127. End Sub
  128.  
  129. Public Sub SaveLib()
  130. On Error GoTo SaveLib2
  131. ff = FreeFile
  132. Open App.Path & "\Data\CodeLib.cod" For Output As #ff
  133. For xx = 0 To 999
  134. If CLdata(1, xx) <> "" Then 'has name
  135.     Print #ff, CLdata(0, xx) 'category
  136.     Print #ff, CLdata(1, xx) 'name
  137.     Print #ff, Trim(CLdata(2, xx))
  138.     Print #ff, "≈≈≈≈≈≈" 'code
  139.     If Trim(CLdata(3, xx)) <> "" Then
  140.     Print #ff, Trim(CLdata(3, xx)) 'helpfile
  141.     End If
  142.     Print #ff, "≈≈≈≈≈≈"
  143.     If Trim(CLdata(4, xx)) <> "" Then
  144.     Print #ff, Trim(CLdata(4, xx)) 'notes
  145.     End If
  146.     Print #ff, "≈≈≈≈≈≈"
  147.     
  148. End If
  149. Next xx
  150. Close #ff
  151. Exit Sub
  152. SaveLib2:
  153. Close #ff
  154. Msbox "There's an error while" & vbCr & "saving the Database..." & vbCr & vbCr & "Error: " & Err & "  " & Err.Description, Title, mbOkonly, mbCritical
  155. End Sub
  156.  
  157. Public Sub LoadLib()
  158. With CodeLib
  159. ff = FreeFile
  160. t = 0
  161. Open App.Path & "\Data\CodeLib.cod" For Input As #ff
  162. 'On Error GoTo LoadLib2
  163. Do While Not EOF(1)
  164. Line Input #ff, CLdata(0, t) 'category
  165. Line Input #ff, CLdata(1, t) 'name
  166.     'Load code
  167.     CLdata(2, t) = ""
  168.     Do
  169.     Line Input #1, Temp 'code
  170.     If Temp = "≈≈≈≈≈≈" Then GoTo LoadLib3
  171.     CLdata(2, t) = CLdata(2, t) & Temp & vbCrLf
  172.     Loop
  173. LoadLib3:
  174.     'kill last chr(13) and chr(10)
  175.     If CLdata(2, t) <> "" Then
  176.     CLdata(2, t) = Left(CLdata(2, t), Len(CLdata(2, t)) - 2)
  177.     End If
  178.     'Load Help
  179.     CLdata(3, t) = ""
  180.     Do
  181.     Line Input #1, Temp 'helpfile
  182.     If Temp = "≈≈≈≈≈≈" Then GoTo LoadLib4
  183.     CLdata(3, t) = CLdata(3, t) & Temp & vbCrLf
  184.     Loop
  185. LoadLib4:
  186.     'kill last chr(13) and chr(10)
  187.     If CLdata(3, t) <> "" Then
  188.     CLdata(3, t) = Left(CLdata(3, t), Len(CLdata(3, t)) - 2)
  189.     End If
  190.     'Load Notes
  191.     CLdata(4, t) = ""
  192.     Do
  193.     Line Input #1, Temp 'notes
  194.     If Temp = "≈≈≈≈≈≈" Then GoTo LoadLib5
  195.     CLdata(4, t) = CLdata(4, t) & Temp & vbCrLf
  196.     Loop
  197. LoadLib5:
  198.     'kill last chr(13) and chr(10)
  199.     If CLdata(4, t) <> "" Then
  200.     CLdata(4, t) = Left(CLdata(4, t), Len(CLdata(4, t)) - 2)
  201.     End If
  202.     CodeCount = CodeCount + 1
  203. t = t + 1
  204. Loop
  205. CodeCount = t
  206. Close #ff
  207. Exit Sub
  208. LoadLib2:
  209. Close #ff
  210. Msbox "There's an error while" & vbCr & "loading the database..." & vbCr & vbCr & "Error: " & Err & "  " & Err.Description, Title, mbOkonly, mbCritical
  211. End With
  212. End Sub
  213.  
  214. Public Sub SearchItems()
  215. For xx = 0 To 999
  216. If CLdata(0, xx) = CatIdx And CLdata(1, xx) <> Empty Then
  217. CodeLib.List1.AddItem CLdata(1, xx)
  218. CodeLib.List1.ItemData(CodeLib.List1.NewIndex) = xx
  219. End If
  220. Next xx
  221. CodeLib.Label9.Caption = CodeLib.List1.ListCount & " items in DataBase"
  222. End Sub
  223.  
  224. Public Sub RenameCode()
  225. With CodeLib
  226. CLdata(1, .List1.ItemData(Idx1)) = IbReturn
  227. .Label1(0).Caption = .Label2.Caption & " " & CLdata(1, .List1.ItemData(Idx1))
  228. .Label1(1).Caption = .Label2.Caption & " " & CLdata(1, .List1.ItemData(Idx1))
  229. .Label1(2).Caption = .Label2.Caption & " " & CLdata(1, .List1.ItemData(Idx1))
  230. .Pic5.BackColor = 0
  231. .Label6.Caption = "Database dirty"
  232.  
  233. t = .List1.ListIndex
  234. .List1.Clear
  235. SearchItems
  236. .List1.Selected(t) = True
  237. End With
  238. End Sub
  239. Public Sub KillEntry()
  240. With CodeLib
  241. Screen.MousePointer = 11
  242. For xx = 0 To 4
  243. CLdata(xx, .List1.ItemData(Idx1)) = ""
  244. Next xx
  245. For xx = 0 To 3
  246. .Text1(xx).Text = ""
  247. .Label1(xx).Caption = ""
  248. Next xx
  249.  
  250. For yy = Idx1 To 998
  251.     For xx = 0 To 4
  252.     CLdata(xx, yy) = CLdata(xx, yy + 1)
  253.     Next xx
  254. Next yy
  255. CLdata(0, 999) = "" 'kill category
  256. CLdata(1, 999) = "" 'kill name
  257. CLdata(2, 999) = "" 'kill code
  258. CLdata(3, 999) = "" 'kill helpfile
  259. CLdata(4, 999) = "" 'kill notes
  260. .Pic5.BackColor = 0
  261. .Label6.Caption = "Database dirty"
  262. .List1.Clear
  263. SearchItems
  264. .Pic7.Visible = False
  265. .Label7.Visible = False
  266. .Pic8.Visible = False
  267. .Label8.Visible = False
  268. DoEvents
  269. .Pic2.BackColor = RGB(192, 192, 192)
  270. .Pic3.BackColor = RGB(192, 192, 192)
  271. .Pic4.BackColor = RGB(192, 192, 192)
  272. CodeCount = CodeCount - 1
  273. .Label11.Caption = "Number of Code-snippets:" & vbCr & CodeCount
  274. Screen.MousePointer = 1
  275. End With
  276. End Sub
  277.  
  278. Public Sub ColBar(Obj As Object, St%, h%, R%, G%, B%, RE%, GE%, BE%)
  279. Dim H2%, H3%, IvR%, IvG%, IvB%
  280. Obj.AutoRedraw = True
  281. Obj.ScaleMode = 3 'pixel
  282. H3 = Int(h / 2)
  283. IvR = Int(RE - R) / H3
  284. IvG = Int(GE - G) / H3
  285. IvB = Int(BE - B) / H3
  286. Do While h >= H3
  287. Obj.Line (0, St + H2)-(Obj.ScaleWidth, St + H2), RGB(R, G, B)
  288. Obj.Line (0, St + h)-(Obj.ScaleWidth, St + h), RGB(R, G, B)
  289. h = h - 1
  290. H2 = H2 + 1
  291. R = R + IvR
  292. G = G + IvG
  293. B = B + IvB
  294. Loop
  295. End Sub
  296. Public Sub ColBox(Obj As Object, BX%, BY%, EX%, EY%, h%, R%, G%, B%, RE%, GE%, BE%)
  297. Dim H2%, H3%, IvR%, IvG%, IvB%
  298. Obj.AutoRedraw = True
  299. Obj.ScaleMode = 3 'pixel
  300. H3 = Int(h / 2)
  301. IvR = Int(RE - R) / H3
  302. IvG = Int(GE - G) / H3
  303. IvB = Int(BE - B) / H3
  304. Do While h >= H3
  305. Obj.Line (BX + H2, BY + H2)-(EX - H2, EY - H2), RGB(R, G, B), B
  306. Obj.Line (BX + h, BY + h)-(EX - h, EY - h), RGB(R, G, B), B
  307. h = h - 1
  308. H2 = H2 + 1
  309. R = R + IvR
  310. G = G + IvG
  311. B = B + IvB
  312. Loop
  313. End Sub
  314.  
  315. Public Sub AddToDB() 'add code
  316.     For xx = 0 To 999
  317.     If CLdata(0, xx) = "" And CLdata(1, xx) = "" Then 'no category and name
  318.     AppendIdx = xx
  319.     Exit For
  320.     End If
  321.     Next xx
  322.         CLdata(0, AppendIdx) = Search2.Combo1.ListIndex 'category
  323.         CLdata(1, AppendIdx) = Search2.Text1.Text 'name
  324.         CLdata(2, AppendIdx) = SelCode 'add code
  325.  
  326. CodeLib.Pic5.BackColor = 0 'database dirty
  327. CodeLib.Label6.Caption = "Database dirty"
  328. If CodeLib.List1.ListCount <> 0 Then
  329. CodeLib.List1.Clear
  330. SearchItems
  331. End If
  332. CodeCount = CodeCount + 1
  333. CodeLib.Label11.Caption = "Number of Code-snippets:" & vbCr & CodeCount
  334. Search2.Hide
  335. End Sub
  336.  
  337. Public Sub AddToDB2() 'add helpfile
  338. If CLdata(3, AppendIdx) <> "" Then
  339. Msbox "The code " & CLdata(1, AppendIdx) & " has already a helpfile. Would you like to replace it with the new one ?", Title, mbYesNo, mbQuestion
  340. If MBReturn = 1 Then Exit Sub 'do not replace help
  341. End If
  342.         CLdata(3, AppendIdx) = SelCode 'add/replace helpfile
  343. CodeLib.Pic5.BackColor = 0 'database dirty
  344. CodeLib.Label6.Caption = "Database dirty"
  345. Search3.Hide
  346. End Sub
  347.  
  348. Public Sub ReplaceCode()
  349. CLdata(2, ReplaceIdx) = SelCode ' Replace the code
  350. CodeLib.Pic5.BackColor = 0 'database dirty
  351. CodeLib.Label6.Caption = "Database dirty"
  352. CodeLib.List1.Clear
  353. SearchItems
  354. Search2.Hide
  355. End Sub
  356.