home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_BAS / RDBLIB.ZIP / RDBLIB.BAS < prev    next >
BASIC Source File  |  1994-02-05  |  14KB  |  361 lines

  1. ' Common Subroutine & Functions Module
  2. ' Provided by:
  3. '    Royce D. Bacon
  4. '    RDB Systems
  5. '    8942 W. Lawrence Ave.
  6. '    Milwaukee, WI  53225
  7. '    Compuserve ID: 70042,1001
  8. '
  9. ' You may use these routines in your own programs and
  10. ' distribute them or the compiled versions of them
  11. ' with your programs.  However, you may not distribute
  12. ' these routines alone for profit.
  13. '
  14. ' Payment for these routines is not required, but will
  15. ' always be appreciated.
  16. '
  17.  
  18.  
  19. Global rb_systemname As String
  20. Global rb_version As String
  21. Global RB_Erraction As Integer
  22. Global Const RB_GRAY = &HC0C0C0
  23.  
  24. ' Windows function declarations
  25.  
  26. Declare Function GetModuleUsage Lib "KERNEL" (ByVal InstanceID%) As Integer
  27.  
  28. '******************************************************
  29. '           DLL Declarations                          *
  30. '******************************************************
  31. Type POINTAPI
  32.     X As Integer
  33.     Y As Integer
  34. End Type
  35.  
  36. Declare Function LoadMenu Lib "User" (ByVal hInstance As Integer, ByVal lpString As String) As Integer
  37. Declare Function GetMenu Lib "User" (ByVal hWnd As Integer) As Integer
  38. Declare Function SetMenu Lib "User" (ByVal hWnd As Integer, ByVal hMenu As Integer) As Integer
  39. Declare Function HiliteMenuItem Lib "User" (ByVal hWnd As Integer, ByVal hMenu As Integer, ByVal wIDHiliteItem As Integer, ByVal wHilite As Integer) As Integer
  40. Declare Function GetMenuString Lib "User" (ByVal hMenu As Integer, ByVal wIDItem As Integer, ByVal lpString As String, ByVal nMaxCount As Integer, ByVal wFlag As Integer) As Integer
  41. Declare Function GetMenuState Lib "User" (ByVal hMenu As Integer, ByVal wId As Integer, ByVal wFlags As Integer) As Integer
  42. Declare Sub DrawMenuBar Lib "User" (ByVal hWnd As Integer)
  43. Declare Function GetSystemMenu Lib "User" (ByVal hWnd As Integer, ByVal bRevert As Integer) As Integer
  44. Declare Function GetSubMenu Lib "User" (ByVal hMenu As Integer, ByVal nPos As Integer) As Integer
  45. Declare Function GetMenuItemID Lib "User" (ByVal hMenu As Integer, ByVal nPos As Integer) As Integer
  46. Declare Function GetMenuItemCount Lib "User" (ByVal hMenu As Integer) As Integer
  47. Declare Function TrackPopupMenu Lib "User" (ByVal hMenu As Integer, ByVal wFlags As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal nReserved As Integer, ByVal hWnd As Integer, lpReserved As Any) As Integer
  48. Declare Function InsertMenu Lib "User" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer, ByVal wIDNewItem As Integer, ByVal lpNewItem As Any) As Integer
  49. Declare Function AppendMenu Lib "User" (ByVal hMenu As Integer, ByVal wFlags As Integer, ByVal wIDNewItem As Integer, ByVal lpNewItem As Any) As Integer
  50. Declare Function ModifyMenu Lib "User" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer, ByVal wIDNewItem As Integer, ByVal lpString As Any) As Integer
  51. Declare Function RemoveMenu Lib "User" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
  52. Declare Function DeleteMenu Lib "User" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
  53.  
  54. Declare Function ExitWindows Lib "User" (ByVal dwReserved As Long, wReturnCode) As Integer
  55. Declare Function GetDeviceCaps Lib "GDI" (ByVal hDC As Integer, ByVal nIndex As Integer) As Integer
  56. Declare Function GetActiveWindow Lib "User" () As Integer
  57. Declare Sub GetCursorPos Lib "User" (lpPoint As POINTAPI)
  58. Declare Function GetSystemMetrics Lib "User" (ByVal nIndex As Integer) As Integer
  59. Declare Function GetFocus Lib "User" () As Integer
  60. Declare Function SetActiveWindow Lib "User" (ByVal hWnd As Integer) As Integer
  61. Declare Function GetModuleHandle Lib "Kernel" (ByVal lpModuleName As String) As Integer
  62. Declare Function GetModuleFileName Lib "Kernel" (ByVal hModule As Integer, ByVal lpFilename As String, ByVal nSize As Integer) As Integer
  63. Declare Function GetFreeSpace Lib "Kernel" (ByVal wFlags As Integer) As Long
  64.  
  65. 'Indices for GetSystemMetrics
  66. Global Const SM_CXSIZE = 30
  67. Global Const SM_CYSIZE = 31
  68.  
  69. 'Indices for GetDeviceCaps
  70. Global Const HORZRES = 8    '  Horizontal width in pixels
  71. Global Const VERTRES = 10   '  Vertical width in pixels
  72.  
  73. 'Menu flags for Add/Check/EnableMenuItem()
  74. Global Const MF_INSERT = &H0
  75. Global Const MF_CHANGE = &H80
  76. Global Const MF_APPEND = &H100
  77. Global Const MF_DELETE = &H200
  78. Global Const MF_REMOVE = &H1000
  79.  
  80. Global Const MF_BYCOMMAND = &H0
  81. Global Const MF_BYPOSITION = &H400
  82.  
  83. Global Const MF_SEPARATOR = &H800
  84.  
  85. Global Const MF_ENABLED = &H0
  86. Global Const MF_GRAYED = &H1
  87. Global Const MF_DISABLED = &H2
  88.  
  89. Global Const MF_UNCHECKED = &H0
  90. Global Const MF_CHECKED = &H8
  91. Global Const MF_USECHECKBITMAPS = &H200
  92.  
  93. Global Const MF_STRING = &H0
  94. Global Const MF_BITMAP = &H4
  95. Global Const MF_OWNERDRAW = &H100
  96.  
  97. Global Const MF_POPUP = &H10
  98. Global Const MF_MENUBARBREAK = &H20
  99. Global Const MF_MENUBREAK = &H40
  100.  
  101. Global Const MF_UNHILITE = &H0
  102. Global Const MF_HILITE = &H80
  103.  
  104. Global Const MF_SYSMENU = &H2000
  105. Global Const MF_HELP = &H4000
  106. Global Const MF_MOUSESELECT = &H8000
  107.  
  108. '  Menu item resource format
  109. Type MENUITEMTEMPLATEHEADER
  110.     versionNumber As Integer
  111.     offset As Integer
  112. End Type
  113.  
  114. Type MENUITEMTEMPLATE
  115.     mtOption As Integer
  116.     mtID As Integer
  117.     mtString As Long
  118. End Type
  119.  
  120. Global Const MF_END = &H80
  121.  
  122. '  System Menu Command Values
  123. Global Const SC_SIZE = &HF000
  124. Global Const SC_MOVE = &HF010
  125. Global Const SC_MINIMIZE = &HF020
  126. Global Const SC_MAXIMIZE = &HF030
  127. Global Const SC_NEXTWINDOW = &HF040
  128. Global Const SC_PREVWINDOW = &HF050
  129. Global Const SC_CLOSE = &HF060
  130. Global Const SC_VSCROLL = &HF070
  131. Global Const SC_HSCROLL = &HF080
  132. Global Const SC_MOUSEMENU = &HF090
  133. Global Const SC_KEYMENU = &HF100
  134. Global Const SC_ARRANGE = &HF110
  135. Global Const SC_RESTORE = &HF120
  136. Global Const SC_TASKLIST = &HF130
  137.  
  138. '******************************************************
  139. '*          OpenFile Modes                            *
  140. '******************************************************
  141. Global Const REPLACEFILE = 0
  142. Global Const READFILE = 1
  143. Global Const APPENDFILE = 2
  144. Global Const RANDOMFILE = 3
  145. Global Const BINARYFILE = 4
  146.  
  147.  
  148. '**************************************************
  149. ' Declares for screen grabber function
  150. '**************************************************
  151. Type lrect
  152.     left As Integer
  153.     top As Integer
  154.  
  155.     right As Integer
  156.     bottom As Integer
  157. End Type
  158. Declare Function GetDesktopWindow Lib "user" () As Integer
  159. Declare Function GetDC Lib "user" (ByVal hWnd%) As Integer
  160.  
  161. ' Note: The following Declare should be on one line:
  162. Declare Function BitBlt Lib "GDI" (ByVal hDestDC%, ByVal X%, ByVal Y%, ByVal nWidth%, ByVal nHeight%, ByVal hSrcDC%, ByVal XSrc%, ByVal YSrc%, ByVal dwRop&) As Integer
  163. Declare Function ReleaseDC Lib "User" (ByVal hWnd As Integer, ByVal hDC As Integer) As Integer
  164.  
  165. Declare Sub GetWindowRect Lib "User" (ByVal hWnd%, lpRect As lrect)
  166. Global TwipsPerPixel As Single
  167.  
  168.  
  169. 'Other API Declarations For Sound
  170. Declare Sub MessageBeep Lib "User" (ByVal wType As Integer)
  171. Declare Sub SndPlaySound Lib "MMSystem.dll" (ByVal WavFile$, ByVal wFlags As Integer)
  172.  
  173. Sub RB_Center (str_to_print As String, line_no, skip_line As Integer)
  174.     ' ============= RB_Center ==============================
  175.     ' Will center a string passed as parameter 1
  176.     ' on printer line passed as parameter 2 or current line if parameter 2 = 0
  177.     ' Will skip to next line if parameter 3 = true
  178.     ' e.g. RB_Center "This String Will Be Centered On Line 3", 3, true
  179.     '
  180.     Dim col_to_print_at As Single
  181.     col_to_print_at = ((printer.ScaleWidth - printer.TextWidth(str_to_print)) / 2) + printer.ScaleLeft
  182.     printer.CurrentX = col_to_print_at
  183.     If line_no <> 0 Then
  184.         printer.CurrentY = line_no
  185.     End If
  186.     If skip_line Then
  187.         printer.Print str_to_print
  188.     Else
  189.         printer.Print str_to_print;
  190.     End If
  191.  
  192. End Sub
  193.  
  194. Function RB_ErrorHandler (pform As String, proutine As String) As Integer
  195.     ' =================== RB_ErrorHandler =========================
  196.     ' Displays dialog indicating error and allows user to
  197.     ' print problem report form, obtain help on error condition,
  198.     ' abort program, retry the function, or ignore the error
  199.     '
  200.     ' Example of using RB_ErrorHandler
  201.     ' erraction = RB_ErrorHandler("FormName", "Routine")
  202.     ' Select Case erraction
  203.     ' Case 1
  204.     '     Resume 0      ' Retry option selected
  205.     ' Case 2
  206.     '     Resume Next   ' Ignore option selected
  207.     ' End Select
  208.     '
  209.     ' To use in your projects include RDBLIB.BAS, RBERRFRM.FRM,
  210.     ' RBPROBRP.FRM, RBSCRN.FRM
  211.     
  212.     Dim RB_Err As Integer
  213.     Dim RB_error As String
  214.     Dim RB_errl As Long
  215.     Dim RB_Msg As String
  216.     RB_Err = Err
  217.     RB_error = Error$
  218.     RB_errl = Erl
  219.     SndPlaySound "crash.wav", 2
  220.     Beep
  221.     RB_Msg = "A " & RB_error & " error (" & RB_Err & ") has occurred"
  222.     If RB_errl <> 0 Then
  223.         RB_Msg = RB_Msg & " at line " & RB_errl
  224.     End If
  225.     RB_Msg = RB_Msg + " in routine " & proutine & " of form " & pform
  226.     RB_Msg = RB_Msg & "."
  227.     RBErrFrm.Msg.Text = RB_Msg
  228.     RBErrFrm.SvErr.Caption = RB_Err
  229.     RBErrFrm.Show MODAL
  230.     Select Case RB_Erraction
  231.     Case 0
  232.         End
  233.     Case 1
  234.         RB_ErrorHandler = RB_Erraction
  235.     Case 2
  236.         RB_ErrorHandler = RB_Erraction
  237.     End Select
  238.  
  239. End Function
  240.  
  241. Function RB_Rjustify (pnumber, pformat As String, pcol) As Single
  242.     ' ========================= RB_Rjustify ====================
  243.     ' Will print a number passed as parameter 1
  244.     ' according to the format passed as parameter 2
  245.     ' right justified on the column passed as parameter 3
  246.     ' Returns to leftmost column position where printing started
  247.     '
  248.     ' Example:
  249.     ' leftcol = RB_Rjustify(200, "###,###.##", 40)
  250.     ' will print "    200.00" with the rightmost 0 at column 40
  251.     '
  252.     Dim rbpos As Single
  253.     Dim rbstr As String
  254.     Dim rblen As Single
  255.     rbstr = Format$(pnumber, pformat)
  256.     rblen = printer.TextWidth(rbstr)
  257.     rbpos = pcol - rblen
  258.     printer.CurrentX = rbpos
  259.     printer.Print rbstr;
  260.     RB_Rjustify = rbpos
  261.  
  262. End Function
  263.  
  264. Function RB_Text_Format (instring As String, pwidth As Long)
  265.     ' ==================== RB_Text_Format ===================
  266.     ' Will return a string variable passed as parameter 1
  267.     ' formatted to print with a line length of parameter 2
  268.     ' It will break each line at the end of a word
  269.     '
  270.     ' Example:
  271.     ' newstring = RB_Text_Format(oldstring, 65)
  272.     ' Printer.Print newstring
  273.     ' will print the contents of oldstring as 65 character lines
  274.     '
  275.     Dim startpos As Integer, nextrtn As Integer, nextspace As Integer
  276.     Dim svstatpos As Integer, svwkstring As String
  277.     Dim wkstring As String, outstring As String, gotstring As Integer
  278.     outstring = ""
  279.     nextrtn = 0
  280.     startpos = 1
  281.     Do While startpos < Len(instring)
  282.         gotstring = False
  283.         nextrtn = InStr(startpos, instring, Chr$(13))
  284.         If nextrtn > 0 Then
  285.             wkstring = Mid$(instring, startpos, nextrtn - startpos + 1)
  286.             If printer.TextWidth(wkstring) < pwidth Then
  287.                 outstring = outstring + wkstring
  288.                 startpos = nextrtn + 2
  289.                 gotstring = True
  290.             End If
  291.         End If
  292.         If Not gotstring Then
  293.             wkstring = ""
  294.             Do
  295.                 svwkstring = wkstring
  296.                 svstartpos = startpos
  297.                 nextrtn = InStr(startpos, instring, " ")
  298.                 If nextrtn = 0 Then
  299.                     wkstring = wkstring + Mid$(instring, startpos)
  300.                     svwkstring = wkstring
  301.                     startpos = Len(instring) + 1
  302.                     svstartpos = startpos
  303.                 Else
  304.                     wkstring = wkstring + Mid$(instring, startpos, nextrtn - startpos + 1)
  305.                     startpos = nextrtn + 1
  306.                 End If
  307.             Loop While printer.TextWidth(wkstring) <= pwidth And startpos <= Len(instring)
  308.             startpos = svstartpos
  309.             outstring = outstring + svwkstring + Chr$(13) + Chr$(10)
  310.         End If
  311.     Loop
  312.     RB_Text_Format = outstring
  313.  
  314.  
  315. End Function
  316.  
  317. Function RB_Validate_Date (cdate As Control) As Integer
  318.     ' ================= RB_Validate_Date =====================
  319.     ' validates date contained in control passed as parameter 1
  320.     ' will return True if input is valid date, the string "__/__/__" or null
  321.     ' will display a msgbox with an "Enter a valid data" msg and return False
  322.     '      if the input date is invalid
  323.     '
  324.     ' Example:
  325.     ' TxtDate_LostFocus
  326.     '   IF Not RB_Validate_Date(TxtDate) then
  327.     '       Date.setfocus
  328.     '   End If
  329.     '
  330.     Dim wk_date As String
  331.     wk_date = cdate.Text
  332.     If wk_date = "__/__/__" Or wk_date = "" Then
  333.         RB_Validate_Date = True
  334.         cdate.Text = ""
  335.     ElseIf Not IsDate(wk_date) Then
  336.         Beep
  337.         MsgBox "Enter a valid date", , "Date Entry Error"
  338.         RB_Validate_Date = False
  339.     Else
  340.         RB_Validate_Date = True
  341.     End If
  342.  
  343. End Function
  344.  
  345. Sub ShellAndWait (CommandString$)
  346.   ' ============== ShellAndWait =====================
  347.   ' Will start (via Shell Function) the command passed as parameter 1
  348.   ' and wait until the command has completed and the window closed
  349.   '
  350.   ' Example:
  351.   ' ShellAndWait("COPY A.TXT B.TXT")
  352.   ' B.TXT will be available now
  353.   '
  354.   ID% = Shell(CommandString$, 3)
  355.   Do
  356.     X% = DoEvents()
  357.   Loop Until GetModuleUsage(ID%) = 0
  358.  
  359. End Sub
  360.  
  361.