Results 1 to 3 of 3

Thread: Runtime error

  1. #1
    Member
    Join Date
    2003-04
    Posts
    2
    Login to Give a bone
    0

    Red face Runtime error

    Hi all,

    I have a problem with my function;

    My routine lets the user pick an object on screen.

    A first failure in selecting an object (The user picks anywhere on the screen), the routine displayes an message box.

    A second failure in selecting an object generates a runtime error.
    <"Method 'GetSubEntity' of object 'IAcadUtility' failed">

    How do i solve this problem?

    Here is the VBA-Code:

    >Public Sub Fase_Enkel()
    >On Error GoTo Fout
    >UserForm1.Hide
    >Fase = "L1"
    >
    >If UserForm1.OptionButton5.Value = True Then
    > Fase = "L2"
    >End If
    >If UserForm1.OptionButton6.Value = True Then
    > Fase = "L3"
    >End If
    >
    >SELECTEER:
    >ThisDrawing.Utility.GetSubEntity objEnt, varPnt, vbCr & "Selecteer een tekst: ", varData
    >
    >If objEnt.ObjectName = "AcDbAttribute" Then
    > Set objAttr = objEnt
    > objAttr.TextString = Fase
    > Haal_Fase
    > GoTo SELECTEER
    >End If
    >If objEnt.ObjectName = "AcDbText" Or objEnt.ObjectName = "AcDbMtext" Then
    > objEnt.TextString = Fase
    > objEnt.Update
    > Haal_Fase
    > GoTo SELECTEER
    >End If
    >
    >Fout:
    > If MsgBox("Er is geen tekst geselecteerd. Verder gaan met selecteren?", vbYesNo, "Fout") = vbYes Then
    > Err.Clear
    > GoTo SELECTEER
    > End If
    >
    >EINDE:
    >UserForm1.Show
    >End Sub

    END Code

  2. #2
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Lightbulb Re: Runtime error

    Here is a function I use to select a subentity. It allows the operator to use <Enter> to exit the subroutine, so your main code needs to check if the returned object is Nothing and exit quietly.

    Code:
    Option Explicit
    
    Private Function SelectSubEnt(Optional Msg As String = "Select object: ") As AcadEntity
      Dim myMsg As String
      myMsg = vbCrLf & Msg
        
      Dim pickObj As AcadEntity
      Dim pickPt As Variant
      Dim pickMatrix As Variant
      Dim pickContext As Variant
      Dim ErrNo As Integer
      ErrNo = 0
      
      With ThisDrawing
        On Error GoTo CheckErr
        .SetVariable "ErrNo", ErrNo
        .Utility.GetSubEntity pickObj, pickPt, pickMatrix, pickContext, myMsg
      End With
      
      Set SelectSubEnt = pickObj
    
    ExitHere:
      Exit Function
      
    CheckErr:
      Debug.Print Err.Description
      If InStr(1, Err.Description, "failed", vbTextCompare) > 0 Then
        ErrNo = CInt(ThisDrawing.GetVariable("ErrNo"))
        If ErrNo = 52 Then
          Err.Clear
          Resume ExitHere
        ElseIf ErrNo = 7 Then
          Err.Clear
          Resume
        End If
      Else
        MsgBox Err.Description
        Resume ExitHere
      End If
    End Function
    
    Sub Test()
      Dim myObj As AcadEntity
      Set myObj = SelectSubEnt
      If myObj Is Nothing Then
        MsgBox "User hit <Enter>, exit quietly."
      Else
        MsgBox "Found object: " & myObj.ObjectName
      End If
    End Sub

  3. #3
    Member
    Join Date
    2003-04
    Posts
    2
    Login to Give a bone
    0

    Thumbs up Re: Runtime error

    Thanks Robert,

    I could use some bits of your code to modify my routine.
    for example:
    >SELECT:
    >Set objEnt = SelectSubEnt
    > If objEnt Is Nothing Then
    > GoTo Fout
    > End If

    Now it works like a dream......

Similar Threads

  1. Runtime error
    By madyb in forum Revit Structure - General
    Replies: 2
    Last Post: 2007-08-02, 04:29 PM
  2. Runtime Error
    By wendellbstephens in forum Revit Structure - General
    Replies: 0
    Last Post: 2007-06-15, 02:08 PM
  3. C++ Runtime Error
    By Wolfgirl in forum AutoCAD General
    Replies: 9
    Last Post: 2006-12-28, 08:19 PM
  4. Microsoft Visual C++ Runtime Library....Runtime Error
    By robertb.65723 in forum Inventor - General
    Replies: 6
    Last Post: 2004-10-28, 10:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •