home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Software Sampler / Visual_Basic_Software_Sampler_Visual_Basic_Programmers_Journal_June_1996.iso / issues / 04apr96 / code / p117.txt < prev    next >
Text File  |  1996-04-24  |  2KB  |  62 lines

  1.  [[listing 1]]
  2. [[VB4]]
  3. Declare Function FormatMessage Lib "kernel32" _
  4.      Alias "FormatMessageA" _
  5.     (ByVal dwFlags As Long, _
  6.      lpSource As Long, _
  7.      ByVal dwMessageId As Long, _
  8.      ByVal dwLanguageId As Long, _
  9.      ByVal lpBuffer As String, _
  10.      ByVal nSize As Long, _
  11.      Arguments As Long) As Long
  12. Public Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
  13. Public Const FORMAT_MESSAGE_IGNORE_INSERTS = &H200
  14. Private Sub cmdFormat_Click()
  15.     Dim sBuff As String
  16.     Dim lMsgId As Long
  17.     sBuff = String(256, " ")
  18.     lMsgId = CLng(Val(txtID))
  19.     ret& = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM Or _
  20.         FORMAT_MESSAGE_IGNORE_INSERTS, _
  21.         0&, lMsgId, 0&, sBuff, Len(sBuff), 0&)
  22.     lblMessage = sBuff
  23. End Sub
  24.  
  25. [[listing 2]]
  26. [[VB4]]
  27. Private Const errFetchOne = vbObjectError + 2001
  28. Private Const errFetchTwo = vbObjectError + 2002
  29. Private Const errFetchDefault = vbObjectError + 2000
  30. Private Const errFetchExternal = vbObjectError + 2999
  31.  
  32. Public Sub Fetch()
  33.     On Error GoTo ErrHandler
  34.     '...Code goes here
  35.     Exit Sub
  36.  
  37. ErrHandler:
  38.     If Err.Source <> DefaultErrSource Then  
  39.         'External error
  40.         Err.Raise _
  41.             Number:=errFetchExternal, _
  42.             Source:=DefaultErrSource _
  43.                 & "[" &Err.Source & "]"
  44.     Else
  45.     Select Case Err.Number
  46.     Case errFetchOne
  47.         Err.Raise _
  48.         Number:=errFetchOne, _
  49.         Description:=LoadResString(errFetchOne)
  50.     'Case errFetchTwo...
  51.     Case Else
  52.         Err.Raise _
  53.         Number:=errFetchDefault, _
  54.         Description:=LoadResString(errFetchDefault)
  55.     End Select
  56.     End If
  57. End Sub
  58.  
  59. 1    02/06/96    10:03 AM
  60.  
  61.  
  62.