Checking if something exists in a collection

Checking if something exists in a collection

Anonymous
Not applicable
291 Views
5 Replies
Message 1 of 6

Checking if something exists in a collection

Anonymous
Not applicable


What am I doing wrong here?

How do I check to see if an item exists in collection?  This bombs
out at the red line.

Sub Test()

    Dim acdTxtStylesColl As AcadTextStyles

    Dim strTxtStyleName As String

 

    strTxtStyleName = "ISO3098B"

 

    Set acdTxtStylesColl = ThisDrawing.TextStyles

 

    If acdTxtStylesColl.Item("strTxtStyleName")
Then


        MsgBox "STYLE EXISTS"

    End If

End Sub

--

NOTICE: This message contains privileged and confidential information

intended only for the use of the addressee named above. If you are
not

the intended recipient of this message you are hereby notified that
you

must not disseminate, copy or take any action in reliance on it. If
you

have received this message in error please notify Sinclair Knight Merz

Pty Ltd immediately. Any views expressed in this message are those
of

the individual sender, except where the sender has the authority to

issue and specifically states them to be the views of Sinclair Knight

Merz.

--

CAUTIONARY NOTES CONCERNING THE USE OF ELECTRONICALLY TRANSFERRED DATA

SINCLAIR KNIGHT MERZ

--

The documentation produced by using this electronic data is uncontrolled

and not subject to

update. The recipient is responsible for reviewing the status of the

transferred information and

should advise Sinclair Knight Merz immediately upon receipt of any

discrepancy. The design

and details are applicable to the intended project only and must not
be

reproduced wholly or

in part, or supplied to any third party without the written permission

of Sinclair Knight Merz

who retains copyright of all the transmitted material

--

The sender makes no warranty regarding the presence of electronic or

magnetic data errors

or computer viruses, or as to the accuracy or completeness of the data

transmitted.

 

0 Likes
292 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Four words: On Error Resume Next

BTW, that is one obnoxious signature you have there not to metnion
rather non-sensical given the fact that you posted a question to no
specific person in a public forum.

--
http://www.acadx.com
Win a free autographed copy of
"AutoCAD 2000 VBA Programmer's Reference"
by Joe Sutphin

"Viney, Scott" wrote in message
news:3AA81F0D.ADF2FFCA@skm.com.au...
What am I doing wrong here?
How do I check to see if an item exists in collection? This bombs out
at the red line.
Sub Test()
Dim acdTxtStylesColl As AcadTextStyles
Dim strTxtStyleName As String

strTxtStyleName = "ISO3098B"

Set acdTxtStylesColl = ThisDrawing.TextStyles

If acdTxtStylesColl.Item("strTxtStyleName") Then
MsgBox "STYLE EXISTS"
End If
End Sub
0 Likes
Message 3 of 6

Anonymous
Not applicable
Frank,

Sorry about the work blurb. But can you explain how to the On Error
Resume Next will work? I jsut want to test if an object exists within a
collection.

Cheers mate

Scott V

Frank Oquendo wrote:

> Four words: On Error Resume Next
>
> BTW, that is one obnoxious signature you have there not to metnion
> rather non-sensical given the fact that you posted a question to no
> specific person in a public forum.
>
> --
> http://www.acadx.com
> Win a free autographed copy of
> "AutoCAD 2000 VBA Programmer's Reference"
> by Joe Sutphin
>
> "Viney, Scott" wrote in message
> news:3AA81F0D.ADF2FFCA@skm.com.au...
> What am I doing wrong here?
> How do I check to see if an item exists in collection? This bombs out
> at the red line.
> Sub Test()
> Dim acdTxtStylesColl As AcadTextStyles
> Dim strTxtStyleName As String
>
> strTxtStyleName = "ISO3098B"
>
> Set acdTxtStylesColl = ThisDrawing.TextStyles
>
> If acdTxtStylesColl.Item("strTxtStyleName") Then
> MsgBox "STYLE EXISTS"
> End If
> End Sub
>
0 Likes
Message 4 of 6

Anonymous
Not applicable
Hi Scott,
Something along this line..

Public Function DoesStyleExist(strTxtStyleName As String) As Boolean
Dim acdTxtStylesColl As AcadTextStyles
Dim acdTxtStyle As AcadTextStyle
On Error Resume Next
Set acdTxtStylesColl = ThisDrawing.TextStyles
Set acdTxtStyle = acdTxtStylesColl.Item(strTxtStyleName)
DoesStyleExist = (Err.Number = 0)
Err.Clear
End Function

Randall Rath
0 Likes
Message 5 of 6

Anonymous
Not applicable
Drop the inverted commas inside the bracket. As it stands it is looking for an item called strTxtStyleName rather than the string that the variable strTxtStyleName refers tp
0 Likes
Message 6 of 6

Anonymous
Not applicable
You should try somthing like this
> > Sub Test()
> > Dim acdTxtStylesColl As AcadTextStyles
> > Dim strTxtStyleName As String
Dim acdTxtStyle as AcadTextStyle
> >
> > strTxtStyleName = "ISO3098B"
> >
> > Set acdTxtStylesColl = ThisDrawing.TextStyles
> >
On Error GoTo EssSt
Set acdTxtStyle= acdTxtStylesColl.Item("strTxtStyleName")
On Error Goto 0
---------
--------
Exit Sub
SomeThing:
--------
--------
Ext Sub
EssSt: MsgBox "It does not extist"
Resume Something
End Sub
>
0 Likes