It is currently Wed Jun 19, 2013 11:28 pm

All times are UTC





Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sun Jul 17, 2011 9:13 pm 
Offline
MCAD Contributer
User avatar

Joined: 29 Apr 2010
Posts: 60
Country: Australia
State: Non US/CAN Resident
CAD System: Inventor
Hi all.

Below is a snippet of a macro I've patched together from other sources (thanks to all you nameless people). I'm reasonably new to VBA and am stuck on how to add a catch for an error.

In the code I am make BHPierces = oCustomPropSet.Item("Pierces"). The Pierces value is generated by another macro. What I need is an error catch so that if oCustomPropSet.Item("Pierces") does not exist in the ipt then it skips to the next line and continues without error.


BHArea = oCustomPropSet.Item("ipwFlatArea").Value
BHPierces = oCustomPropSet.Item("Pierces").Value
BHMass = oCustomPropSet.Item("ipwMass").Value

_________________
Brendan Henderson
CAD Manager/Owner
____________________________________
From BLH Drafting Services
Mobile 0428 509212
Phone 03-5436 1094
Web http://www.blh.com.au
Twitter @BLHDrafting
____________________________________
Windows 7 x64 -64 GB Ram, Intel Xeon E5-1620 @ 3.6 GHz
ATI FirePro V5900 2 GB, 180 GB SSD & 1 TB HDD
Inv R2013 PDS SP1.1
Vault 2013 Workgroup Update 1


Share on FacebookShare on TwitterShare on DiggShare on DeliciousShare on TumblrShare on Google+
Top
 Profile  
 
PostPosted: Mon Jul 18, 2011 3:07 pm 
Offline
MCAD Addict
User avatar

Joined: 22 Mar 2004
Posts: 530
Country: United States
State: Pennsylvania
CAD System: Inventor
There are several ways to accomplish this. The approach I have taken in the past is to build the property value call into a small function. You can use the VBA OnError statement to catch the error in the function and return values that you can test against to take further action if required.
Code:
Private Function GetPropertyValue(ByRef invPropSet As Inventor.PropertySet, _
                                    ByVal strPropName As String, _
                                    ByRef strPropValue As String) As Boolean
                                   
    On Error GoTo BlackHole
    strPropValue = invPropSet.Item(strPropName).value
    GetPropertyValue = True
    Exit Function
   
BlackHole:
    strPropValue = ""
    GetPropertyValue = False
   
End Function


In your main function...
Code:
Dim bolRetVal as Boolean

bolRetVal = GetPropertyValue(oCustomPropSet, "Pierces", BHPierces)
If Not bolRetVal Then
    'take some action here...
End If
'or you could just simply call it this way if
'you do not need to react to the error condition...
GetPropertyValue oCustomPropSet, "Pierces", BHPierces

_________________
Robert A. Williams
http://www.leacar.com
"Gentlemen...you can't fight here. This is the War Room!"


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
POWERED_BY