home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Programmer'…arterly (Limited Edition)
/
Visual_Basic_Programmers_Journal_VB-CD_Quarterly_Limited_Edition_1995.iso
/
code
/
ch29code
/
frmlomem.frm
(
.txt
)
< prev
next >
Wrap
Visual Basic Form
|
1995-08-02
|
5KB
|
116 lines
VERSION 4.00
Begin VB.Form frmLowMem
BackColor = &H00C0C0C0&
BorderStyle = 3 'Fixed Dialog
ClientHeight = 285
ClientLeft = 1080
ClientTop = 1515
ClientWidth = 3105
ControlBox = 0 'False
Height = 690
Left = 1020
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 285
ScaleWidth = 3105
Top = 1170
Width = 3225
Begin MSComDlg.CommonDialog cdlg
Left = 45
Top = -135
_Version = 65536
_ExtentX = 847
_ExtentY = 847
_StockProps = 0
CancelError = -1 'True
DialogTitle = "Select a Test Application"
FileName = "write.exe"
Filter = "Applications (*.exe)|*.exe"
FilterIndex = 1
End
Begin VB.Label lblMsg
Alignment = 2 'Center
BackStyle = 0 'Transparent
Caption = "Label1"
Height = 195
Left = 135
TabIndex = 0
Top = 45
Width = 2685
End
Attribute VB_Name = "frmLowMem"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
'************************************************************
' FRMLOMEM.FRM - Demonstrates good error handling techniques.
'************************************************************
Option Explicit
'************************************************************
' Centers the form
'************************************************************
Private Sub Form_Load()
'********************************************************
' Tell your app where to go when a error occurs.
'********************************************************
On Error GoTo Form_Load_Err
'********************************************************
' Center the form and the label.
'********************************************************
Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 2
lblMsg.Move (ScaleWidth - lblMsg.Width) / 2, _
(ScaleHeight - lblMsg.Height) / 2
'********************************************************
' Raise an error to simulate a low memory situation.
'********************************************************
Err.Raise InputBox("Enter a error number:", Default:=7)
Exit Sub
Form_Load_Err:
'********************************************************
' When a error is triggered, jump to the error handler.
'********************************************************
ErrHandler Err.Number, "Form_Load"
End
End Sub
'************************************************************
' A generic error handler.
'************************************************************
Sub ErrHandler(iErr%, sCallingProc$)
Dim msg$, res%
'********************************************************
' Prevent crashes in your error handler with Resume Next
'********************************************************
On Error Resume Next
'********************************************************
' If out of memory error, then tell use to free memory
'********************************************************
If iErr = 7 Or iErr = 31001 Then
'****************************************************
' Here is a good place to unload any picture boxes,
' hide unnecessary controls, close DDE links or OLE
' objects, erase arrays, and set object variables
' = Nothing.
'****************************************************
msg = "Your system is extremely low on memory, so "
msg = msg & "please close any applications "
msg = msg & "that you (or this application) are "
msg = msg & "not using."
'********************************************************
' Otherwise tell the user what error occurred, and where
' it was triggered. (This is useful during tech support
' calls).
'********************************************************
Else
msg = "A """ & Error(iErr) & """ error has occurred "
msg = msg & "in this applications " & sCallingProc
msg = msg & " procedure. " & vbLf & vbLf & "Please "
msg = msg & "consult ""Appendix E: Error Messages"" "
msg = msg & "for instructions on how to correct "
msg = msg & "this error."
End If
'********************************************************
' Display the appropriate error message.
'********************************************************
MsgBox msg, vbExclamation
End Sub