Persistance of objects 
Author Message
 Persistance of objects

Hi,

I wonder if it's possible to store objects (instantiated from VBA classes by
VBA template code) in the active document?

The problem I have is that I want to store extra data for freeform shapes
that are created by my VBA code. I haven't found a way to add this data to
the actual shape objects (which would have simplified things alot). Creating
custom objects that hold this data and can be linked to the right shape by
the use of keys is of course possible, but how do I store these custom
objects with the shapes in the same document? By the way we are talking
about around 20 to 30 data values for each shape and an upper limit of more
than 1000 shapes so the custom properties of the document isn't really
feasible I think. Do correct me if I'm wrong.

To store the data in an external database isn't possible in this case.

Many thanks in advance for any help on this.

/ Lasse T.



Mon, 12 Jan 2004 17:23:44 GMT  
 Persistance of objects
Hi Lars

What I would probably try is:

1) Name each Shape so you can reference it by its name.
2) One CustDocProp per shape, with the docProp's name being related to the
Shape's name, and containing all the data values for that shape as a single
long string, separated by some delimiter.

AFAIK there is no string length limitation for Custom doc props. Certainly
you can go to several thousand characters per property without problems.

Regards

Dave


| Hi,
|
| I wonder if it's possible to store objects (instantiated from VBA classes
by
| VBA template code) in the active document?
|
| The problem I have is that I want to store extra data for freeform shapes
| that are created by my VBA code. I haven't found a way to add this data to
| the actual shape objects (which would have simplified things alot).
Creating
| custom objects that hold this data and can be linked to the right shape by
| the use of keys is of course possible, but how do I store these custom
| objects with the shapes in the same document? By the way we are talking
| about around 20 to 30 data values for each shape and an upper limit of
more
| than 1000 shapes so the custom properties of the document isn't really
| feasible I think. Do correct me if I'm wrong.
|
| To store the data in an external database isn't possible in this case.
|
| Many thanks in advance for any help on this.
|
| / Lasse T.
|
|
|



Tue, 13 Jan 2004 05:19:50 GMT  
 Persistance of objects
Hi Dave,

Thanks for the answer. I've tested your solution. I also stumbled on an
article at msofficepro.com that discussed Variables in a Document. I've
tested that too. Here is what I found:

1) Word can handle 64K number of CustDocProps. When I add more Word will
just delete the existing CustDocProps and start adding from the start again.
Strange behaviour.
2) Each CustDocProp can be max 255 characters long. When I try to add more
characters nothing will happen. Strange limitation.
3) Users can add, change and delete CustDocProps.

4) Word can handle 32K number of Varibles. When I add more Word will crash
when I try to save the document.
5) Each Variable can be max 64K characters long. This at least is an
expected behaviour since the built in data type String can handle 64K.
6) Variables are invisable to the user.

I'll probably go with Variables, mainly because of points 3) and 6). Number
4) must obviously be checked thoroughly. Also, I'll probably use your idea
and put some data items together in the same variable to lower the number of
variables used.

It seems to me that custom properties and, especially, variables are not
used that much since these kinds of odd behaviour exists with them.

Again thanks for your help.

/ Lasse T.


Quote:
> Hi Lars

> What I would probably try is:

> 1) Name each Shape so you can reference it by its name.
> 2) One CustDocProp per shape, with the docProp's name being related to the
> Shape's name, and containing all the data values for that shape as a
single
> long string, separated by some delimiter.

> AFAIK there is no string length limitation for Custom doc props. Certainly
> you can go to several thousand characters per property without problems.

> Regards

> Dave



Tue, 13 Jan 2004 19:00:00 GMT  
 Persistance of objects
Hi Lars

I'm confused by "Each CustDocProp can be max 255 characters long" - I
created one with 6,000 characters as a test before I posted. But I agree
that their visibility to the user is an issue.

Regards

Dave


| Hi Dave,
|
| Thanks for the answer. I've tested your solution. I also stumbled on an
| article at msofficepro.com that discussed Variables in a Document. I've
| tested that too. Here is what I found:
|
| 1) Word can handle 64K number of CustDocProps. When I add more Word will
| just delete the existing CustDocProps and start adding from the start
again.
| Strange behaviour.
| 2) Each CustDocProp can be max 255 characters long. When I try to add more
| characters nothing will happen. Strange limitation.
| 3) Users can add, change and delete CustDocProps.
|
| 4) Word can handle 32K number of Varibles. When I add more Word will crash
| when I try to save the document.
| 5) Each Variable can be max 64K characters long. This at least is an
| expected behaviour since the built in data type String can handle 64K.
| 6) Variables are invisable to the user.
|
| I'll probably go with Variables, mainly because of points 3) and 6).
Number
| 4) must obviously be checked thoroughly. Also, I'll probably use your idea
| and put some data items together in the same variable to lower the number
of
| variables used.
|
| It seems to me that custom properties and, especially, variables are not
| used that much since these kinds of odd behaviour exists with them.
|
| Again thanks for your help.
|
| / Lasse T.
|


| > Hi Lars
| >
| > What I would probably try is:
| >
| > 1) Name each Shape so you can reference it by its name.
| > 2) One CustDocProp per shape, with the docProp's name being related to
the
| > Shape's name, and containing all the data values for that shape as a
| single
| > long string, separated by some delimiter.
| >
| > AFAIK there is no string length limitation for Custom doc props.
Certainly
| > you can go to several thousand characters per property without problems.
| >
| > Regards
| >
| > Dave
| >
|
|
|



Tue, 13 Jan 2004 21:47:38 GMT  
 Persistance of objects
Hi Dave,

Yeah, I was confused too. But I've checked and checked and can't find
anything wrong with my testing (which doesn't exclude errors of course). The
code I've used for CustDocProp testing and Variable testing are very
similar. A function is called that adds 100 characters at a time and then
reports the length of the value with the Len function. Inside the function
is a loop that adds 10 characters 10 times. I retested it now and even
looked at the value in the immediate window, counting the characters. It
stops at 255. No matter how many characters I add it remains the same. Up
until 250 characters the value is OK, then only 5 characters are added on
the next loop. Beats me why our results differ. And I definitely don't
understand why there should be a 255 char limit. For me this 255 char limit
applies even if I add a custom property in the document properties dialogue.
I can only add 255 chars to the Value textbox.

Anyway, I will get the job done which is what matters to me.

Regards

/ Lasse T.


Quote:
> Hi Lars

> I'm confused by "Each CustDocProp can be max 255 characters long" - I
> created one with 6,000 characters as a test before I posted. But I agree
> that their visibility to the user is an issue.

> Regards

> Dave



Tue, 13 Jan 2004 22:40:09 GMT  
 Persistance of objects
Hi Lars

| Yeah, I was confused too.

My mistake, you were quite right. When I added the 6,000 character string as
a custom doc prop, and didn't get an error message, I assumed that it must
have worked, especially when I saw the new Doc property appear in the
Properties dialog  ... I forgot that VBA is a Microsoft language! <g>

In case anyone else is interested, BTW, you can easily demonstrate the
problem by running the following code:

Sub Test()

With ActiveDocument.CustomDocumentProperties
    .Add Name:="MyString", _
        LinkToContent:=False, _
        Type:=msoPropertyTypeString, _
        Value:=String(6000, "a")
End With

'Above runs with no error message, and the new doc proprty does _
'appear in the Properties dialog, but the following line returns "255"

MsgBox Len(ActiveDocument.CustomDocumentProperties("MyString").Value)

End Sub

| Anyway, I will get the job done which is what matters to me.

Good luck.

Regards

Dave



Wed, 14 Jan 2004 02:02:02 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Problem with Persistance of object type between apps

2. Object Persistance/Serialization

3. Object persistance

4. Object Persistance and Focus

5. PublicNotCreatable object collection persistance

6. Object property persistance

7. Object persistance without the PropBag?

8. Object Persistance to DB

9. someone please explain object persistance

10. Object persistance

11. Custom complex properties persistance

12. .NET Persistance

 

 
Powered by phpBB® Forum Software