Variable Attributes

Mar 9, 2011 at 2:27 PM

Many thanks for this great library.

I tried to add Custom Attributes to Variables, as it is possible in SPSS, but found no way to to that. Is this (or will this soon) be supported?

Coordinator
Mar 9, 2011 at 3:06 PM
I'm unfamiliar with this feature for custom attributes. There are no plans to enhance this library to keep up with new features. However, if you wish to enhance this library and contribute back, that would be welcome.
Mar 15, 2011 at 4:22 PM
Edited Mar 15, 2011 at 4:29 PM

I don't think this is a new feature, i.e. it seems to be featured in the SPSS 14 Dev Guide ("spssAddVarAttribute").

I implemented it in a very crude and simple way that seems to be working for me. As I am a noob programmer others might elaborate this in a better way. All i did was:

- Adding "Attributes" as a Property of Dictionary<string, string> to SpssVariable.cs

- Adding this to the Update Method of SpssVariable.cs:

  foreach (KeyValuePair<string, string> Attribute in Attributes)
            {
                SpssSafeWrapper.spssAddVarAttribute(FileHandle, this.name, Attribute.Key, -1, Attribute.Value);
             }

 

- Adding this to SpssSafeWrapper.cs:

  public static ReturnCode spssAddVarAttribute(int handle, string varName, string attribName, int attribSub, string attribText)
        {
            return spssAddVarAttribute(handle, ref varName, ref attribName, attribSub, ref attribText);
         }

 

- And this to SpssThinWrapper.cs:

  [DllImport("spssio32.dll", EntryPoint = "spssAddVarAttribute", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
        protected static extern ReturnCode spssAddVarAttribute(int handle, [MarshalAs(UnmanagedType.VBByRefStr)] ref string varName, [MarshalAs(UnmanagedType.VBByRefStr)] ref string attribName,  int attribSub, [MarshalAs(UnmanagedType.VBByRefStr)] ref string attribText);

 

It is then possible to add Attributes to Variables with <var>.Attributes.Add(<name>, <value>).

The only issue seems to be that the Attributes don't show up right away when opening the .SAV-File, but have to be "activated" through the View-Menu.

Coordinator
Mar 19, 2011 at 12:58 AM
Thanks for sharing. This looks like a good start. We'd also need the code to delete attributes and modify existing ones, I suspect.