home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 26
/
CD_ASCQ_26_1295.iso
/
vrac
/
sbardemo.zip
/
CONSTANT.GLB
next >
Wrap
Text File
|
1995-08-18
|
10KB
|
266 lines
Option Explicit
'********************************************************************************
'* Message Box Constants *
'********************************************************************************
' Function Parameters
' MsgBox parameters
Global Const MB_OK = 0 ' OK button only
Global Const MB_OKCANCEL = 1 ' OK and Cancel buttons
Global Const MB_ABORTRETRYIGNORE = 2 ' Abort, Retry, and Ignore buttons
Global Const MB_YESNOCANCEL = 3 ' Yes, No, and Cancel buttons
Global Const MB_YESNO = 4 ' Yes and No buttons
Global Const MB_RETRYCANCEL = 5 ' Retry and Cancel buttons
Global Const MB_ICONSTOP = 16 ' Critical message
Global Const MB_ICONQUESTION = 32 ' Warning query
Global Const MB_ICONEXCLAMATION = 48 ' Warning message
Global Const MB_ICONINFORMATION = 64 ' Information message
' MsgBox return values
Global Const IDOK = 1 ' OK button pressed
Global Const IDCANCEL = 2 ' Cancel button pressed
Global Const IDABORT = 3 ' Abort button pressed
Global Const IDRETRY = 4 ' Retry button pressed
Global Const IDIGNORE = 5 ' Ignore button pressed
Global Const IDYES = 6 ' Yes button pressed
Global Const IDNO = 7 ' No button pressed
'File Handle types..
Global Const FILEIO_INPUT = 1
Global Const FILEIO_OUTPUT = 2
Global Const FILEIO_RANDOM = 3
Global Const FILEIO_APPEND = 4
Global Const FILEIO_BINARY = 5
Global Const FILEIO_BINARY_READ = 6
Global Const FILEIO_BINARY_WRITE = 7
Global Const FILEIO_RANDOMSHARED = 8
'LoadFileToTextBox Errors
Global Const TB_NOTMULTILINE = 28001
Global Const TB_FILETOOBIG = 28002
'********************************************************************************
'* Send Message API Call *
'********************************************************************************
Declare Function SendMessage Lib "User" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
Global Const WM_USER = &H400
Global Const EM_SETREADONLY = WM_USER + 31
Function GetNewFileHandle (ByVal psFile$, ByVal piAccess%, ByVal piRecLen%, piOpenErr%) As Integer
'
'***************************************************************
'* Name of Function: GetNewFileHandle *
'* Name of File: FILEIO.BAS *
'* Author: M. John Rodriguez *
'* Date Created: Jun 14, 1995 *
'* Last Modified: *
'***************************************************************
'Parameters:
' psFile$ complete path of the file to be opened (String)
' piAccess% type of access - see below (Integer)
' piRecLen% length of the record for random files (Integer)
' piOpenErr% Returned Error Code if any (Integer)
'Local Variables
' hf% Handle to the newly opened file
' iErr% Error returned from the opening...
On Local Error Resume Next
Dim hf%, iErr%
'Start the loop
Do
'Get the handle
hf% = OpenFile(psFile$, piAccess%, piRecLen%, iErr%)
'Let windows do something
DoEvents
Loop While hf% = 0 And iErr% = -1 'Loop to will get a handle or an error
If hf% = 0 Then 'If we didn't get the handle ...
piOpenErr% = iErr% 'Return the error back to the caller
Else 'Otherwise
GetNewFileHandle = hf% 'Return the file handle
End If
End Function
Function LoadFileToTextBox (ctrlTextBox As TextBox, ByVal psFileName$, piErr%) As Integer
'***************************************************************
'* Name of Function: LoadFileToTextBox *
'* Name of File: FILEIO.BAS *
'* Author: M. John Rodriguez *
'* Date Created: Jun 16, 1995 *
'* Last Modified: *
'***************************************************************
'Parameters:
' ctrlTextBox TextBox that will contain the file contents
' psFileName$ Name of the File containing the text to load
' piErr% Error Returned to the user in case of failure
'Local Variables
' ifh% File Handle
' sBufferData$ Holds the data from the file
' iErr% File Opening error
' lFileLen& Length of file
'This procedure loads a text file into a multiline text box. Designed to provide
'a quick method of loading text information.
On Local Error Resume Next
Dim ifh%, sBufferData$, iErr%, lFileLen&
If Not ctrlTextBox.MultiLine Then 'If this is not a multiline box
piErr% = TB_NOTMULTILINE 'Return the error code
Exit Function 'Exit the function
End If
lFileLen& = FileLen(psFileName$)
If Err <> 0 Then
piErr% = Err
ctrlTextBox.Text = "No text available. Error: " + Error$(Err)
Exit Function
End If
If lFileLen& > 30000 Then 'If the file is bigger than 30K
piErr% = TB_FILETOOBIG 'Return File too big error
ctrlTextBox.Text = "No text available. Error: File Too Big"
Exit Function
End If
'Get a new file handle
ifh% = GetNewFileHandle(psFileName$, FILEIO_BINARY_READ, 0, iErr%)
If ifh% = 0 Then 'IF we didn't get one then
piErr% = iErr% 'Return the error to the caller
ctrlTextBox.Text = "No text available. Error: " + Error$(iErr%)
Exit Function 'Exit the function
End If
Err = 0
sBufferData$ = String$(LOF(ifh%), Chr$(0))
Get #ifh%, , sBufferData$
ctrlTextBox.Text = sBufferData$
Close ifh%
If Err = 0 Then
LoadFileToTextBox = True
Else
piErr% = Err
End If
sBufferData$ = ""
End Function
Function OpenFile (ByVal psFile$, ByVal piFileAccess%, ByVal piRecLength%, piFileErr%) As Integer
'
'***************************************************************
'* Name of Function: OpenFile *
'* Name of File: FILEIO.BAS *
'* Author: M. John Rodriguez *
'* Date Created: Jan 15, 1995 *
'* Last Modified: Apr 12, 1995 *
'***************************************************************
'Parameters:
' psFile$ complete path of the file to be opened (String)
' piFileAccess% type of access - see below (Integer)
' piRecLength% length of the record for random files (Integer)
' piFileErr% Returned Error Code if any (Integer)
'Local Variables
' hFile% handle to the open file (Integer)
' iMB_Ans% Answer returned from MessageBox on Error (Integer)
' sCurDisk$ drive referenced by the psFile$ (String)
' sTemp$ Temporary String Variable (String)
' bBusy% This get's done one at a time so as not to corrupt files
Static bBusy%
'Create a file handle variable
Dim hFile%, iMB_Ans%, sCurDisk$, sTemp$
If bBusy% Then piFileErr% = -1: Exit Function
bBusy% = True
'Set out error checking
On Local Error GoTo OpenFile_Error
'Here is where we start for our error loop
OpenFile_Start:
'Reset the error number...
Err = 0
'Get the next instance of an available file handle...
hFile% = FreeFile
'Open the file:
Select Case piFileAccess%
Case FILEIO_INPUT 'Input
Open psFile$ For Input As #hFile%
Case FILEIO_OUTPUT 'Output
Open psFile$ For Output As #hFile%
Case FILEIO_RANDOM 'Random
Open psFile$ For Random As #hFile% Len = piRecLength%
Case FILEIO_APPEND 'Append
Open psFile$ For Append As #hFile%
Case FILEIO_BINARY 'Binary Files
Open psFile$ For Binary As #hFile%
Case FILEIO_BINARY_READ 'Binary Read-Only Files
Open psFile$ For Binary Access Read As #hFile%
Case FILEIO_BINARY_WRITE 'Binary Write-Only Files
Open psFile$ For Binary Access Write As #hFile%
Case FILEIO_RANDOMSHARED
Open psFile$ For Random Shared As #hFile% Len = piRecLength%
End Select
'If successful then we return the handle...
OpenFile = hFile%
GoTo OpenFile_Exit
OpenFile_Error:
Select Case Err
Case 71 'Disk Drive Not Ready..
'First, we need to get the first two characters that represent the drive
sTemp$ = Left$(psFile$, 2)
'if the second character is not a ":"
If Right$(sTemp$, 1) <> ":" Then
'we must be referencing the current drive
sCurDisk$ = Left$(CurDir$, 2)
Else
sCurDisk$ = sTemp$
End If
iMB_Ans% = MsgBox("Drive " + sCurDisk$ + " is not ready.", MB_ICONSTOP + MB_RETRYCANCEL, App.Title)
If iMB_Ans% = IDCANCEL Then
piFileErr% = 71
Resume OpenFile_Exit:
Else
Resume OpenFile_Start
End If
Case Else
'Return the error to the user in the piFileErr% parameter.
piFileErr% = Err
Resume OpenFile_Exit:
End Select
OpenFile_Exit:
bBusy% = False
End Function
Function ReadOnlyTextBox (ctrlTextBox As TextBox) As Integer
Dim iRet%
iRet% = SendMessage(ctrlTextBox.hWnd, EM_SETREADONLY, True, 0&)
ReadOnlyTextBox = iRet%
End Function