资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

vb点虐 事件日志的简单介绍

请教高手,如何用vb实现“使用日志”?

很多种方法,最常用的一是用文本文件或数据库记录,二是调用API函数直接写入系统日志或应用程序日志

创新互联专业为企业提供自流井网站建设、自流井做网站、自流井网站设计、自流井网站制作等企业网站建设、网页设计与制作、自流井企业网站模板建站服务,十余年自流井做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

在vb点虐 中,记录系统错误日志这个功能怎么实现

Public Sub ShowError(strModule As String, strProcedure As String, lngErrorNumber As Long, strErrorDescription As String, showMsg As String)

'

'错误处理中心过程,写数据库日志表或写日志文件

'

'strModule '模块名称

'strProcedure '过程名称

'lngErrorNumber '错误ID号

'strErrorDescription '错误描述

'showMsg '是否显示本过程内错误显示信息(值:"Y" or "N")

'Error表结构(f001 (Date)发生时间, f002 (nvarchar50)模块名称, f003 (nvarchar50)过程名称, f004 (nvarchar50)错误ID号, _

f005 (nvarchar300)错误描述,f006 (nvarchar50)版 本 号, f007 (nvarchar50)用户名称, f008 (nvarchar50)网卡地址

'ErrorCode表结构 f001 (nvarchar20)错误代码, f002 (nvarchar255)错误信息, f003 (numeric9)错误级别

' 级别说明: '10'以下,一般错误,不影响操作

' '11-20',严重错误,不能操作,程序执行退出

On Error GoTo ErrorHandle

Dim strMessage As String

Dim strCaption As String

Dim sVer As String

Dim intLogFile As Integer

Dim Res As New ADODB.Recordset

Dim ResErrorCode As New ADODB.Recordset

Dim strSQL As String

'对应错误号,从ErrorCode表中找到对应的错误信息,0-1000 错误号保留给VB

DBOpen ResErrorCode, "select * from errorcode where f001='" lngErrorNumber "'"

If Not (ResErrorCode.EOF Or ResErrorCode.BOF) Then

strMessage = ResErrorCode.Fields("f002")

If ResErrorCode.Fields("f003") 10 Then

MsgBox "产生一个严重错误,可能影响到系统的可操作性,请立即联系本系统开发人员!", vbCritical, "严重错误"

End If

End If

'写错误入文件----------------------------

intLogFile = FreeFile

Open App.Path "\" strIni.LogFile For Append As #intLogFile

Print #intLogFile, "***错误"; VBA.Now "*** " "Version:" _

str$(App.Major) "." str$(App.Minor) "." Format(App.Revision, "0000")

Print #intLogFile, "Error: " lngErrorNumber

Print #intLogFile, "Description: " strErrorDescription

Print #intLogFile, "Module: " strModule

Print #intLogFile, "Procedure: " strProcedure

Print #intLogFile, ""

Close #intLogFile

If Len(strMessage) 2 Then strErrorDescription = strMessage

strMessage = "错误: " "(" lngErrorNumber ")" strErrorDescription vbCrLf vbCrLf _

"模块:" strModule "; 过程:" strProcedure

sVer = Trim(str$(App.Major) "." str$(App.Minor) "." _

Format(App.Revision, "0000"))

strCaption = "错误 Version: " sVer

'写错误入数据库表--------------------------

strSQL = "insert into error(f001,f002,f003,f004,f005,f006,f007,f008) values(" _

DateFmtB VBA.Now DateFmtE "," _

IIf(Len(Trim(strModule)) = 0, "null", "'" strModule "'") "," _

IIf(Len(Trim(strProcedure)) = 0, "null", "'" strProcedure "'") "," _

IIf(Len(Trim(lngErrorNumber)) = 0, "null", "'" lngErrorNumber "'") "," _

IIf(Len(Trim(strErrorDescription)) = 0, "null", "'" Replace(strErrorDescription, "'", "") "'") "," _

IIf(Len(Trim(sVer)) = 0, "null", "'" sVer "'") "," _

IIf(Len(Trim(sUserName)) = 0, "null", "'" sUserName "'") "," _

IIf(Len(Trim(sVer)) = 0, "null", "'" EthernetNO "'") ")"

Cn.Execute strSQL

'是否显示未知错误信息

If Trim(UCase(showMsg)) = "Y" Then MsgBox strMessage, vbCritical, strCaption

PROC_EXIT:

Set Res = Nothing

Set ResErrorCode = Nothing

Exit Sub

ErrorHandle:

Resume Next

关于VB编程

首先,二者所使用的软件不一样,Visual Basic 6使用的是Visual Studio 6.0环境;Visual Basic.NET使用的是Visual Basic.NET 2003/2005环境。

Visual Basic.NET与早期VB程序设计语言的主要区别在于以下五个方面:

1. Visual Basic.NET支持微软最新推出的ADO.NET和ActiveX Data Objects(ADO)功能。程序员可以通过ADO把基于XML的数据绑定到数据库、类、集合,以及数组中使用。

2. Visual Basic.NET首次全面支持面向对象的程序结构,允许程序员创建组件化的可复用代码资源。Visual Basic.NET不仅支持对象的继承、封装、多态性等对象特征,而且还允许开发人员在程序中构造可运行在各类操作系统平台上的XML Web服务。

3. Visual Basic.NET新增的调试和跟踪功能允许应用程序直接访问操作系统的注册表、事件日志、性能计数器和文件系统等系统资源。

4. Visual Basic.NET在安全方面为程序员提供了强有力的工具。借助于对微软.NET架构的直接访问,程序员可以通过.NET架构提供的多种安全模式对其应用实现各种粒度的安全控制。

5. 借助于Visual Basic.NET提供的移动设备互联工具,程序员可以针对80种以上的移动设备开发各种无线应用。


新闻名称:vb点虐 事件日志的简单介绍
URL链接:http://cdkjz.cn/article/ddedgoh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220