Updating Xrecords?

Updating Xrecords?

Anonymous
Not applicable
325 Views
7 Replies
Message 1 of 8

Updating Xrecords?

Anonymous
Not applicable
Is it possible to "update" an x-record or does it have to be deleted and re-created? I have a "table" of drawing revisions I keep in a dictionary, these are editable via a form. In the form I pass the revision letter of the revision I want to modify to my routine. The routine then goes through the revision table until it finds a match for the revision letter passed to it. While stepping through the code everything seems to be working fine, no errors, but its obvious that the xrecord does not truly update. What am I doing wrong here? The routine is short so I have posted it in this message. Thanks for any tips ---------------------------------------------------------------------------- ----------- Sub UpdateRev(rev As Variant) Dim ObjAcad As Object Dim ObjDoc As Object Set ObjAcad = GetObject(, "AutoCAD.Application") Set ObjDoc = ObjAcad.ActiveDocument Dim ObjDictionary As AcadDictionary Dim ObjRevisions As AcadDictionary Dim Xtyp, XVar As Variant Dim XR As AcadXRecord Dim i As Integer On Error Resume Next 'Get our main dictionary Set ObjDictionary = ObjDoc.Dictionaries.Item("TBLOCKER") If Err.Number = 0 Then 'Get our revisions dictionary Set ObjRevisions = ObjDictionary.Item("REVISIONS") If ObjRevisions Then For i = 0 To ObjRevisions.Count - 1 Set XR = ObjRevisions.Item(i) XR.GetXRecordData Xtyp, XVar If XVar(0) = rev(0) Then 'then update our revision xrecord Xtyp(0) = 300: XVar(0) = rev(0) Xtyp(1) = 301: XVar(1) = rev(1) Xtyp(2) = 302: XVar(2) = rev(2) Xtyp(3) = 303: XVar(3) = rev(3) Xtyp(4) = 304: XVar(4) = rev(4) Xtyp(5) = 305: XVar(5) = rev(5) XR.SetXRecordData XType, XVar Exit For End If Next i End If End If end sub -- Perry Leets Inovec Optimization and Control Systems Eugene, Oregon
0 Likes
326 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
> On Error Resume Next > Set ObjRevisions = ObjDictionary.Item("REVISIONS") > If ObjRevisions Then I'm going to take a guess, that the last line above is failing, but it is not being detected because you have turned off error checking, by calling 'On Error Resume Next'. The problem that many VB programmers seem to have finding errors in their code, is in many cases due to the frivolous or improper use of 'On Error Resume Next', which serves to conceal errors. This practice is encouraged by Autodesk's incorrect use of errors, for the purpose of signaling non-error conditions, such as having a collection's Item() method raise an error (e.g., 'key not found'), to indicate that an element was not found. After you get past the code that you expect to fail (like the call to the Item() method), you must reinstate error checking _immediately_, with 'On Error Goto 0' (or Goto ). If you fail to do this, any subsequent errors in your code will be ignored, and you will just sit there scratching your head. -- http://www.caddzone.com AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005 http://www.acadxtabs.com "perry" wrote in message news:40aa42cc$1_1@newsprd01... > Is it possible to "update" an x-record or does it have to be deleted and > re-created? > I have a "table" of drawing revisions I keep in a dictionary, these are > editable via > a form. In the form I pass the revision letter of the revision I want to > modify to my > routine. The routine then goes through the revision table until it finds a > match for > the revision letter passed to it. While stepping through the code everything > seems to > be working fine, no errors, but its obvious that the xrecord does not truly > update. > What am I doing wrong here? The routine is short so I have posted it in this > message. > Thanks for any tips > > ---------------------------------------------------------------------------- > ----------- > > Sub UpdateRev(rev As Variant) > Dim ObjAcad As Object > Dim ObjDoc As Object > Set ObjAcad = GetObject(, "AutoCAD.Application") > Set ObjDoc = ObjAcad.ActiveDocument > Dim ObjDictionary As AcadDictionary > Dim ObjRevisions As AcadDictionary > Dim Xtyp, XVar As Variant > Dim XR As AcadXRecord > Dim i As Integer > > On Error Resume Next > 'Get our main dictionary > Set ObjDictionary = ObjDoc.Dictionaries.Item("TBLOCKER") > If Err.Number = 0 Then > 'Get our revisions dictionary > Set ObjRevisions = ObjDictionary.Item("REVISIONS") > If ObjRevisions Then > For i = 0 To ObjRevisions.Count - 1 > Set XR = ObjRevisions.Item(i) > XR.GetXRecordData Xtyp, XVar > If XVar(0) = rev(0) Then > 'then update our revision xrecord > Xtyp(0) = 300: XVar(0) = rev(0) > Xtyp(1) = 301: XVar(1) = rev(1) > Xtyp(2) = 302: XVar(2) = rev(2) > Xtyp(3) = 303: XVar(3) = rev(3) > Xtyp(4) = 304: XVar(4) = rev(4) > Xtyp(5) = 305: XVar(5) = rev(5) > XR.SetXRecordData XType, XVar > Exit For > End If > Next i > End If > End If > end sub > > -- > Perry Leets > Inovec Optimization and Control Systems > Eugene, Oregon > >
0 Likes
Message 3 of 8

Anonymous
Not applicable
Thanks for the advice Tony, I'll try to get away from all these "on error" things. Shame on Autodesk for instilling bad habits in me ;) After removing the "on error" then the mysterious error became less mysterious. It wasnt the line you suspected though, if you look closely at the code sample you will see that the call to SetXrecordData is attempting to pass a variable called XType which was defined as XTyp. Ironically, one of the reasons I loved switching from Lisp to VB is that the VBAIDE was so good at catching my typos! -- Perry Leets Inovec Optimization and Control Systems Eugene, Oregon "Tony Tanzillo" wrote in message news:40aa4eb6$2_3@newsprd01... > > On Error Resume Next > > > Set ObjRevisions = ObjDictionary.Item("REVISIONS") > > If ObjRevisions Then > > I'm going to take a guess, that the last line > above is failing, but it is not being detected > because you have turned off error checking, by > calling 'On Error Resume Next'. > > The problem that many VB programmers seem to have > finding errors in their code, is in many cases due > to the frivolous or improper use of 'On Error Resume > Next', which serves to conceal errors. This practice > is encouraged by Autodesk's incorrect use of errors, > for the purpose of signaling non-error conditions, > such as having a collection's Item() method raise an > error (e.g., 'key not found'), to indicate that an > element was not found. > > After you get past the code that you expect to fail > (like the call to the Item() method), you must reinstate > error checking _immediately_, with 'On Error Goto 0' > (or Goto ). If you fail to do this, any > subsequent errors in your code will be ignored, and you > will just sit there scratching your head.
0 Likes
Message 4 of 8

Anonymous
Not applicable
perry wrote: > Ironically, one of the reasons I loved switching from Lisp to VB is > that the VBAIDE was so > good at catching my typos! Unfortunately, the editor has no reason to suspect that was a typo so it let you get away with it. One habit I got into is to not capaitalize when I type code, only when declaring variables. This works wonderfully as typos will not result in the capitalization you expected, thus serving as a visible cue you got something wrong.
0 Likes
Message 5 of 8

Anonymous
Not applicable
Use "Option Explicit" in your module. You will then get a compile error, everytime you use a variable which has not been declared , which in turn will catch all your typos. "Frank Oquendo" wrote in message news:40aa6bcc$1_3@newsprd01... > perry wrote: > > > Ironically, one of the reasons I loved switching from Lisp to VB is > > that the VBAIDE was so > > good at catching my typos! > > Unfortunately, the editor has no reason to suspect that was a typo so it > let you get away with it. One habit I got into is to not capaitalize > when I type code, only when declaring variables. This works wonderfully > as typos will not result in the capitalization you expected, thus > serving as a visible cue you got something wrong. > >
0 Likes
Message 6 of 8

Anonymous
Not applicable
Tony Well spoken... Use of 'On Error Resume Next' can be very helpful, but only if the programmer takes care of the handling: On Error Resume Next Set AccObj = GetObject(, "Access.Application." & OffVer) If Err <> 0 Then Err.Clear Set AccObj = CreateObject("Access.Application." & OffVer) If Err <> 0 Then MsgBox "Description: " & Err.Description & _ vbCrLf & "Number: " & Err.Number, _ vbExclamation + vbOKOnly, "Error message" Err.Clear Else With AccObj .Visible = True .OpenCurrentDatabase DbsPth, False .UserControl = True End With End If Else AppTit = AccObj.CurrentDb.Properties("AppTitle") AppActivate AppTit, True If Err <> 0 Then Err.Clear AppActivate "Microsoft Access", True End If End If Cheers -- Juerg Menzi MENZI ENGINEERING GmbH, Switzerland http://www.menziengineering.ch
0 Likes
Message 7 of 8

Anonymous
Not applicable
I typically do have that turned on, Im assuming the typo wasnt caught because of the "On error" statement. -- Perry Leets Inovec Optimization and Control Systems Eugene, Oregon "Ravi Pothineni" wrote in message news:40aa87d0$1_1@newsprd01... > Use "Option Explicit" in your module. You will then get a compile error, > everytime you use a variable which has not been declared , which in turn > will catch all your typos. > > "Frank Oquendo" wrote in message > news:40aa6bcc$1_3@newsprd01... > > perry wrote: > > > > > Ironically, one of the reasons I loved switching from Lisp to VB is > > > that the VBAIDE was so > > > good at catching my typos! > > > > Unfortunately, the editor has no reason to suspect that was a typo so it > > let you get away with it. One habit I got into is to not capaitalize > > when I type code, only when declaring variables. This works wonderfully > > as typos will not result in the capitalization you expected, thus > > serving as a visible cue you got something wrong. > > > > > >
0 Likes
Message 8 of 8

Anonymous
Not applicable
When you turn on the option "Require variable declaration", it only adds "Option Explicit" to new modules. If you turned on that option after you started the project, some of your modules may be missing this statement. -- ---- Ed ---- "perry" wrote in message news:40ab7747$1_3@newsprd01... I typically do have that turned on, Im assuming the typo wasnt caught because of the "On error" statement. -- Perry Leets Inovec Optimization and Control Systems Eugene, Oregon "Ravi Pothineni" wrote in message news:40aa87d0$1_1@newsprd01... > Use "Option Explicit" in your module. You will then get a compile error, > everytime you use a variable which has not been declared , which in turn > will catch all your typos. > > "Frank Oquendo" wrote in message > news:40aa6bcc$1_3@newsprd01... > > perry wrote: > > > > > Ironically, one of the reasons I loved switching from Lisp to VB is > > > that the VBAIDE was so > > > good at catching my typos! > > > > Unfortunately, the editor has no reason to suspect that was a typo so it > > let you get away with it. One habit I got into is to not capaitalize > > when I type code, only when declaring variables. This works wonderfully > > as typos will not result in the capitalization you expected, thus > > serving as a visible cue you got something wrong. > > > > > >
0 Likes