首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VBA中的错误处理

VBA中的错误处理
EN

Stack Overflow用户
提问于 2010-07-13 23:44:06
回答 2查看 481关注 0票数 0

我有一个看起来像这样的潜艇:

代码语言:javascript
复制
Sub open_esy(filename, p As String, p1 As Integer)

Dim fileLocation As String
Dim iFileNum As Integer, findblank
Dim letter_temp0 As String, letter0 As String, letter1 As String
Dim i As Integer
Dim j As Integer

i = 16

If Dir("\\Tecan3\output\" & filename & "*esy") <> "" Then
  fileLocation = "\\Tecan3\output\" & Dir("\\Tecan3\output\" & filename & "*esy")
ElseIf Dir("\\Tecan_2\output on tecan 2\" & filename & "*esy") <> "" Then
  fileLocation = "\\Tecan_2\output on tecan 2\" & Dir("\\Tecan_2\output on tecan 2\" & filename & "*esy")
ElseIf Dir("\\Tecan1\tecan #1 output\" & filename & "*esy") <> "" Then
  fileLocation = "\\Tecan1\tecan #1 output\" & Dir("\\Tecan1\tecan #1 output\" & filename & "*esy")
Else
  MsgBox "file " & filename & "not found"
  Exit Sub
End If

'open the batch file


   ''''old iFileNum = FreeFile()
   ''''old Open fileLocation For Input As #1

   ''''old Do While Not EOF(iFileNum)
    ''''old Line Input #iFileNum, stext

        Dim fso As New FileSystemObject
    Dim fld As Folder
    Dim ts As textstream

    Set ts = fso.OpenTextFile(fileLocation, ForReading)


    While Not ts.AtEndOfStream
        stext = ts.ReadLine

        letter0 = Mid(stext, 1, 3)

        If letter0 <> "A01" And letter0 <> "B01" And letter0 <> "C01" And letter0 <> "D01" And letter0 <> "E01" And letter0 <> "F01" And letter0 <> "G01" And letter0 <> "H01" And letter0 <> "I01" Then

        'letter1 = Mid(stext, 7, InStr(8, stext, " ") - 7)

        letter1 = Mid(stext, 7, InStr(8, stext, " ") - InStr(1, stext, "   ") - 3)

         Windows("Batch_XXXX revised.xlsm").Activate

        Call ProcessVialPosition(letter0, i)
        Cells(i, 3) = letter1
        i = i + 1
        End If
    Wend

    ts.Close

   ''''old Loop

   ''''old Close #1



   Cells(2, 2) = filename


   Cells(1, 2) = p

   Cells(1, 4) = p1


   save_template ("\\Centos5\ls-data\Interface\TF1\THC worklists\" & filename & "_THC" & ".txt")

End Sub

出于某种原因,它在看似随机的点上存在

如何捕获它存在的位置,以及如何捕获错误?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-07-13 23:53:05

您是否在询问如何跟踪看似未被引发的错误?如果是这样,要禁用IDE中的所有错误处理,请单击“工具”->“选项”->“常规”->“中断所有错误”

如果失败,您将需要设置一个breakpoint and step throught the code

票数 3
EN

Stack Overflow用户

发布于 2010-07-13 23:48:15

您需要一些错误处理代码!

代码语言:javascript
复制
Sub open_esy(filename, p As String, p1 As Integer) 
On Error Goto Err_open_esy

... your sub here ...

Exit_open_esy:
  Exit Sub

Err_open_esy:
  ... your error handling code here ...
  ... you can grab line numbers too if you insert them above ...
  MyUniversalErrorHandler(Err.Number, Err.Description, Erl)
'Erl is the error line number from the above sub/function
End Sub
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3238853

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档