home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 26 / CD_ASCQ_26_1295.iso / vrac / sbardemo.zip / CONSTANT.GLB next >
Text File  |  1995-08-18  |  10KB  |  266 lines

  1. Option Explicit
  2.  
  3. '********************************************************************************
  4. '*                          Message Box Constants                               *
  5. '********************************************************************************
  6. ' Function Parameters
  7. ' MsgBox parameters
  8. Global Const MB_OK = 0                 ' OK button only
  9. Global Const MB_OKCANCEL = 1           ' OK and Cancel buttons
  10. Global Const MB_ABORTRETRYIGNORE = 2   ' Abort, Retry, and Ignore buttons
  11. Global Const MB_YESNOCANCEL = 3        ' Yes, No, and Cancel buttons
  12. Global Const MB_YESNO = 4              ' Yes and No buttons
  13. Global Const MB_RETRYCANCEL = 5        ' Retry and Cancel buttons
  14.  
  15. Global Const MB_ICONSTOP = 16          ' Critical message
  16. Global Const MB_ICONQUESTION = 32      ' Warning query
  17. Global Const MB_ICONEXCLAMATION = 48   ' Warning message
  18. Global Const MB_ICONINFORMATION = 64   ' Information message
  19.  
  20. ' MsgBox return values
  21. Global Const IDOK = 1                  ' OK button pressed
  22. Global Const IDCANCEL = 2              ' Cancel button pressed
  23. Global Const IDABORT = 3               ' Abort button pressed
  24. Global Const IDRETRY = 4               ' Retry button pressed
  25. Global Const IDIGNORE = 5              ' Ignore button pressed
  26. Global Const IDYES = 6                 ' Yes button pressed
  27. Global Const IDNO = 7                  ' No button pressed
  28.  
  29. 'File Handle types..
  30. Global Const FILEIO_INPUT = 1
  31. Global Const FILEIO_OUTPUT = 2
  32. Global Const FILEIO_RANDOM = 3
  33. Global Const FILEIO_APPEND = 4
  34. Global Const FILEIO_BINARY = 5
  35. Global Const FILEIO_BINARY_READ = 6
  36. Global Const FILEIO_BINARY_WRITE = 7
  37. Global Const FILEIO_RANDOMSHARED = 8
  38.  
  39. 'LoadFileToTextBox Errors
  40. Global Const TB_NOTMULTILINE = 28001
  41. Global Const TB_FILETOOBIG = 28002
  42.  
  43. '********************************************************************************
  44. '*                          Send Message API Call                               *
  45. '********************************************************************************
  46. Declare Function SendMessage Lib "User" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
  47. Global Const WM_USER = &H400
  48. Global Const EM_SETREADONLY = WM_USER + 31
  49.  
  50. Function GetNewFileHandle (ByVal psFile$, ByVal piAccess%, ByVal piRecLen%, piOpenErr%) As Integer
  51.  
  52. '
  53. '***************************************************************
  54. '*   Name of Function:  GetNewFileHandle                       *
  55. '*   Name of File:      FILEIO.BAS                             *
  56. '*   Author:            M. John Rodriguez                      *
  57. '*   Date Created:      Jun 14, 1995                           *
  58. '*   Last Modified:                                            *
  59. '***************************************************************
  60. 'Parameters:
  61. '   psFile$         complete path of the file to be opened (String)
  62. '   piAccess%       type of access - see below (Integer)
  63. '   piRecLen%       length of the record for random files  (Integer)
  64. '   piOpenErr%      Returned Error Code if any (Integer)
  65. 'Local Variables
  66. '   hf%             Handle to the newly opened file
  67. '   iErr%           Error returned from the opening...
  68.  
  69. On Local Error Resume Next
  70.  
  71. Dim hf%, iErr%
  72.  
  73. 'Start the loop
  74. Do
  75.     'Get the handle
  76.     hf% = OpenFile(psFile$, piAccess%, piRecLen%, iErr%)
  77.     'Let windows do something
  78.     DoEvents
  79. Loop While hf% = 0 And iErr% = -1   'Loop to will get a handle or an error
  80.  
  81. If hf% = 0 Then                 'If we didn't get the handle ...
  82.     piOpenErr% = iErr%          'Return the error back to the caller
  83. Else                            'Otherwise
  84.     GetNewFileHandle = hf%      'Return the file handle
  85. End If
  86.  
  87. End Function
  88.  
  89. Function LoadFileToTextBox (ctrlTextBox As TextBox, ByVal psFileName$, piErr%) As Integer
  90.  
  91. '***************************************************************
  92. '*   Name of Function:  LoadFileToTextBox                      *
  93. '*   Name of File:      FILEIO.BAS                             *
  94. '*   Author:            M. John Rodriguez                      *
  95. '*   Date Created:      Jun 16, 1995                           *
  96. '*   Last Modified:                                            *
  97. '***************************************************************
  98. 'Parameters:
  99. '   ctrlTextBox     TextBox that will contain the file contents
  100. '   psFileName$     Name of the File containing the text to load
  101. '   piErr%          Error Returned to the user in case of failure
  102. 'Local Variables
  103. '   ifh%            File Handle
  104. '   sBufferData$    Holds the data from the file
  105. '   iErr%           File Opening error
  106. '   lFileLen&       Length of file
  107.  
  108. 'This procedure loads a text file into a multiline text box.  Designed to provide
  109. 'a quick method of loading text information.
  110.  
  111. On Local Error Resume Next
  112.  
  113. Dim ifh%, sBufferData$, iErr%, lFileLen&
  114.  
  115. If Not ctrlTextBox.MultiLine Then           'If this is not a multiline box
  116.     piErr% = TB_NOTMULTILINE                'Return the error code
  117.     Exit Function                           'Exit the function
  118. End If
  119.  
  120. lFileLen& = FileLen(psFileName$)
  121.  
  122. If Err <> 0 Then
  123.     piErr% = Err
  124.     ctrlTextBox.Text = "No text available. Error: " + Error$(Err)
  125.     Exit Function
  126. End If
  127.  
  128. If lFileLen& > 30000 Then        'If the file is bigger than 30K
  129.     piErr% = TB_FILETOOBIG      'Return File too big error
  130.     ctrlTextBox.Text = "No text available. Error: File Too Big"
  131.     Exit Function
  132. End If
  133.  
  134. 'Get a new file handle
  135. ifh% = GetNewFileHandle(psFileName$, FILEIO_BINARY_READ, 0, iErr%)
  136.  
  137. If ifh% = 0 Then            'IF we didn't get one then
  138.     piErr% = iErr%          'Return the error to the caller
  139.     ctrlTextBox.Text = "No text available. Error: " + Error$(iErr%)
  140.     Exit Function           'Exit the function
  141. End If
  142.  
  143. Err = 0
  144. sBufferData$ = String$(LOF(ifh%), Chr$(0))
  145. Get #ifh%, , sBufferData$
  146. ctrlTextBox.Text = sBufferData$
  147. Close ifh%
  148.  
  149. If Err = 0 Then
  150.     LoadFileToTextBox = True
  151. Else
  152.     piErr% = Err
  153. End If
  154.  
  155. sBufferData$ = ""
  156.  
  157. End Function
  158.  
  159. Function OpenFile (ByVal psFile$, ByVal piFileAccess%, ByVal piRecLength%, piFileErr%) As Integer
  160. '
  161. '***************************************************************
  162. '*   Name of Function:  OpenFile                               *
  163. '*   Name of File:      FILEIO.BAS                             *
  164. '*   Author:            M. John Rodriguez                      *
  165. '*   Date Created:      Jan 15, 1995                           *
  166. '*   Last Modified:     Apr 12, 1995                           *
  167. '***************************************************************
  168. 'Parameters:
  169. '   psFile$           complete path of the file to be opened (String)
  170. '   piFileAccess%     type of access - see below (Integer)
  171. '   piRecLength%      length of the record for random files  (Integer)
  172. '   piFileErr%        Returned Error Code if any (Integer)
  173. 'Local Variables
  174. '   hFile%          handle to the open file (Integer)
  175. '   iMB_Ans%        Answer returned from MessageBox on Error (Integer)
  176. '   sCurDisk$       drive referenced by the psFile$ (String)
  177. '   sTemp$          Temporary String Variable (String)
  178. '   bBusy%          This get's done one at a time so as not to corrupt files
  179.  
  180. Static bBusy%
  181.  
  182. 'Create a file handle variable
  183. Dim hFile%, iMB_Ans%, sCurDisk$, sTemp$
  184.  
  185. If bBusy% Then piFileErr% = -1: Exit Function
  186.  
  187. bBusy% = True
  188.  
  189. 'Set out error checking
  190. On Local Error GoTo OpenFile_Error
  191.  
  192. 'Here is where we start for our error loop
  193. OpenFile_Start:
  194.     
  195.     'Reset the error number...
  196.     Err = 0
  197.     
  198.     'Get the next instance of an available file handle...
  199.     hFile% = FreeFile
  200.     
  201.     'Open the file:
  202.     Select Case piFileAccess%
  203.         Case FILEIO_INPUT           'Input
  204.             Open psFile$ For Input As #hFile%
  205.         Case FILEIO_OUTPUT          'Output
  206.             Open psFile$ For Output As #hFile%
  207.         Case FILEIO_RANDOM          'Random
  208.             Open psFile$ For Random As #hFile% Len = piRecLength%
  209.         Case FILEIO_APPEND          'Append
  210.             Open psFile$ For Append As #hFile%
  211.         Case FILEIO_BINARY          'Binary Files
  212.             Open psFile$ For Binary As #hFile%
  213.         Case FILEIO_BINARY_READ      'Binary Read-Only Files
  214.             Open psFile$ For Binary Access Read As #hFile%
  215.         Case FILEIO_BINARY_WRITE     'Binary Write-Only Files
  216.             Open psFile$ For Binary Access Write As #hFile%
  217.         Case FILEIO_RANDOMSHARED
  218.             Open psFile$ For Random Shared As #hFile% Len = piRecLength%
  219.     End Select
  220.     
  221.     'If successful then we return the handle...
  222.     OpenFile = hFile%
  223.     GoTo OpenFile_Exit
  224.  
  225. OpenFile_Error:
  226.     Select Case Err
  227.         Case 71                 'Disk Drive Not Ready..
  228.             'First, we need to get the first two characters that represent the drive
  229.             sTemp$ = Left$(psFile$, 2)
  230.             'if the second character is not a ":"
  231.             If Right$(sTemp$, 1) <> ":" Then
  232.                 'we must be referencing the current drive
  233.                 sCurDisk$ = Left$(CurDir$, 2)
  234.             Else
  235.                 sCurDisk$ = sTemp$
  236.             End If
  237.             iMB_Ans% = MsgBox("Drive " + sCurDisk$ + " is not ready.", MB_ICONSTOP + MB_RETRYCANCEL, App.Title)
  238.             If iMB_Ans% = IDCANCEL Then
  239.                 piFileErr% = 71
  240.                 Resume OpenFile_Exit:
  241.             Else
  242.                 Resume OpenFile_Start
  243.             End If
  244.         Case Else
  245.             'Return the error to the user in the piFileErr% parameter.
  246.             piFileErr% = Err
  247.             Resume OpenFile_Exit:
  248.     End Select
  249.  
  250. OpenFile_Exit:
  251.  
  252. bBusy% = False
  253.  
  254. End Function
  255.  
  256. Function ReadOnlyTextBox (ctrlTextBox As TextBox) As Integer
  257.  
  258. Dim iRet%
  259.  
  260. iRet% = SendMessage(ctrlTextBox.hWnd, EM_SETREADONLY, True, 0&)
  261.  
  262. ReadOnlyTextBox = iRet%
  263.  
  264. End Function
  265.  
  266.