下面通过程序来介绍,运行下面的程序,首先要在Form中加入一个ListBox和CommandButton在将下面的代码加入到form的代码窗口中。
Private Declare Function FormatMessage Lib 'kernel32' _
Alias 'FormatMessageA' (ByVal dwFlags As Long, _
lpSource As Any, ByVal dwMessageId As Long, _
ByVal dwLanguageId As Long, ByVal lpBuffer _
As String, ByVal nSize As Long, Arguments As _
Long) As Long
Private Declare Function GetLastError Lib 'kernel32' _
() As Long
Private Declare Function CloseHandle Lib 'kernel32' _
(ByVal hObject As Long) As Long
Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
Const FORMAT_MESSAGE_IGNORE_INSERTS = &H200
Private Sub Command1_Click()
Dim ErrID As Long
Dim astr As String
Dim bstr As String
Dim l As Long
astr = String$(256, 20)
'获得具体的错误信息
For ErrID = 0 To 8191
l = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM Or _
FORMAT_MESSAGE_IGNORE_INSERTS, 0&, ErrID, 0&, _
astr, Len(astr), ByVal 0)
If l Then
bstr = Left$(astr, InStr(astr, Chr(10)) - 2)
'将错误信息加入列表框
List1.AddItem Str(ErrID) + ' ' + bstr
End If
Next ErrID
End Sub
运行程序,点击Command1,错误代码和向对应的错误提示信息就全部列在ListBox中了。以上程序在Win95,VB5.0下运行通过。
本文来自 280文秘网(https://www.it280.com),转载请保留网址和出处
【VisualBasic辅导:编程获得系统错误信息提示】相关文章:
儿童舞蹈教程:国标新手上路03-23
2024年江苏中级导游等级考试准考证打印时间及入口(11月18日9:00起)03-23
盐阜大众报报业集团(盐城)公开招聘《东方生活报》编辑记者的公告 2月25日到3月3日报名03-23
2018湖南省农村信用社联合社招聘科技专业人才拟聘公告03-23
5月11日开始报名!2023年内蒙古鄂尔多斯市乌审旗秋季幼升小入学条件和流程公布03-23
初中学校德育课程整合实施探究03-23
元旦节送给长辈的祝福短信03-23
2015年美国化学工程专业排名03-23
