让Pb自动提示运行时错误

来源:互联网 发布:plc显示屏编程 编辑:程序博客网 时间:2024/05/18 02:39


将一下代码复制到应用程序的systemerror事件中,当应用程序运行时出错会自动弹出提示框。

 

String ls_ErrorMessge
String ls_DocName
Integer li_FileNum, li_Return

Choose Case Error.Number
 Case 1 //1 Divide by zero
  ls_ErrorMessge = "发生被 0 除错误"
 Case 2 //2 Null o b j e c t reference
  ls_ErrorMessge = "空对象引用"
 Case 3 //3 Array boundary exceeded
  ls_ErrorMessge = "数组越界"
 Case 4 //4 Enumerated value is out of range for function
  ls_ErrorMessge = "枚举值超出函数的范围"
 Case 5 //5 Negative value encountered in function
  ls_ErrorMessge = "函数中遇到负数"
 Case 6 //6 Invalid DataWindow row/column specified
  ls_ErrorMessge = "数据窗口的列或行非法"
 Case 7 //7 Unresolvable external when linking reference
  ls_ErrorMessge = "链接调用时不能解决外部对象"
 Case 8 //8 Reference of array with null subscript
  ls_ErrorMessge = "使用空下标引用数组"
 Case 9 //9 DLL function not found in current application
  ls_ErrorMessge = "当前应用中没有找到动态链接库的函数"
 Case 10 //10 Unsupported argument type in DLL function
  ls_ErrorMessge = "使用了动态链接库函数不支持的参数类型"
 Case 11 //11 Object file is out of date and must be converted to current version
  ls_ErrorMessge = "对象文件已经过时并且必须使用当前的版本"
 Case 12 //12 DataWindow column type does not match GetItem type
  ls_ErrorMessge = "数据窗口的列的数据类型与GetItem函数的类型不符"
 Case 13 //13 Unresolved property reference
  ls_ErrorMessge = "属性引用尚未解决"
 Case 14 //14 Error opening DLL library for external function
  ls_ErrorMessge = "为外部函数调用而打开动态链接库时发生错误"
 Case 15 //15 Error calling external function name
  ls_ErrorMessge = "调用外部函数时发生错误"
 Case 16 //16 Maximum string size exceeded
  ls_ErrorMessge = "字符串长度超越了最大限制"
 Case 17 //17 DataWindow referenced in DataWindow o b j e c t does not exist
  ls_ErrorMessge = "数据窗口引用的数据窗口对象不存在"
 Case 18 //18 Function doesn't return value
  ls_ErrorMessge = "函数没有返回值(应该有而没有)"
 Case 19 //19 Cannot convert name in Any variable to name
  ls_ErrorMessge = "不能转换Any类型的变量到另一个类型"
 Case 20 //20 Database command has not been successfully prepared
  ls_ErrorMessge = "数据库命令没有成功准备"
 Case 21 //21 Bad runtime function reference
  ls_ErrorMessge = "引用了错误的运行时函数"
 Case 22 //22 Unknown o b j e c t type
  ls_ErrorMessge = "不知道的对象类型"
 Case 23 //23 Cannot assign o b j e c t of type name to variable of type name
  ls_ErrorMessge = "不能将对象赋给变量,两种类型不能赋值"
 Case 24 //24 Function call doesn't match its definition
  ls_ErrorMessge = "函数调用格式与其定义不一致"
 Case 25 //25 Double or Real expression has overflowed
  ls_ErrorMessge = "双精度型或实型表达式溢出"
 Case 26 //26 Field name assignment not supported
  ls_ErrorMessge = "不支持这种字段赋值"
 Case 27 //27 Cannot take a negative to a noninteger power
  ls_ErrorMessge = "不能计算一个负数的非整数次方"
 Case 28 //28 VBX Error: name
  ls_ErrorMessge = "VBX 错误"
 Case 29 //29 Nonarray expected in ANY variable
  ls_ErrorMessge = "Any 类型变量期待非数组类型"
 Case 30 //30 External o b j e c t does not support data type name
  ls_ErrorMessge = "外部对象不支持这种变量类型"
 Case 31 //31 External o b j e c t data type name not supported
  ls_ErrorMessge = "外部对象的数据类型不支持"
 Case 32 //32 Name not found calling external o b j e c t function name
  ls_ErrorMessge = "调用外部对象函数时函数名称没有找到"
 Case 33 //33 Invalid parameter type calling external o b j e c t function name
  ls_ErrorMessge = "调用外部对象函数时使用了错误的参数类型"
 Case 34 //34 Incorrect number of parameters calling external o b j e c t function name
  ls_ErrorMessge = "调用外部对象函数时使用的参数个数不对"
 Case 35 //35 Error calling external o b j e c t function name
  ls_ErrorMessge = "调用外部对象的函数错误"
 Case 36 //36 Name not found accessing external o b j e c t property name
  ls_ErrorMessge = "访问外部对象属性时属性名称没有找到"
 Case 37 //37 Type mismatch accessing external o b j e c t property name
  ls_ErrorMessge = "访问外部对象属性时使用了不匹配的类型"
 Case 38 //38 Incorrect number of subscripts accessing external o b j e c t property name
  ls_ErrorMessge = "访问外部对象属性时使用了错误的下标"
 Case 39 //39 Error accessing external o b j e c t property name
  ls_ErrorMessge = "访问外部对象的属性错误"
 Case 40 //40 Mismatched ANY data types in expression
  ls_ErrorMessge = "表达式中Any数据类型不匹配"
 Case 41 //41 Illegal ANY data type in expression
  ls_ErrorMessge = "表达式中使用了非法的Any数据类型"
 Case 42 //42 Specified argument type differs from required argument type at runtime in DLL function name
  ls_ErrorMessge = "指定的参数类型与动态链接库中的函数所需要的参数类型不一致"
 Case 43 //43 Parent o b j e c t doesn't exist
  ls_ErrorMessge = "父对象不存在"
 Case 44 //44 Function has conflicting argument or return type in ancestor
  ls_ErrorMessge = "函数与祖先的参数或返回值冲突"
 Case 45 //45 Internal table overflow; maximum number of o b j e c ts exceeded
  ls_ErrorMessge = "内部表溢出;对象的最大数目已经超越"
 Case 46 //46 Null o b j e c t reference cannot be assigned or passed to a variable of this type
  ls_ErrorMessge = "空对象引用不能赋值或传递给一个这种类型的变量"
 Case 47 //47 Array expected in ANY variable
  ls_ErrorMessge = "Any类型期待数组"
 Case 48 //48 Size mismatch in array to o b j e c t conversion
  ls_ErrorMessge = "将数组转换成对象时数组的大小不匹配"
 Case 49 //49 Type mismatch in array to o b j e c t conversion
  ls_ErrorMessge = "将数组转换成对象不匹配"
 Case 50 //50 Distributed Service Error
  ls_ErrorMessge = "分布式服务错误"
 Case 51 //51 Bad argument list for function/event
  ls_ErrorMessge = "函数/事件的参数列表错误"
 Case 52 //52 Distributed Communications Error
  ls_ErrorMessge = "分布式通讯错误"
 Case 53 //53 Requested server not active
  ls_ErrorMessge = "被请求的服务器没有激活"
 Case 54 //54 Server not accepting requests
  ls_ErrorMessge = "服务器不接受请求"
 Case 55 //55 Request terminated abnormally
  ls_ErrorMessge = "请求意外中断"
 Case 56 //56 Response to request incomplete
  ls_ErrorMessge = "响应请求不完整"
 Case 57 //57 Not connected
  ls_ErrorMessge = "没有连接"
 Case 58 //58 Object instance does not exist
  ls_ErrorMessge = "对象实例不存在"
 Case 59 //59 Invalid column range
  ls_ErrorMessge = "无效的列的范围"
 Case 60 //60 Invalid row range
  ls_ErrorMessge = "无效的行的范围"
 Case 61 //61 Invalid conversion of number dimensional array to o b j e c t
  ls_ErrorMessge = "转换多维数组到一个对象无效"
 Case 62 //62 Server busy
  ls_ErrorMessge = "服务器忙"
 Case 63 //63 Function/event with no return value used in expression
  ls_ErrorMessge = "在表达式中函数/事件没有返回值"
 Case 64 //64 Object array expected in left side of assignment
  ls_ErrorMessge = "赋值语句左边期待对象数组"
 Case 65 //65 Dynamic function not found. Possible causes include: pass by value/reference mismatch
  ls_ErrorMessge = "动态函数没有找到,可能是因为:值传递/引用传递不匹配"
 Case 66 //66 Invalid subscript for array index operation
  ls_ErrorMessge = "属组索引使用了非法的下标"
 Case 67 //67 NULL o b j e c t reference cannot be assigned or passed to an autoinstantiate
  ls_ErrorMessge = "空的对象引用不能赋值或传递给一个自动实例化对象"
 Case 68 //68 NULL o b j e c t reference cannot be passed to external DLL function name
  ls_ErrorMessge = "空的对象引用不能传递给外部动态链接库函数"
 Case 69 //69 Function name cannot be called from a secured runtime session
  ls_ErrorMessge = "安全模式中不能调用该函数"
 Case 70 //70 External DLL function name cannot be called from a secured runtime session
  ls_ErrorMessge = "安全模式中不能调用外部动态链接库函数"
 Case 71 //71 General protection fault occurred
  ls_ErrorMessge = "发生一般的保护错误"
 Case 72 //72 name failed with an operating system error code of number
  ls_ErrorMessge = "字段发生一个操作系统错误"
 Case 73 //73 Reference parameters cannot be passed to an asynchronous shared/remote o b j e c t method
  ls_ErrorMessge = "引用型参数不能传递给一个异步的共享/远程对象方法"
 Case 74 //74 Reference parameters cannot be passed to a shared o b j e c t method
  ls_ErrorMessge = "引用型参数不能传递给一个共享对象的方法"
 Case 75 //75 The server has forced the client to disconnect
  ls_ErrorMessge = "服务器已经强制客户端断开连接"
 Case 76 //76 Passing NULL as a parameter to external function name
  ls_ErrorMessge = "给外部函数传递了一个空值参数"
 Case 77 //77 Object passed to shared/remote o b j e c t method is not a nonvisual user o b j e c t
  ls_ErrorMessge = "对象传递给共享/远程对象的方法不是一个不可视的用户对象"
 Case 78 //78 Listen can only be done in Enterprise version of PowerBuilder
  ls_ErrorMessge = "监听只能在企业版的PowerBuilder中使用"
 Case 79 //79 The argument to name must be an array
  ls_ErrorMessge = "参数必须是一个数组"
 Case 80 //80 The server has timed out the client connection
  ls_ErrorMessge = "客户端尝试连接的时间已经超出服务器设置的限制时间"
 Case 81 //81 Function argument file creator must be a four character string
  ls_ErrorMessge = "函数参数文件创建者必须是一个四个字符的字符串"
 Case 82 //82 Function argument file type must be a four character string
  ls_ErrorMessge = "函数参数文件类型必须是一个四个字符的字符串"
 Case 83 //83 Attempt to invoke a function or event that is not accessible
  ls_ErrorMessge = "试图调用一个不可存取的函数或事件"
 Case 84 //84 Wrong number of arguments passed to function/event call
  ls_ErrorMessge = "在函数/事件中传递的参数个数错误"
 Case 85 //85 Error in reference argument passed in function/event call
  ls_ErrorMessge = "在函数/事件中传递的引用型参数错误"
 Case 86 //86 Ambiguous function/event reference
  ls_ErrorMessge = "引用不明确的函数/事件"
 Case 87 //87 The connection to the server has been lost
  ls_ErrorMessge = "与服务器的连接已经丢失"
 Case 88 //88 Cannot ask for ClassDefinition Information on open painter: name
  ls_ErrorMessge = "不能在打开的画笔中查询类定义信息"
 Case 85 //89 5.0 style proxy o b j e c ts are not supported. Copy the new style proxy that was generated at migration time
  ls_ErrorMessge = "5.0中的类型代理对象不支持,拷贝移植时产生的新的类型代理"
 Case 90 //90 Cannot assign array of type name to variable of type array of name
  ls_ErrorMessge = "这两种数据类型的数组不能赋值"
 Case 91 //91 Cannot convert any in Any variable to string.Possible cause uninitialized value.
  ls_ErrorMessge = "不能将任意型变量转变成字符型变量"
 Case Else
  ls_ErrorMessge = '未知错误, 请记录错误号并与管理员联系'
End Choose

MessageBox("运行时错误提示",ls_ErrorMessge)

ls_DocName = GetCurrentDirectory() + "\log.txt"
li_FileNum = FileOpen( ls_DocName, LineMode! , Write!, LockWrite!, Append! )
li_Return = FileWrite( li_FileNum, String( Today(), "yyyy-mm-dd hh:mm:ss" ) )
li_Return = FileWrite( li_FileNum, ls_ErrorMessge )
FileClose( li_FileNum )

原创粉丝点击