乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
楼主: mark

Question 18 answers go here

[复制链接]

116

主题

996

帖子

9

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1466
发表于 2005-8-26 11:22:43 | 显示全部楼层
Actually while it is a common method in C++ it is also available in VB ..
回复

使用道具 举报

154

主题

1274

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1936
发表于 2005-8-26 11:35:52 | 显示全部楼层
I'm not a VB guru, anyway thanks for the hint.
回复

使用道具 举报

116

主题

996

帖子

9

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1466
发表于 2005-8-26 11:45:54 | 显示全部楼层
Here is an example of a useful on error resume next:
  1. Private Function HasElements(ArrayIn As Variant) As Boolean
  2. 'this routine will test to see if a 1d array is initialized
  3.    On Error Resume Next
  4.    HasElements = (UBound(ArrayIn) >= LBound(ArrayIn))
  5. End Function

Typically, this is what I do:
  1. Private Sub foo()
  2. On Error GoTo foo_Error
  3. 'work goes here
  4. ExitHere:
  5.     'clean up code goes here
  6.     On Error GoTo 0
  7.     Exit Sub
  8. foo_Error:
  9.    'log the error here by inspecting the Err object
  10.     Resume ExitHere
  11. End Sub

Say you where in a loop and you wanted to catch an error in the loop, you could use the above construct with the resume next command, that would place you on the next line following the error.
Here is an example:
  1. 'This routine takes a csv string if line handles and returns a collection
  2. 'of acadLine's
  3. Private Function stringToHoles(sCol As String, sIdentifier As String) As Collection
  4. Dim lineObj As AcadLine
  5. Dim sHandles() As String
  6. Dim i As Long, upper As Long
  7. Dim colLines As New Collection
  8. On Error GoTo ErrorHandler
  9. If Len(sCol) = 0 Then GoTo ExitHere
  10. sHandles= Split(sCol, ",")
  11. upper = UBound(sTemp)
  12. For i = 0 To upper
  13.     Set lineObj = ThisDrawing.HandleToObject(sHandles(i)) 'this will cause an error if the handle doesn't exist
  14.     If Not lineObj Is Nothing Then
  15.         lineobj.Highlight True
  16.         colLines.Add lineobj
  17.     End If
  18.     Set lineObj = Nothing
  19. Next i
  20. Set stringToHoleCollections = colLines
  21. ExitHere:
  22.     Set colTemp = Nothing
  23.     Erase sTemp
  24.     On Error GoTo 0
  25.     Exit Function
  26. ErrorHandler:
  27.     Select Case Err.Number
  28.         Case -2147467259 'Automation error Unspecified error - Means the object doesn't exist
  29.             Set lineObj = Nothing
  30.             Resume Next
  31.         Case -2145386484 'unknown handle - means the handle doesn't exist in the drawing
  32.             Set lineObj = Nothing
  33.             Resume Next
  34.         Case -2145386420 'object erased continue on
  35.             Set lineObj = Nothing
  36.             Resume Next
  37.         Case Else
  38.     End Select
  39.     Resume ExitHere
  40. End Function
回复

使用道具 举报

116

主题

996

帖子

9

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1466
发表于 2005-8-26 11:59:17 | 显示全部楼层
I'm not a VB guru, anyway thanks for the hint.
resistance is futile, you will be assimilated...
回复

使用道具 举报

116

主题

996

帖子

9

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1466
发表于 2005-8-26 12:53:48 | 显示全部楼层
> In Visual Basic, what does the line "On Error
> Resume Next" instruct the program to do?
My guess:
Quit processing the current evaluation and move on to the "err process'".
Am i close?
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-7-4 09:42 , Processed in 0.322980 second(s), 71 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表