프로그램이 돌아 그냥 튕겨져 나온다면 사용자는 황당하게 된다.
고로 개발자는 어떤 일이 있어도 프로그램이 이유없이 종료하게 하면 안된다.
에러처리는 2가지 방법이 있다.
하나는 에러를 무시, 또 다른 하나는 에러메세지 처리 후 다른 처리..
VB 문법에 on ERROR 문이 있다.
ON ERROR RESUME NEXT : 에러가 나도 계속 진행
ON ERROR GOTO 어디 : 에러가 나면 어디로 이동
ON ERROR GOTO 0 : 이전 에러 설정에 따름(이 문장을 만나면 ERR객체는 초기화 된다
ERR 객체에 유용한 것
ERR.NUMBER : 에러 번호
ERR.DESCRIPTION : 에러 메세지
예제
Public Function DB_Query() As Boolean
Dim sSql As String
Dim sSql As String
DB_Query = False '초기치를 실패로 둠
On Error GoTo Error_Code
실행 문장..
DB_Query = True '성공
Exit Function
Exit Function
Error_Code:
Screen.MousePointer = vbDefault
Call GP_Stasts("DB_Query Error") '상태항 등에 에러가 발생한 곳을 표시
MsgBox (Err.Description) '에러메세지 표시
End Function
Screen.MousePointer = vbDefault
Call GP_Stasts("DB_Query Error") '상태항 등에 에러가 발생한 곳을 표시
MsgBox (Err.Description) '에러메세지 표시
End Function
Private Sub Form_Resize()
On Error Resume Next '무조건 처리
txtExec.Width = Me.ScaleWidth - (GC_FormTitleRight * 2)
fraLink.Width = txtExec.Width
fraCond.Width = txtExec.Width
grdMaster.Width = txtExec.Width
grdMaster.Height = Me.ScaleHeight - grdMaster.Top - GC_FormTitleBottom
On Error GoTo 0 '이전 에러 설정으로 복귀
End Sub
On Error Resume Next '무조건 처리
txtExec.Width = Me.ScaleWidth - (GC_FormTitleRight * 2)
fraLink.Width = txtExec.Width
fraCond.Width = txtExec.Width
grdMaster.Width = txtExec.Width
grdMaster.Height = Me.ScaleHeight - grdMaster.Top - GC_FormTitleBottom
On Error GoTo 0 '이전 에러 설정으로 복귀
End Sub
'VB,크리스탈레포트' 카테고리의 다른 글
[VB]이름변경 프로그램, 소스 (0) | 2009.04.29 |
---|---|
[VB]네트워크 연결 프로그램 소스,실행파일 (0) | 2009.04.29 |
[크리스탈레포트]결과값 제어 (0) | 2009.04.29 |
[VB]크리스탈레포트 DB연결 에러 (0) | 2009.04.29 |
[VB]스프레드 길이 자동조정 모듈 (0) | 2009.04.29 |