I'm only going to show the "normal" lisp way ... not the ActiveX methods. In some cases the ActiveX may be a bit simpler though, but you can swot-up on that on your own 
XData
Basically if you go the older XData route, you can do the following. Add a new list item starting with -3 containing a sub-list:
Code:
'(-3 ("YourAppName" ;Change to whatever you want to identify your data to - not longer than 31 characters
(1000 . "Any string value")
(1002 . {") ;Start a nested list
(1005 . "34E567") ;A handle link to another entity, automatically updated if changed
(1005 . "34A876") ;A handle link to another entity, automatically updated if changed
(1005 . "34B234") ;A handle link to another entity, automatically updated if changed
(1002 . "}) ;End the nested list
(1010 . 100.0) ;X value in floating point "real"
(1020 . 100.0) ;Y value in floating point "real"
(1030 . 100.0) ;Z value in floating point "real"
(1040 . 12345.67) ;An arbitrary real number
(1041 . 123.45) ;A real number "distance" which gets mutiplied by the factor to which the host entity is scaled
))
You need to register the name you've decided on by issuing (regapp "YourAppName") after ensuring that it's not already registered by using (tblsearch "APPID" "YourAppName").
After adding it to the entity data list (as obtained from entget), simply do an entmod and your data is saved to the entity.To see all the various XData group types look in the Dev help (DXF Reference > Advanced DXF Issues > Extended Data).
To later retrieve your data you need to tell entget that you also want the XData list(s). You do this by adding the optional application names list. So, assuming the ename of the entity is saved in variable ename:
Code:
(setq edata (entget ename '("YourAppName")))
Then you get the (assoc -3 edata). Inside which is(are) a sublist(s) starting with YourAppName, followed by whatever data you added to it.
XRecord
XRecords are "slightly" simpler. You create a new XRecord (see the Developer Help: DXF Reference > OBJECTS Section > XRECORD) object by using the entmakex (instead of entmake) so you first make a non-visual entity of (0 . "XRECORD") type, which is not (yet) owned by anything. Then you attach it to the entity, assume ename is the entity name of the host entity and xname the entity name obtained from entmakex:
Code:
(dictadd ename "YourDictionaryName" xname)
Then to obtain the XRecord entity you use:
Code:
(setq xlist (dictsearch ename "YourDictionaryName"))
LData
As alanjt's hinted at, this is not "really" recommended, there's some issues with sharing LData to other customization languages ... in particular VBA. However, this is probably the simplest way to get what you want.
To save any value(s) which is inside a variable to an entity you use:
Code:
(vlax-ldata-put ename "YourKeyName" data)
To retrieve the data:
Code:
(setq data (vlax-ldata-get ename "YourKeyName"))
data can contain any lisp value from t(true) or nil(false) through to a list of values.
Basically LData just generates dictionary objects and link this through XRecords to the entity(ies). Unfortunately the way it does so makes it not so easy for other API's to work with the data. So if you ever decide to change to another API (e.g. DotNet) it may be a good idea to rather go with XData/XRecord directly.