PDA

View Full Version : getxrecord method problems



peter
2005-01-03, 01:19 PM
Hello vba'ers,

Maybe you can help me.

I was trying to answer a question from a gentleman in France who was trying to store and retrieve data in a dictionary, so I cooked up a small example to show how to do it.

I hit a stumbling block with I got the getxrecorddata statement



objXRecordReturn.GetXRecordData XRecordDataTypeReturn, XRecordDataReturn


for some reason It is returning blanks.

DO any of you have a good module for this or can you tell me what is wrong with the following code?

Peter Jamtgaard





Option Explicit
Public Sub Test()
Dim arrMyData(3) As Variant
arrMyData(0) = "hello"
arrMyData(1) = "There"
arrMyData(2) = "jean"
CreateDictionary "test7"
CreateXRecords "test7", arrMyData
ReadXRecords "test7"
End Sub
Private Sub CreateDictionary(strDictionaryName As String)
Dim objDictionary As AcadDictionary
On Error Resume Next
Set objDictionary = ThisDrawing.Dictionaries.Add(strDictionaryName)
objDictionary.Delete
Set objDictionary = ThisDrawing.Dictionaries.Add(strDictionaryName)
End Sub
Private Sub CreateXRecords(strDictionaryName As String, arrMyData() As Variant)
Dim intIndex As Integer
Dim objDictionary As AcadDictionary
Dim objXRecord As AcadXRecord
Dim XRecordData(0) As Variant
Dim XRecordDataType(0) As Integer
Set objDictionary = ThisDrawing.Dictionaries.Item(strDictionaryName)
MsgBox "Storing XRecord Information: "
For intIndex = 0 To UBound(arrMyData) - 1
Set objXRecord = objDictionary.AddXRecord(CStr(intIndex) & "A")
XRecordDataType(0) = 1
XRecordData(0) = arrMyData(intIndex)
objXRecord.SetXRecordData XRecordDataType, XRecordData
Next intIndex
End Sub
Private Sub ReadXRecords(strDictionaryName As String)
MsgBox "Retieving XRecord Information: "
Dim intIndex As Integer
Dim arrMyDataReturn(3) As Variant
Dim objDictionary As AcadDictionary
Dim objXRecordReturn As AcadXRecord
Dim XRecordDataReturn(0) As Variant
Dim XRecordDataTypeReturn(0) As Integer
Set objDictionary = ThisDrawing.Dictionaries.Item(strDictionaryName)
For intIndex = 0 To objDictionary.Count - 1
Set objXRecordReturn = objDictionary.Item(CStr(intIndex) & "A")
MsgBox objDictionary.Name & " Item: " & objXRecordReturn.Name
objXRecordReturn.GetXRecordData XRecordDataTypeReturn, XRecordDataReturn
MsgBox "XRecordDataTypeReturn: " & XRecordDataTypeReturn(0)
arrMyDataReturn(intIndex) = XRecordDataReturn(0)
MsgBox "XRecordDataReturn: " & XRecordDataReturn(0)
Next intIndex
MsgBox arrMyDataReturn(0) & " " & arrMyDataReturn(1) & " " & arrMyDataReturn(2)
End Sub

RobertB
2005-01-03, 02:40 PM
Here is part of the problem:

Dim XRecordDataReturn(0) As Variant
Dim XRecordDataTypeReturn(0) As Integer

Those variables should be plain variants:

Dim XRecordDataReturn As Variant
Dim XRecordDataTypeReturn As Variant

There may be other issues too, I didn't look too closely.

peter
2005-01-03, 08:34 PM
In the help through the vlide for this method the example uses an integer array for the datatype

ReDim XRecordDataType(0 To ArraySize) As Integer
ReDim XRecordData(0 To ArraySize) As Variant

I have played with the code and seem to figure out why it isn't working.

DO you have an example of reading from a dictionary using vba?

Peter Jamtgaard

peter
2005-01-03, 08:36 PM
Nevermind,


That worked, Thanks bob

Peter

fixo
2007-12-27, 09:16 PM
Nevermind,


That worked, Thanks bob

Peter

However I changed it slightly to show solution
if this would be interesting to somebody else

(Sorry for the late Peter)


Private Sub ReadXRecords(strDictionaryName As String)
MsgBox "Retieving XRecord Information: "
Dim intIndex As Integer
Dim arrMyDataReturn(3) As Variant
Dim objDictionary As AcadDictionary
Dim objXRecordReturn As AcadXRecord
Dim XRecordDataReturn As Variant
Dim XRecordDataTypeReturn As Variant
Set objDictionary = ThisDrawing.Dictionaries.Item(strDictionaryName)
For intIndex = 0 To objDictionary.Count - 1
Set objXRecordReturn = objDictionary.Item(CStr(intIndex) & "A")
MsgBox objDictionary.Name & " Item: " & objXRecordReturn.Name
objXRecordReturn.GetXRecordData XRecordDataTypeReturn, XRecordDataReturn
MsgBox "XRecordDataTypeReturn: " & XRecordDataTypeReturn(0)
arrMyDataReturn(intIndex) = XRecordDataReturn(0)
MsgBox "XRecordDataReturn: " & XRecordDataReturn(0)
Next intIndex
MsgBox arrMyDataReturn(0) & " " & arrMyDataReturn(1) & " " & arrMyDataReturn(2)
End Sub

~'J'~