Code Red > VB(A)

If function help

(1/3) > >>

Mark:
How come this doesn't work? What am I missing?
I'm trying to see if a selection set exists in the current dwg.

--- Code: ---
Sub ss_exists()
    If ThisDrawing.SelectionSets.Item("SNEW") Then
        MsgBox "selection set found: "
    End If
End Sub

--- End code ---

TR:
Item must be an integer.

Try this:


--- Code: ---
Sub ss_exists()
Dim I As Integer
For I = 1 To ThisDrawing.SelectionSets.Count
    If ThisDrawing.SelectionSets.Item(I).Name = "SNEW" Then
        MsgBox "selection set found: "
    End If
Next
End Sub

--- End code ---

Mark:
Thanks Tim but, it didn't like that either!
fails on this line;
ThisDrawing.SelectionSets.Item(I).Name = "SNEW"

invalid argument index in item

JohnK:
How did you create the SS?

Keith™:
The problem is that while you can indeed filter for a selection set with

--- Code: ---
ThisDrawing.SelectionSets.Item("SNEW")

--- End code ---


You cannot test for whether it actually exists or not from here alone. This is completely different than in lisp, where you can see if a variable has a value set to it, or if a function returned a non nil value.

VBA will not let you test against NULL in this instance.

Also if the selection set does not exist you will get a run time error "Key not found" and the application will crash.

Navigation

[0] Message Index

[#] Next page

Go to full version