Author Topic: Setting XRecord  (Read 8884 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Setting XRecord
« on: July 17, 2006, 06:41:39 PM »
Why won't this work?
Code: [Select]
Public Sub AddXRec(ByRef XrecName As String, DataType As Variant, Data As Variant)

Dim DictCol As Collection
Dim MyDict As Object
Dim Xrec As AcadXRecord

Set DictCol = This.Drawing.Dictionaries
Set MyDict = DictCol.Add("VBAtoLisp")
Set Xrec = MyDict.AddXRecord(XrecName)
xrec.SetXRecordData (datatype,data)

End Sub

When I hit enter on the last line, it gives and error stating
"Compile error:
Expected: ="
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Bob Wahr

  • Guest
Re: Setting XRecord
« Reply #1 on: July 17, 2006, 06:47:49 PM »
Lose the parenthesis
Code: [Select]
Public Sub AddXRec(ByRef XrecName As String, DataType As Variant, Data As Variant)

Dim DictCol As Collection
Dim MyDict As Object
Dim Xrec As AcadXRecord

Set DictCol = This.Drawing.Dictionaries
Set MyDict = DictCol.Add("VBAtoLisp")
Set Xrec = MyDict.AddXRecord(XrecName)
xrec.SetXRecordData datatype,data

End Sub

Bob Wahr

  • Guest
Re: Setting XRecord
« Reply #2 on: July 17, 2006, 06:49:20 PM »
Rule of thumb for most things VBA, if you are on the right side of an equals such as
Code: [Select]
Set Xrec = MyDict.AddXRecord(XrecName) you use the parethesis, if not, you don't.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Setting XRecord
« Reply #3 on: July 17, 2006, 06:56:47 PM »
Thank you very much Bob.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Bob Wahr

  • Guest
Re: Setting XRecord
« Reply #4 on: July 17, 2006, 06:58:23 PM »
Not a problem.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Setting XRecord
« Reply #5 on: July 17, 2006, 07:13:25 PM »
If you wish to maintain consistant parenthesis use throughout your code you can use the call statement --


Public Sub AddXRec(ByRef XrecName As String, DataType As Variant, Data As Variant)

    Dim DictCol As Collection, _
        MyDict  As Object, _
        Xrec    As AcadXRecord

    Set DictCol = This.Drawing.Dictionaries
    Set MyDict  = DictCol.Add ("VBAtoLisp")
    Set Xrec    = MyDict.AddXRecord (XrecName)

    Call xrec.SetXRecordData (datatype, data)

End Sub


(untested / drawing from memory)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Setting XRecord
« Reply #6 on: July 17, 2006, 07:27:18 PM »
Thanks Michael.  Just trying to get an idea of what this is all about.

Next question:
When you want to fill and XRecord, you need to use a variant, right?
Do you define the variant with and array of values?
Here is the code I'm trying.
Code: [Select]
Public Sub Main(ByRef Str1 As String, Str2 As String)

Dim DataType(1) As Variant
Dim Data(1) As Variant

Set Data(0) = Str1
Set Data(1) = Str2
Set DataType(0) = 1
Set DataType(1) = 2

AddXRec "VBAtoLisp", DataType, Data

End Sub

I pass Str1 & Str2 from a user form.  The error says that it wants an object for Str1, or any other variable that is first to get set (I have tried to set the DataType, with the same error).

Why?
« Last Edit: July 17, 2006, 07:29:22 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Bob Wahr

  • Guest
Re: Setting XRecord
« Reply #7 on: July 17, 2006, 07:43:31 PM »
Because you are Dimming the array as an array of 1 item with an index of 1.  You need to give it the entire range you are using so,

Dim DataType(0 to 1) as Variant
Dim Data(0 to 1) as Variant

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Setting XRecord
« Reply #8 on: July 17, 2006, 07:45:30 PM »
Thanks Bob.  I will have to pick this up tomorrow, it's time for me to go home, and no Cad there.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Bob Wahr

  • Guest
Re: Setting XRecord
« Reply #9 on: July 17, 2006, 07:48:36 PM »
Time for me to go as well.  We'll play some more tommorrow.

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Setting XRecord
« Reply #10 on: July 17, 2006, 08:35:41 PM »
Because you are Dimming the array as an array of 1 item with an index of 1.  You need to give it the entire range you are using so,

Dim DataType(0 to 1) as Variant
Dim Data(0 to 1) as Variant
Bob, This actually is not quite right......If your Index base is 0, using Dim Data(1) as Whatever  knows you mean Data(0 to 1).....here's a simple Example to demonstrate this:
Code: [Select]
Sub test()
Dim MyArray(2) As String
MyArray(0) = "Test1"
MyArray(1) = "Test2"
MyArray(2) = "Test3"

Dim i As Integer
For i = 0 To UBound(MyArray)
    Debug.Print MyArray(i)
Next
End Sub
Now, I prefer the way you show so you know the Lower & Upper bounds, but it's not mandatory.

Tim,
The error you get regarding an Object is due to your using this format
Code: [Select]
Set Data(0) = Str1
Set Data(1) = Str2
Set DataType(0) = 1
Set DataType(1) = 2
You use Set ONLY when you are casting some type of object. In this case, strings and integers are not objects, so lose the Set..... another error will pop up though, as Autocad expects DXF codes to be Integers and the array must be dimensioned as such.....make sure to change the first Function/Sub to accept an Integer array, too.

So for anything that uses the DXF codes, such as Xrecords, SelectionSet filters, etc., you want to use this format:
Code: [Select]
Dim DataType(1) As Integer
Dim Data(1) As Variant

Data(0) = Str1
Data(1) = Str2
DataType(0) = 1
DataType(1) = 2
HTH





Bob Wahr

  • Guest
Re: Setting XRecord
« Reply #11 on: July 17, 2006, 10:19:39 PM »
Thanks Jeff.  That's what I get for answering quickly instead of paying attention. 

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Setting XRecord
« Reply #12 on: July 18, 2006, 11:06:16 AM »
Thanks Jeff and Bob.  Now I'm erroring on a different part, and I don't understand why.  Here is the code.
Code: [Select]
Public Sub AddXRec(ByRef XrecName As String, DataType As Variant, Data As Variant)

Dim DictCol As Collection
Dim MyDict As Object
Dim Xrec As AcadXRecord

Set DictCol = This.Drawing.Dictionaries
MyDict = DictCol.Add("VBAtoLisp")
Xrec = MyDict.AddXRecord(XrecName)
Xrec.SetXRecordData DataType, Data


End Sub
It is erroring here.
Code: [Select]
MyDict = DictCol.Add("VBAtoLisp")
Saying that it is "Expected Function or variable".. What does it want.  I thought I could add a new dictionary with add, but it doesn't seem to like it.  It is highlighting ".Add" portion of the code, if that helps.


Edit:  It even errors if I use
Set MyDict = DictCol.Add("VBAtoLisp") [Tried per Jeff's comments about using Set for objects.]
« Last Edit: July 18, 2006, 11:13:51 AM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Bob Wahr

  • Guest
Re: Setting XRecord
« Reply #13 on: July 18, 2006, 11:29:01 AM »
Code: [Select]
Public Sub AddXRec(ByRef XrecName As String, DataType As Variant, Data As Variant)

Dim DictCol As Collection
Dim MyDict As AcadDictionary
'you want this to be a dictionary so no reason not to Dim it as such
Dim Xrec As AcadXRecord

Set DictCol = This.Drawing.Dictionaries
Set MyDict = DictCol.Add("VBAtoLisp")
'if you are setting an object, you need Set X = Y
Set Xrec = MyDict.AddXRecord(XrecName)
Xrec.SetXRecordData DataType, Data
'if you are setting the properties of an object, you don't

End Sub

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Setting XRecord
« Reply #14 on: July 18, 2006, 11:33:08 AM »
I tried that also Bob.  Maybe you didn't see my edit to my other post.  I will continue to look through the help to see if I can understand what is going on.  Thanks again.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.