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
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