PageRenderTime 58ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/Spss/SpssSafeWrapper.cs

#
C# | 1990 lines | 483 code | 35 blank | 1472 comment | 49 complexity | 64713a1d4b30e9c4fc1db0fe322ff097 MD5 | raw file
Possible License(s): LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace Spss
  4. {
  5. /// <summary>
  6. /// Very thin SpssSafeWrapper class for functions exposed by spssio32.dll.
  7. /// </summary>
  8. [CLSCompliant(false)]
  9. public class SpssSafeWrapper : SpssThinWrapper
  10. {
  11. /// <summary>
  12. /// Creates an instance of the <see cref="SpssSafeWrapper"/> class.
  13. /// </summary>
  14. protected SpssSafeWrapper()
  15. {
  16. }
  17. // These lengths were extracted from the SPSS documentation
  18. // rather than any header file.
  19. public const int SPSS_GUID_LENGTH = 256;
  20. public const int SPSS_SYSTEM_STRING_LENGTH = 41;
  21. public const int SPSS_MAX_TEXTINFO = 255;
  22. public const int SPSS_DATESTAMP_LENGTH = 9;
  23. public const int SPSS_TIMESTAMP_LENGTH = 8;
  24. #region veg
  25. public static Int32 SPSS_STRING(Int32 size)
  26. {
  27. return size;
  28. }
  29. public const Int32 SPSS_NUMERIC = 0;
  30. #endregion veg
  31. /// <summary>
  32. /// Opens an SPSS file for reading.
  33. /// </summary>
  34. /// <param name="fileName">
  35. /// Name of the file.
  36. /// </param>
  37. /// <param name="handle">
  38. /// The handle to the opened file.
  39. /// </param>
  40. /// <returns>
  41. /// <see cref="ReturnCode.SPSS_OK"/>,
  42. /// <see cref="ReturnCode.SPSS_FITAB_FULL"/>,
  43. /// <see cref="ReturnCode.SPSS_FILE_OERROR"/>,
  44. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>,
  45. /// <see cref="ReturnCode.SPSS_FILE_RERROR"/>,
  46. /// <see cref="ReturnCode.SPSS_INVALID_FILE"/>,
  47. /// <see cref="ReturnCode.SPSS_NO_TYPE2"/>, or
  48. /// <see cref="ReturnCode.SPSS_NO_TYPE999"/>.
  49. /// </returns>
  50. /// <remarks>
  51. /// This function opens an SPSS data file for reading and returns a handle that should be
  52. /// used for subsequent operations on the file.
  53. /// Files opened with spssOpenRead should be closed with <see cref="SpssThinWrapper.spssCloseReadDelegate"/>.
  54. /// </remarks>
  55. public static ReturnCode spssOpenRead(string fileName, out int handle)
  56. {
  57. return SpssThinWrapper.spssOpenReadImpl(ref fileName, out handle);
  58. }
  59. /// <summary>
  60. /// Creates an empty SPSS file.
  61. /// </summary>
  62. /// <param name="fileName">
  63. /// Name of the file.
  64. /// </param>
  65. /// <param name="handle">
  66. /// The handle to the new file.
  67. /// </param>
  68. /// <returns>
  69. /// <see cref="ReturnCode.SPSS_OK"/>,
  70. /// <see cref="ReturnCode.SPSS_FITAB_FULL"/>,
  71. /// <see cref="ReturnCode.SPSS_FILE_OERROR"/>,
  72. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>,
  73. /// </returns>
  74. /// <remarks>
  75. /// This function opens a file in preparation for creating a new SPSS data file and returns a
  76. /// handle that should be used for subsequent operations on the file.
  77. /// Files opened with spssOpenWrite should be closed with <see cref="SpssThinWrapper.spssCloseWriteDelegate"/>.
  78. /// </remarks>
  79. public static ReturnCode spssOpenWrite(string fileName, out int handle)
  80. {
  81. return SpssThinWrapper.spssOpenWriteImpl(ref fileName, out handle);
  82. }
  83. /// <summary>
  84. /// Reports the name of the case weight variable.
  85. /// </summary>
  86. /// <param name="handle">
  87. /// Handle to the data file.
  88. /// </param>
  89. /// <param name="varName">
  90. /// The name of the case weight variable.
  91. /// </param>
  92. /// <returns>
  93. /// <see cref="ReturnCode.SPSS_OK"/>,
  94. /// <see cref="ReturnCode.SPSS_NO_CASEWGT"/>,
  95. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>, or
  96. /// <see cref="ReturnCode.SPSS_INVALID_CASEWGT"/>.
  97. /// </returns>
  98. /// <remarks>
  99. /// This function reports the name of the case weight variable.
  100. /// </remarks>
  101. public static ReturnCode spssGetCaseWeightVar(int handle, out string varName)
  102. {
  103. varName = new string(' ', SPSS_MAX_VARNAME + 1);
  104. ReturnCode result = SpssThinWrapper.spssGetCaseWeightVarImpl(handle, ref varName);
  105. varName = (result == ReturnCode.SPSS_OK) ? varName.Substring(0, varName.IndexOf('\0')) : null;
  106. return result;
  107. }
  108. /// <summary>
  109. /// Retrieves the first block of SPSS Data Entry information from a data file.
  110. /// </summary>
  111. /// <param name="handle">
  112. /// Handle to the data file.
  113. /// </param>
  114. /// <param name="data">
  115. /// Data from the file.
  116. /// </param>
  117. /// <param name="maxData">
  118. /// Maximum bytes to return.
  119. /// </param>
  120. /// <returns>
  121. /// <see cref="ReturnCode.SPSS_OK"/>,
  122. /// <see cref="ReturnCode.SPSS_NO_DEW"/>,
  123. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>, or
  124. /// <see cref="ReturnCode.SPSS_FILE_BADTEMP"/>.
  125. /// </returns>
  126. /// <remarks>
  127. /// The client can retrieve DEW information (file information that is private to the SPSS
  128. /// Data Entry product) from a file in whatever increments are convenient. The first such
  129. /// increment is retrieved by calling spssGetDEWFirst, and subsequent segments are
  130. /// retrieved by calling spssGetDEWNext as many times as necessary. As with
  131. /// spssGetDEWInfo, spssGetDEWFirst will return SPSS_NO_DEW if the file was written
  132. /// with a byte order that is the reverse of that of the host.
  133. /// </remarks>
  134. public static ReturnCode spssGetDEWFirst(int handle, out string data, int maxData)
  135. {
  136. data = new string(' ', maxData);
  137. int len;
  138. ReturnCode result = SpssThinWrapper.spssGetDEWFirstImpl(handle, ref data, data.Length, out len);
  139. data = (result == ReturnCode.SPSS_OK) ? data.Substring(0, len) : null;
  140. return result;
  141. }
  142. /// <summary>
  143. /// Gets the Data Entry GUID from a data file.
  144. /// </summary>
  145. /// <param name="handle">
  146. /// Handle to the data file.
  147. /// </param>
  148. /// <param name="asciiGUID">
  149. /// The file's GUID in character form or a null string if the
  150. /// file contains no GUID.
  151. /// </param>
  152. /// <returns>
  153. /// <see cref="ReturnCode.SPSS_OK"/> or
  154. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>.
  155. /// </returns>
  156. /// <remarks>
  157. /// Data Entry for Windows maintains a GUID in character form as a uniqueness indicator.
  158. /// Two files have identical dictionaries and DEW information if they have the same
  159. /// GUID. Note that the spssOpenWriteCopy function will not copy the source file’s
  160. /// GUID. spssGetDEWGUID allows the client to read a file’s GUID, if any.
  161. /// </remarks>
  162. public static ReturnCode spssGetDEWGUID(int handle, out string asciiGUID)
  163. {
  164. asciiGUID = new string(' ', SPSS_GUID_LENGTH + 1);
  165. ReturnCode result = SpssThinWrapper.spssGetDEWGUIDImpl(handle, ref asciiGUID);
  166. // Although we search for a null terminator, the documentation
  167. // tells us that the GUID is always SPSS_GUID_LENGTH, so we COULD
  168. // just terminate the string there to trim off the null terminator that is
  169. // artificially put there.
  170. asciiGUID = (result == ReturnCode.SPSS_OK) ? asciiGUID.Substring(0, asciiGUID.IndexOf('\0')) : null;
  171. return result;
  172. }
  173. /// <summary>
  174. /// Retrieves the next block of SPSS Data Entry information from a data file.
  175. /// </summary>
  176. /// <param name="handle">
  177. /// Handle to the data file.
  178. /// </param>
  179. /// <param name="data">
  180. /// Data from the file.
  181. /// </param>
  182. /// <param name="maxData">
  183. /// Maximum bytes to return.
  184. /// </param>
  185. /// <returns>
  186. /// <see cref="ReturnCode.SPSS_OK"/>,
  187. /// <see cref="ReturnCode.SPSS_DEW_NOFIRST"/>,
  188. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>, or
  189. /// <see cref="ReturnCode.SPSS_FILE_BADTEMP"/>.
  190. /// </returns>
  191. /// <remarks>
  192. /// The client can retrieve DEW information (file information that is private to the SPSS
  193. /// Data Entry product) from a file in whatever increments are convenient. The first such
  194. /// increment is retrieved by calling <see cref="spssGetDEWFirst"/>, and subsequent segments are
  195. /// retrieved by calling spssGetDEWNext as many times as necessary. As with
  196. /// <see cref="SpssThinWrapper.spssGetDEWInfoDelegate"/>, <see cref="spssGetDEWFirst"/> will return SPSS_NO_DEW if the file was written
  197. /// with a byte order that is the reverse of that of the host.
  198. /// </remarks>
  199. public static ReturnCode spssGetDEWNext(int handle, out string data, int maxData)
  200. {
  201. data = new string(' ', maxData);
  202. int len;
  203. ReturnCode result = SpssThinWrapper.spssGetDEWNextImpl(handle, ref data, data.Length, out len);
  204. data = (result == ReturnCode.SPSS_OK) ? data.Substring(0, len) : null;
  205. return result;
  206. }
  207. /// <summary>
  208. /// Gets the file label of a data file.
  209. /// </summary>
  210. /// <param name="handle">
  211. /// Handle to the data file.
  212. /// </param>
  213. /// <param name="id">
  214. /// File label.
  215. /// </param>
  216. /// <returns>
  217. /// <see cref="ReturnCode.SPSS_OK"/> or
  218. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>.
  219. /// </returns>
  220. /// <remarks>
  221. /// This function retrieves the file label of the SPSS data file associated with
  222. /// <paramref>handle</paramref> into the <paramref>id</paramref> parameter.
  223. /// </remarks>
  224. public static ReturnCode spssGetIdString(int handle, out string id)
  225. {
  226. id = new string(' ', SPSS_MAX_IDSTRING + 1); // leave room for null terminator
  227. ReturnCode result = SpssThinWrapper.spssGetIdStringImpl(handle, ref id);
  228. id = (result == ReturnCode.SPSS_OK) ? id.Substring(0, id.IndexOf('\0')) : null;
  229. return result;
  230. }
  231. /// <summary>
  232. /// Gets information on the running version of SPSS, and the hosting computer.
  233. /// </summary>
  234. /// <param name="handle">
  235. /// Handle to the data file.
  236. /// </param>
  237. /// <param name="relInfo">
  238. /// Array of <see cref="int"/> in which release- and machine-specific data will be
  239. /// stored.
  240. /// </param>
  241. /// <returns>
  242. /// <see cref="ReturnCode.SPSS_OK"/>,
  243. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>, or
  244. /// <see cref="ReturnCode.SPSS_NO_TYPE73"/>.
  245. /// </returns>
  246. /// <remarks>
  247. /// This function reports release- and machine-specific information about the file
  248. /// associated with handle. The information consists of an array of eight int values copied
  249. /// from record type 7, subtype 3 of the file, and is useful primarily for debugging. The
  250. /// array elements are, in order, release number (index 0), release subnumber (1), special
  251. /// release identifier number (2), machine code (3), floating-point representation code (4),
  252. /// compression scheme code (5), big/little-endian code (6), and character representation
  253. /// code (7).
  254. /// </remarks>
  255. public static ReturnCode spssGetReleaseInfo(int handle, out int[] relInfo)
  256. {
  257. relInfo = new int[8];
  258. ReturnCode result = SpssThinWrapper.spssGetReleaseInfoImpl(handle, relInfo);
  259. return result;
  260. }
  261. /// <summary>
  262. /// Gets the name of the system that created a data file.
  263. /// </summary>
  264. /// <param name="handle">
  265. /// Handle to the data file.
  266. /// </param>
  267. /// <param name="sysName">
  268. /// The originating system name.
  269. /// </param>
  270. /// <returns>
  271. /// <see cref="ReturnCode.SPSS_OK"/> or
  272. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>.
  273. /// </returns>
  274. /// <remarks>
  275. /// This function returns the name of the system under which the file was created.
  276. /// </remarks>
  277. public static ReturnCode spssGetSystemString(int handle, out string sysName)
  278. {
  279. sysName = new string(' ', SPSS_SYSTEM_STRING_LENGTH + 1); // leave room for null terminator
  280. ReturnCode result = SpssThinWrapper.spssGetSystemStringImpl(handle, ref sysName);
  281. sysName = (result == ReturnCode.SPSS_OK) ? sysName.Substring(0, sysName.IndexOf('\0')) : null;
  282. return result;
  283. }
  284. /// <summary>
  285. /// Gets the data created by TextSmart.
  286. /// </summary>
  287. /// <param name="handle">
  288. /// Handle to the data file.
  289. /// </param>
  290. /// <param name="textInfo">
  291. /// Text data.
  292. /// </param>
  293. /// <returns>
  294. /// <see cref="ReturnCode.SPSS_OK"/> or
  295. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>.
  296. /// </returns>
  297. /// <remarks>
  298. /// This function retrieves the text data created by TextSmart.
  299. /// </remarks>
  300. public static ReturnCode spssGetTextInfo(int handle, out string textInfo)
  301. {
  302. textInfo = new string(' ', SPSS_MAX_TEXTINFO + 1);
  303. ReturnCode result = SpssThinWrapper.spssGetTextInfoImpl(handle, ref textInfo);
  304. textInfo = (result == ReturnCode.SPSS_OK) ? textInfo.Substring(0, textInfo.IndexOf('\0')) : null;
  305. return result;
  306. }
  307. /// <summary>
  308. /// Gets the creation date of a data file, as recorded in the file itself.
  309. /// </summary>
  310. /// <param name="handle">
  311. /// Handle to the data file.
  312. /// </param>
  313. /// <param name="fileDate">
  314. /// File creation date.
  315. /// </param>
  316. /// <param name="fileTime">
  317. /// File creation time.
  318. /// </param>
  319. /// <returns>
  320. /// <see cref="ReturnCode.SPSS_OK"/> or
  321. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>.
  322. /// </returns>
  323. /// <remarks>
  324. /// This function returns the creation date of the file as recorded in the file itself. The creation
  325. /// date is a 9-byte string in dd mmm yy format (27 Feb 96). The creation time is a
  326. /// 8-byte oypcbi in hh:mm:ss format (13:12:15).
  327. /// </remarks>
  328. public static ReturnCode spssGetTimeStamp(int handle, out string fileDate, out string fileTime)
  329. {
  330. fileDate = new string(' ', SPSS_DATESTAMP_LENGTH + 1);
  331. fileTime = new string(' ', SPSS_TIMESTAMP_LENGTH + 1);
  332. ReturnCode result = SpssThinWrapper.spssGetTimeStampImpl(handle, ref fileDate, ref fileTime);
  333. fileDate = (result == ReturnCode.SPSS_OK) ? fileDate.Substring(0, fileDate.IndexOf('\0')) : null;
  334. fileTime = (result == ReturnCode.SPSS_OK) ? fileTime.Substring(0, fileTime.IndexOf('\0')) : null;
  335. return result;
  336. }
  337. /// <summary>
  338. /// Gets the string value of a variable.
  339. /// </summary>
  340. /// <param name="handle">
  341. /// Handle to the data file.
  342. /// </param>
  343. /// <param name="varHandle">
  344. /// Handle of the variable.
  345. /// </param>
  346. /// <param name="value">
  347. /// Value of the string variable.
  348. /// </param>
  349. /// <returns>
  350. /// <see cref="ReturnCode.SPSS_OK"/>,
  351. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  352. /// <see cref="ReturnCode.SPSS_OPEN_WRMODE"/>,
  353. /// <see cref="ReturnCode.SPSS_INVALID_CASE"/>,
  354. /// <see cref="ReturnCode.SPSS_STR_EXP"/>, or
  355. /// <see cref="ReturnCode.SPSS_BUFFER_SHORT"/>.
  356. /// </returns>
  357. /// <remarks>
  358. /// This function gets the value of a string variable for the current case, which is the case
  359. /// read by the most recent call to <see cref="SpssThinWrapper.spssReadCaseRecordDelegate"/>.
  360. /// </remarks>
  361. public static ReturnCode spssGetValueChar(int handle, double varHandle, out string value)
  362. {
  363. value = new string(' ', SPSS_MAX_LONGSTRING + 1); // leave room for null terminator
  364. ReturnCode result = SpssThinWrapper.spssGetValueCharImpl(handle, varHandle, ref value, value.Length);
  365. if (result == ReturnCode.SPSS_BUFFER_SHORT)
  366. {
  367. value = new string(' ', SPSS_MAX_VERYLONGSTRING + 1);
  368. result = SpssThinWrapper.spssGetValueCharImpl(handle, varHandle, ref value, value.Length);
  369. }
  370. value = (result == ReturnCode.SPSS_OK) ? value.Substring(0, value.IndexOf('\0')) : null;
  371. return result;
  372. }
  373. /// <summary>
  374. /// Gets the alignment of a variable.
  375. /// </summary>
  376. /// <param name="handle">
  377. /// Handle to the data file.
  378. /// </param>
  379. /// <param name="varName">
  380. /// Variable name.
  381. /// </param>
  382. /// <param name="alignment">
  383. /// Alignment of the variable.
  384. /// </param>
  385. /// <returns>
  386. /// <see cref="ReturnCode.SPSS_OK"/>,
  387. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  388. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>, or
  389. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>.
  390. /// </returns>
  391. /// <remarks>
  392. /// This function reports the value of the alignment attribute of a variable.
  393. /// </remarks>
  394. public static ReturnCode spssGetVarAlignment(int handle, string varName, out AlignmentCode alignment)
  395. {
  396. return SpssThinWrapper.spssGetVarAlignmentImpl(handle, ref varName, out alignment);
  397. }
  398. /// <summary>
  399. /// Gets the missing values of a short string variable.
  400. /// </summary>
  401. /// <param name="handle">
  402. /// Handle to the data file.
  403. /// </param>
  404. /// <param name="varName">
  405. /// Variable name.
  406. /// </param>
  407. /// <param name="missingFormat">
  408. /// Missing value format code.
  409. /// </param>
  410. /// <param name="missingVal1">
  411. /// First missing value.
  412. /// </param>
  413. /// <param name="missingVal2">
  414. /// Second missing value.
  415. /// </param>
  416. /// <param name="missingVal3">
  417. /// Third missing value.
  418. /// </param>
  419. /// <returns>
  420. /// <see cref="ReturnCode.SPSS_OK"/>,
  421. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  422. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  423. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>,
  424. /// <see cref="ReturnCode.SPSS_STR_EXP"/>, or
  425. /// <see cref="ReturnCode.SPSS_SHORTSTR_EXP"/>.
  426. /// </returns>
  427. /// <remarks>
  428. /// This function reports the missing values of a short string variable. The value of
  429. /// <paramref>missingFormat</paramref> will indicate
  430. /// the number of missing values. The
  431. /// appropriate number of missing values is copied to the <paramref>missingVal1</paramref>,
  432. /// <paramref>missingVal2</paramref>, and <paramref>missingVal3</paramref> parameters.
  433. /// </remarks>
  434. public static ReturnCode spssGetVarCMissingValues(int handle, string varName, out MissingValueFormatCode missingFormat, out string missingVal1, out string missingVal2, out string missingVal3)
  435. {
  436. missingVal1 = new string(' ', SPSS_MAX_SHORTSTRING + 1);
  437. missingVal2 = new string(' ', SPSS_MAX_SHORTSTRING + 1);
  438. missingVal3 = new string(' ', SPSS_MAX_SHORTSTRING + 1);
  439. ReturnCode result = SpssThinWrapper.spssGetVarCMissingValuesImpl(handle, ref varName, out missingFormat,
  440. ref missingVal1, ref missingVal2, ref missingVal3);
  441. if (missingFormat < MissingValueFormatCode.SPSS_THREE_MISSVAL)
  442. missingVal3 = null;
  443. else
  444. missingVal3 = (result == ReturnCode.SPSS_OK) ? missingVal3.Substring(0, missingVal3.IndexOf('\0')) : null;
  445. if (missingFormat < MissingValueFormatCode.SPSS_TWO_MISSVAL)
  446. missingVal2 = null;
  447. else
  448. missingVal2 = (result == ReturnCode.SPSS_OK) ? missingVal2.Substring(0, missingVal2.IndexOf('\0')) : null;
  449. if (missingFormat < MissingValueFormatCode.SPSS_ONE_MISSVAL)
  450. missingVal1 = null;
  451. else
  452. missingVal1 = (result == ReturnCode.SPSS_OK) ? missingVal1.Substring(0, missingVal1.IndexOf('\0')) : null;
  453. return result;
  454. }
  455. /// <summary>
  456. /// Gets the width of a variable.
  457. /// </summary>
  458. /// <param name="handle">
  459. /// Handle to the data file.
  460. /// </param>
  461. /// <param name="varName">
  462. /// Variable name.
  463. /// </param>
  464. /// <param name="columnWidth">
  465. /// Column width.
  466. /// </param>
  467. /// <returns>
  468. /// <see cref="ReturnCode.SPSS_OK"/>,
  469. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  470. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>, or
  471. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>.
  472. /// </returns>
  473. /// <remarks>
  474. /// This function reports the value of the column width attribute of a variable. A value of
  475. /// zero is special and means that the SPSS Data Editor, which is the primary user of this
  476. /// attribute, will set an appropriate width using its own algorithm.
  477. /// </remarks>
  478. public static ReturnCode spssGetVarColumnWidth(int handle, string varName, out int columnWidth)
  479. {
  480. return SpssThinWrapper.spssGetVarColumnWidthImpl(handle, ref varName, out columnWidth);
  481. }
  482. /// <summary>
  483. /// Gets the name and type of a variable.
  484. /// </summary>
  485. /// <param name="handle">
  486. /// Handle to the data file.
  487. /// </param>
  488. /// <param name="iVar">
  489. /// Zero origin variable number.
  490. /// </param>
  491. /// <param name="varName">
  492. /// Variable name.
  493. /// </param>
  494. /// <param name="varType">
  495. /// Variable type.
  496. /// </param>
  497. /// <returns>
  498. /// <see cref="ReturnCode.SPSS_OK"/>,
  499. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  500. /// <see cref="ReturnCode.SPSS_INVALID_FILE"/>,
  501. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>, or
  502. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>.
  503. /// </returns>
  504. /// <remarks>
  505. /// This function gets the name and type of one of the variables present in a data file. It
  506. /// serves the same purpose as <see cref="spssGetVarNames"/> but returns the information one variable
  507. /// at a time and, therefore, can be passed to a Visual Basic program.
  508. /// The type code is an integer in the range 0–255, 0 indicating a numeric
  509. /// variable and a positive value indicating a string variable of that size.
  510. /// </remarks>
  511. public static ReturnCode spssGetVarInfo(int handle, int iVar, out string varName, out int varType)
  512. {
  513. varName = new string(' ', SpssSafeWrapper.SPSS_MAX_VARNAME + 1);
  514. ReturnCode result = SpssThinWrapper.spssGetVarInfoImpl(handle, iVar, ref varName, out varType);
  515. varName = (result == ReturnCode.SPSS_OK) ? varName.Substring(0, varName.IndexOf('\0')) : null;
  516. return result;
  517. }
  518. /// <summary>
  519. /// Gets the handle for a named variable.
  520. /// </summary>
  521. /// <param name="handle">
  522. /// Handle to the data file.
  523. /// </param>
  524. /// <param name="varName">
  525. /// Variable name.
  526. /// </param>
  527. /// <param name="varHandle">
  528. /// Handle for the variable.
  529. /// </param>
  530. /// <returns>
  531. /// <see cref="ReturnCode.SPSS_OK"/>,
  532. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  533. /// <see cref="ReturnCode.SPSS_DICT_NOTCOMMIT"/>,
  534. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  535. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>, or
  536. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  537. /// </returns>
  538. /// <remarks>
  539. /// This function returns a handle for a variable, which can then be used to read or write
  540. /// (depending on how the file was opened) values of the variable. If handle is associated
  541. /// with an output file, the dictionary must be written with <see cref="SpssThinWrapper.spssCommitHeaderDelegate"/>
  542. /// before variable handles can be obtained via spssGetVarHandle.
  543. /// </remarks>
  544. public static ReturnCode spssGetVarHandle(int handle, string varName, out double varHandle)
  545. {
  546. return SpssThinWrapper.spssGetVarHandleImpl(handle, ref varName, out varHandle);
  547. }
  548. /// <summary>
  549. /// Gets the variable label for some named variable.
  550. /// </summary>
  551. /// <param name="handle">
  552. /// Handle to the data file.
  553. /// </param>
  554. /// <param name="varName">
  555. /// Variable name.
  556. /// </param>
  557. /// <param name="varLabel">
  558. /// Variable label.
  559. /// </param>
  560. /// <returns>
  561. /// <see cref="ReturnCode.SPSS_OK"/>,
  562. /// <see cref="ReturnCode.SPSS_NO_LABEL"/>,
  563. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  564. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>, or
  565. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>.
  566. /// </returns>
  567. /// <remarks>
  568. /// This function copies the label of variable <paramref>varName</paramref> into
  569. /// <paramref>varLabel</paramref>. To get labels more than 120 characters long, use
  570. /// the spssGetVarLabelLong function.
  571. /// </remarks>
  572. public static ReturnCode spssGetVarLabel(int handle, string varName, out string varLabel)
  573. {
  574. int len;
  575. varLabel = new string(' ', SPSS_MAX_LONGSTRING + 1); // leave room for null terminator
  576. ReturnCode result = spssGetVarLabelLongImpl(handle, ref varName, ref varLabel, varLabel.Length, out len);
  577. varLabel = (result == ReturnCode.SPSS_OK) ? varLabel.Substring(0, len) : varLabel = null;
  578. return result;
  579. }
  580. /// <summary>
  581. /// Gets the measurement level of a variable.
  582. /// </summary>
  583. /// <param name="handle">
  584. /// Handle to the data file.
  585. /// </param>
  586. /// <param name="varName">
  587. /// Variable name.
  588. /// </param>
  589. /// <param name="measureLevel">
  590. /// Measurement level.
  591. /// </param>
  592. /// <returns>
  593. /// <see cref="ReturnCode.SPSS_OK"/>,
  594. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  595. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>, or
  596. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>.
  597. /// </returns>
  598. /// <remarks>
  599. /// This function reports the value of the measurement level attribute of a variable.
  600. /// </remarks>
  601. public static ReturnCode spssGetVarMeasureLevel(int handle, string varName, out MeasurementLevelCode measureLevel)
  602. {
  603. int measureLevelInt;
  604. ReturnCode status = SpssThinWrapper.spssGetVarMeasureLevelImpl(handle, ref varName, out measureLevelInt);
  605. measureLevel = (MeasurementLevelCode)measureLevelInt;
  606. return status;
  607. }
  608. /// <summary>
  609. /// Gets the missing values of a numeric variable.
  610. /// </summary>
  611. /// <param name="handle">
  612. /// Handle to the data file.
  613. /// </param>
  614. /// <param name="varName">
  615. /// Variable name.
  616. /// </param>
  617. /// <param name="missingFormat">
  618. /// Missing value format code.
  619. /// </param>
  620. /// <param name="missingVal1">
  621. /// First missing value.
  622. /// </param>
  623. /// <param name="missingVal2">
  624. /// Second missing value.
  625. /// </param>
  626. /// <param name="missingVal3">
  627. /// Third missing value.
  628. /// </param>
  629. /// <returns>
  630. /// <see cref="ReturnCode.SPSS_OK"/>,
  631. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  632. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  633. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>, or
  634. /// <see cref="ReturnCode.SPSS_NUME_EXP"/>.
  635. /// </returns>
  636. /// <remarks>
  637. /// This function reports the missing values of a numeric variable. The value of
  638. /// <paramref>missingFormat</paramref> determines the interpretation of
  639. /// <paramref>missingVal1</paramref>, <paramref>missingVal2</paramref>, and
  640. /// <paramref>missingVal3</paramref>. If missingFormat is SPSS_MISS_RANGE,
  641. /// <paramref>missingVal1</paramref> and <paramref>missingVal2</paramref>
  642. /// represent the upper and lower limits, respectively, of the range, and
  643. /// <paramref>missingVal3</paramref> is not used. If missingFormat is
  644. /// SPSS_MISS_RANGEANDVAL, <paramref>missingVal1</paramref> and
  645. /// <paramref>missingVal2</paramref> represent the range and
  646. /// <paramref>missingVal3</paramref> is the discrete missing value.
  647. /// If missingFormat is neither of the above, it will be in the range
  648. /// 0–3, indicating the number of discrete missing
  649. /// values present. (The macros SPSS_NO_MISSVAL, SPSS_ONE_MISSVAL,
  650. /// SPSS_TWO_MISSVAL, and SPSS_THREE_MISSVAL may be used as synonyms for 0–3.)
  651. /// </remarks>
  652. public static ReturnCode spssGetVarNMissingValues(int handle, string varName, out MissingValueFormatCode missingFormat, out double missingVal1, out double missingVal2, out double missingVal3)
  653. {
  654. return SpssThinWrapper.spssGetVarNMissingValuesImpl(handle, ref varName, out missingFormat, out missingVal1, out missingVal2, out missingVal3);
  655. }
  656. /// <summary>
  657. /// Gets the value label for a variable.
  658. /// </summary>
  659. /// <param name="handle">
  660. /// Handle to the data file.
  661. /// </param>
  662. /// <param name="varName">
  663. /// Variable name.
  664. /// </param>
  665. /// <param name="value">
  666. /// Short string value for which the label is wanted.
  667. /// </param>
  668. /// <param name="label">
  669. /// Label for the value.
  670. /// </param>
  671. /// <returns>
  672. /// <see cref="ReturnCode.SPSS_OK"/>,
  673. /// <see cref="ReturnCode.SPSS_NO_LABELS"/>,
  674. /// <see cref="ReturnCode.SPSS_NO_LABEL"/>,
  675. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  676. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  677. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>,
  678. /// <see cref="ReturnCode.SPSS_STR_EXP"/>,
  679. /// <see cref="ReturnCode.SPSS_SHORTSTR_EXP"/>, or
  680. /// <see cref="ReturnCode.SPSS_EXC_STRVALUE"/>.
  681. /// </returns>
  682. /// <remarks>
  683. /// This function gets the value label for a given value of a short string variable.
  684. /// </remarks>
  685. public static ReturnCode spssGetVarCValueLabel(int handle, string varName, string value, out string label)
  686. {
  687. int len;
  688. label = new string(' ', SPSS_MAX_VALLABEL + 1);
  689. ReturnCode result = spssGetVarCValueLabelLongImpl(handle, ref varName, ref value, ref label, label.Length, out len);
  690. label = (result == ReturnCode.SPSS_OK) ? label.Substring(0, len) : null;
  691. return result;
  692. }
  693. /// <summary>
  694. /// Gets the value label for a given value of a numeric variable.
  695. /// </summary>
  696. /// <param name="handle">
  697. /// Handle to the data file.
  698. /// </param>
  699. /// <param name="varName">
  700. /// Variable name.
  701. /// </param>
  702. /// <param name="value">
  703. /// Numeric value for which the label is wanted.
  704. /// </param>
  705. /// <param name="label">
  706. /// Label for the value.
  707. /// </param>
  708. /// <returns>
  709. /// <see cref="ReturnCode.SPSS_OK"/>,
  710. /// <see cref="ReturnCode.SPSS_NO_LABELS"/>,
  711. /// <see cref="ReturnCode.SPSS_NO_LABEL"/>,
  712. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  713. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  714. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>, or
  715. /// <see cref="ReturnCode.SPSS_NUME_EXP"/>.
  716. /// </returns>
  717. /// <remarks>
  718. /// This function gets the value label for a given value of a numeric variable.
  719. /// </remarks>
  720. public static ReturnCode spssGetVarNValueLabel(int handle, string varName, double value, out string label)
  721. {
  722. int len;
  723. label = new string(' ', SPSS_MAX_VALLABEL + 1); // leave room for null terminator
  724. ReturnCode result = spssGetVarNValueLabelLong(handle, ref varName, value, ref label, label.Length, out len);
  725. if (result == ReturnCode.SPSS_OK)
  726. label = label.Substring(0, len);
  727. else
  728. label = null;
  729. return result;
  730. }
  731. /// <summary>
  732. /// Gets print formatting information for a variable.
  733. /// </summary>
  734. /// <param name="handle">
  735. /// Handle to the data file.
  736. /// </param>
  737. /// <param name="varName">
  738. /// Variable name.
  739. /// </param>
  740. /// <param name="printType">
  741. /// Print format type code (file spssdio.h defines macros of
  742. /// the form <see cref="FormatTypeCode">SPSS_FMT_...</see> for all valid format type codes)
  743. /// </param>
  744. /// <param name="printDec">
  745. /// Number of digits after the decimal.
  746. /// </param>
  747. /// <param name="printWidth">
  748. /// Print format width.
  749. /// </param>
  750. /// <returns>
  751. /// <see cref="ReturnCode.SPSS_OK"/>,
  752. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  753. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>, or
  754. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>.
  755. /// </returns>
  756. /// <remarks>
  757. /// This function reports the print format of a variable. Format type, number of decimal
  758. /// places, and field width are returned as <paramref>printType</paramref>,
  759. /// <paramref>printDec</paramref>, and <paramref>printWid</paramref>, respectively.
  760. /// </remarks>
  761. public static ReturnCode spssGetVarPrintFormat(int handle, string varName, out FormatTypeCode printType, out int printDec, out int printWidth)
  762. {
  763. return SpssThinWrapper.spssGetVarPrintFormatImpl(handle, ref varName, out printType, out printDec, out printWidth);
  764. }
  765. /// <summary>
  766. /// Gets the write format of a variable.
  767. /// </summary>
  768. /// <param name="handle">
  769. /// Handle to the data file
  770. /// </param>
  771. /// <param name="varName">
  772. /// Variable name
  773. /// </param>
  774. /// <param name="writeType">
  775. /// Pointer to write format type code (file spssdio.h defines macros of
  776. /// the form <see cref="FormatTypeCode">SPSS_FMT_...</see> for all valid format type codes)
  777. /// </param>
  778. /// <param name="writeDec">
  779. /// Pointer to number of digits after the decimal
  780. /// </param>
  781. /// <param name="writeWidth">
  782. /// Pointer to write format width
  783. /// </param>
  784. /// <returns>
  785. /// <see cref="ReturnCode.SPSS_OK"/>,
  786. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  787. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>, or
  788. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>.
  789. /// </returns>
  790. /// <remarks>
  791. /// This function reports the write format of a variable. Format type, number of decimal
  792. /// places, and field width are returned as writeType, writeDec, and writeWid,
  793. /// respectively.
  794. /// </remarks>
  795. public static ReturnCode spssGetVarWriteFormat(int handle, string varName, out FormatTypeCode writeType, out int writeDec, out int writeWidth)
  796. {
  797. return SpssThinWrapper.spssGetVarWriteFormatImpl(handle, ref varName, out writeType, out writeDec, out writeWidth);
  798. }
  799. /// <summary>
  800. /// Opens an SPSS file for appending cases.
  801. /// </summary>
  802. /// <param name="fileName">
  803. /// Name of the file.
  804. /// </param>
  805. /// <param name="handle">
  806. /// Handle to the opened file.
  807. /// </param>
  808. /// <returns>
  809. /// <see cref="ReturnCode.SPSS_OK"/>,
  810. /// <see cref="ReturnCode.SPSS_FITAB_FULL"/>,
  811. /// <see cref="ReturnCode.SPSS_FILE_OERROR"/>,
  812. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>,
  813. /// <see cref="ReturnCode.SPSS_FILE_RERROR"/>,
  814. /// <see cref="ReturnCode.SPSS_INVALID_FILE"/>,
  815. /// <see cref="ReturnCode.SPSS_NO_TYPE2"/>,
  816. /// <see cref="ReturnCode.SPSS_NO_TYPE999"/>, or
  817. /// <see cref="ReturnCode.SPSS_INCOMPAT_APPEND"/>.
  818. /// </returns>
  819. /// <remarks>
  820. /// This function opens an SPSS data file for appending cases and returns a handle that
  821. /// should be used for subsequent operations on the file.
  822. /// </remarks>
  823. public static ReturnCode spssOpenAppend(string fileName, out int handle)
  824. {
  825. return SpssThinWrapper.spssOpenAppendImpl(ref fileName, out handle);
  826. }
  827. /// <summary>
  828. /// Creates a new SPSS data file, with a dictionary copied from an existing file.
  829. /// </summary>
  830. /// <param name="fileName">
  831. /// Name of the new file.
  832. /// </param>
  833. /// <param name="dictFileName">
  834. /// Name of existing file.
  835. /// </param>
  836. /// <param name="handle">
  837. /// Handle of the new file.
  838. /// </param>
  839. /// <returns>
  840. /// <see cref="ReturnCode.SPSS_OK"/>,
  841. /// <see cref="ReturnCode.SPSS_FITAB_FULL"/>,
  842. /// <see cref="ReturnCode.SPSS_FILE_OERROR"/>,
  843. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>,
  844. /// <see cref="ReturnCode.SPSS_FILE_RERROR"/>,
  845. /// <see cref="ReturnCode.SPSS_INVALID_FILE"/>,
  846. /// <see cref="ReturnCode.SPSS_NO_TYPE2"/>, or
  847. /// <see cref="ReturnCode.SPSS_NO_TYPE999"/>.
  848. /// </returns>
  849. /// <remarks>
  850. /// This function opens a file in preparation for creating a new SPSS data file and initializes
  851. /// its dictionary from that of an existing SPSS data file. It is useful when you want to modify
  852. /// the dictionary or data of an existing file or replace all of its data. The typical sequence
  853. /// of operations is to call <see cref="spssOpenWriteCopy"/> (newFileName, oldFileName, ...) to open a
  854. /// new file initialized with a copy of the old file’s dictionary, then <see cref="spssOpenRead"/> (oldFile-
  855. /// Name, ...) to open the old file to access its data.
  856. /// </remarks>
  857. public static ReturnCode spssOpenWriteCopy(string fileName, string dictFileName, out int handle)
  858. {
  859. return SpssThinWrapper.spssOpenWriteCopyImpl(ref fileName, ref dictFileName, out handle);
  860. }
  861. /// <summary>
  862. /// Sets the case weight variable in a data file.
  863. /// </summary>
  864. /// <param name="handle">
  865. /// Handle to the data file.
  866. /// </param>
  867. /// <param name="varName">
  868. /// The name of the case weight variable.
  869. /// </param>
  870. /// <returns>
  871. /// <see cref="ReturnCode.SPSS_OK"/>,
  872. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  873. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  874. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>,
  875. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  876. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>,
  877. /// <see cref="ReturnCode.SPSS_NUME_EXP"/>, or
  878. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  879. /// </returns>
  880. /// <remarks>
  881. /// This function defines variable varName as the case weight variable for the data file
  882. /// specified by the handle.
  883. /// </remarks>
  884. public static ReturnCode spssSetCaseWeightVar(int handle, string varName)
  885. {
  886. return SpssThinWrapper.spssSetCaseWeightVarImpl(handle, ref varName);
  887. }
  888. /// <summary>
  889. /// Sets the Trends date variable information.
  890. /// </summary>
  891. /// <param name="handle">
  892. /// Handle to the data file.
  893. /// </param>
  894. /// <param name="dateInfo">
  895. /// Array containing date variables information.
  896. /// </param>
  897. /// <returns>
  898. /// <see cref="ReturnCode.SPSS_OK"/>,
  899. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  900. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  901. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>,
  902. /// <see cref="ReturnCode.SPSS_INVALID_DATEINFO"/>, or
  903. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  904. /// </returns>
  905. /// <remarks>
  906. /// This function sets the Trends date variable information. The array at dateInfo is
  907. /// assumed to have numofElements elements that correspond to the data array portion of
  908. /// record 7, subtype 3. Its first six elements comprise the “fixed” information, followed
  909. /// by a sequence of one or more three-element groups. Since very little validity checking
  910. /// is done on the input array, this function should be used with caution and is
  911. /// recommended only for copying Trends information from one file to another.
  912. /// </remarks>
  913. unsafe public static ReturnCode spssSetDateVariables(int handle, int[] dateInfo)
  914. {
  915. return SpssThinWrapper.spssSetDateVariablesImpl(handle, dateInfo.Length, (int*)Marshal.UnsafeAddrOfPinnedArrayElement(dateInfo, 0));
  916. }
  917. /// <summary>
  918. /// Sets the first block of Data Entry information.
  919. /// </summary>
  920. /// <param name="handle">
  921. /// Handle to the data file.
  922. /// </param>
  923. /// <param name="data">
  924. /// Data to be written.
  925. /// </param>
  926. /// <returns>
  927. /// <see cref="ReturnCode.SPSS_OK"/>,
  928. /// <see cref="ReturnCode.SPSS_EMPTY_DEW"/>,
  929. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  930. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  931. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>,
  932. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>, or
  933. /// <see cref="ReturnCode.SPSS_FILE_BADTEMP"/>.
  934. /// </returns>
  935. /// <remarks>
  936. /// DEW information (file information which is private to the SPSS Data Entry product)
  937. /// can be delivered to the I/O DLL in whatever segments are convenient for the client.
  938. /// The spssSetDEWFirst function is called to deliver the first such segment, and
  939. /// subsequent segments are delivered by calling spssSetDEWNext as many times as
  940. /// necessary.
  941. /// </remarks>
  942. public static ReturnCode spssSetDEWFirst(int handle, string data)
  943. {
  944. return SpssThinWrapper.spssSetDEWFirstImpl(handle, ref data, data.Length);
  945. }
  946. /// <summary>
  947. /// Sets the unique Data Entry uniqueness GUID.
  948. /// </summary>
  949. /// <param name="handle">
  950. /// Handle to the data file.
  951. /// </param>
  952. /// <param name="asciiGUID">
  953. /// The GUID to be stored on the file.
  954. /// </param>
  955. /// <returns>
  956. /// <see cref="ReturnCode.SPSS_OK"/>,
  957. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  958. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  959. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>, or
  960. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  961. /// </returns>
  962. /// <remarks>
  963. /// This function stores the Data Entry for Windows uniqueness indicator on the data file.
  964. /// It should only be used by the DEW product.
  965. /// </remarks>
  966. public static ReturnCode spssSetDEWGUID(int handle, string asciiGUID)
  967. {
  968. return SpssThinWrapper.spssSetDEWGUIDImpl(handle, ref asciiGUID);
  969. }
  970. /// <summary>
  971. /// Sets the next block of information for Data Entry.
  972. /// </summary>
  973. /// <param name="handle">
  974. /// Handle to the data file.
  975. /// </param>
  976. /// <param name="data">
  977. /// Data to be written.
  978. /// </param>
  979. /// <returns>
  980. /// <see cref="ReturnCode.SPSS_OK"/>,
  981. /// <see cref="ReturnCode.SPSS_DEW_NOFIRST"/>,
  982. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  983. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  984. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>,
  985. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>, or
  986. /// <see cref="ReturnCode.SPSS_FILE_BADTEMP"/>.
  987. /// </returns>
  988. /// <remarks>
  989. /// The DEW information (file information that is private to the SPSS Data Entry product)
  990. /// can be delivered to the I/O DLL in whatever segments are convenient for the client.
  991. /// The spssSetDEWFirst function is called to deliver the first such segment, and
  992. /// subsequent segments are delivered by calling spssSetDEWNext as many times as
  993. /// necessary.
  994. /// </remarks>
  995. public static ReturnCode spssSetDEWNext(int handle, string data)
  996. {
  997. return SpssThinWrapper.spssSetDEWNextImpl(handle, ref data, data.Length);
  998. }
  999. /// <summary>
  1000. /// Sets the file label of a data file.
  1001. /// </summary>
  1002. /// <param name="handle">
  1003. /// Handle to the data file.
  1004. /// </param>
  1005. /// <param name="id">
  1006. /// File label. The length of the string should not exceed
  1007. /// <see cref="SpssThinWrapper.SPSS_MAX_IDSTRING"/> characters.
  1008. /// </param>
  1009. /// <returns>
  1010. /// <see cref="ReturnCode.SPSS_OK"/>,
  1011. /// <see cref="ReturnCode.SPSS_EXC_LEN64"/>
  1012. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1013. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>, or
  1014. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>.
  1015. /// </returns>
  1016. /// <remarks>
  1017. /// This function sets the file label of the output SPSS data file associated with handle to
  1018. /// the given string id.
  1019. /// </remarks>
  1020. public static ReturnCode spssSetIdString(int handle, string id)
  1021. {
  1022. return SpssThinWrapper.spssSetIdStringImpl(handle, ref id);
  1023. }
  1024. /// <summary>
  1025. /// Sets multiple response definitions to a data file.
  1026. /// </summary>
  1027. /// <param name="handle">
  1028. /// Handle to the data file.
  1029. /// </param>
  1030. /// <param name="mrespDefs">
  1031. /// ASCII string containing definitions.
  1032. /// </param>
  1033. /// <returns>
  1034. /// <see cref="ReturnCode.SPSS_OK"/>,
  1035. /// <see cref="ReturnCode.SPSS_EMPTY_MULTRESP"/>
  1036. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1037. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  1038. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>, or
  1039. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  1040. /// </returns>
  1041. /// <remarks>
  1042. /// This function is used to write multiple response definitions to the file. The definitions
  1043. /// consist of a single null-terminated ASCII string which is similar to that containing the
  1044. /// variable set definitions.
  1045. /// </remarks>
  1046. public static ReturnCode spssSetMultRespDefs(int handle, string mrespDefs)
  1047. {
  1048. return SpssThinWrapper.spssSetMultRespDefsImpl(handle, ref mrespDefs);
  1049. }
  1050. /// <summary>
  1051. /// Sets the text data from the string in textInfo.
  1052. /// </summary>
  1053. /// <param name="handle">
  1054. /// Handle to the data file
  1055. /// </param>
  1056. /// <param name="textInfo">
  1057. /// Text data
  1058. /// </param>
  1059. /// <returns>
  1060. /// <see cref="ReturnCode.SPSS_OK"/>,
  1061. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1062. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  1063. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>, or
  1064. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  1065. /// </returns>
  1066. /// <remarks>
  1067. /// This function sets the text data from the null-terminated string in textInfo. If the string is
  1068. /// longer than 255 characters, only the first 255 are (quietly) used. If textInfo contains the
  1069. /// empty string, existing text data, if any, is deleted.
  1070. /// </remarks>
  1071. public static ReturnCode spssSetTextInfo(int handle, string textInfo)
  1072. {
  1073. return SpssThinWrapper.spssSetTextInfoImpl(handle, ref textInfo);
  1074. }
  1075. /// <summary>
  1076. /// Sets the value of a string variable.
  1077. /// </summary>
  1078. /// <param name="handle">
  1079. /// Handle to the data file.
  1080. /// </param>
  1081. /// <param name="varHandle">
  1082. /// Handle to the variable.
  1083. /// </param>
  1084. /// <param name="value">
  1085. /// Value of the variable. The length of the
  1086. /// string (ignoring trailing blanks, if any) should be less than or equal
  1087. /// to the length of the variable.
  1088. /// </param>
  1089. /// <returns>
  1090. /// <see cref="ReturnCode.SPSS_OK"/>,
  1091. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1092. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  1093. /// <see cref="ReturnCode.SPSS_DICT_NOTCOMMIT"/>,
  1094. /// <see cref="ReturnCode.SPSS_STR_EXP"/>, or
  1095. /// <see cref="ReturnCode.SPSS_EXC_STRVALUE"/>.
  1096. /// </returns>
  1097. /// <remarks>
  1098. /// This function sets the value of a string variable for the current case. The current case is
  1099. /// not written out to the data file until <see cref="SpssThinWrapper.spssCommitCaseRecordDelegate"/> is called.
  1100. /// </remarks>
  1101. public static ReturnCode spssSetValueChar(int handle, double varHandle, string value)
  1102. {
  1103. return SpssThinWrapper.spssSetValueCharImpl(handle, varHandle, ref value);
  1104. }
  1105. /// <summary>
  1106. /// Sets the alignment of a variable.
  1107. /// </summary>
  1108. /// <param name="handle">
  1109. /// Handle to the data file.
  1110. /// </param>
  1111. /// <param name="varName">
  1112. /// Variable name.
  1113. /// </param>
  1114. /// <param name="alignment">
  1115. /// Alignment. If not a legal
  1116. /// value, alignment is set to a type-appropriate default.
  1117. /// </param>
  1118. /// <returns>
  1119. /// <see cref="ReturnCode.SPSS_OK"/>,
  1120. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1121. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  1122. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>,
  1123. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>, or
  1124. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>.
  1125. /// </returns>
  1126. /// <remarks>
  1127. /// This function sets the value of the alignment attribute of a variable.
  1128. /// </remarks>
  1129. public static ReturnCode spssSetVarAlignment(int handle, string varName, AlignmentCode alignment)
  1130. {
  1131. return SpssThinWrapper.spssSetVarAlignmentImpl(handle, ref varName, alignment);
  1132. }
  1133. /// <summary>
  1134. /// Sets missing values for a short string variable.
  1135. /// </summary>
  1136. /// <param name="handle">
  1137. /// Handle to the data file.
  1138. /// </param>
  1139. /// <param name="varName">
  1140. /// Variable name.
  1141. /// </param>
  1142. /// <param name="missingFormat">
  1143. /// The number of missing values (0-3) actually supplied.
  1144. /// </param>
  1145. /// <param name="missingVal1">
  1146. /// First missing value.
  1147. /// </param>
  1148. /// <param name="missingVal2">
  1149. /// Second missing value.
  1150. /// </param>
  1151. /// <param name="missingVal3">
  1152. /// Third missing value.
  1153. /// </param>
  1154. /// <returns>
  1155. /// <see cref="ReturnCode.SPSS_OK"/>,
  1156. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1157. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  1158. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>,
  1159. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  1160. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>,
  1161. /// <see cref="ReturnCode.SPSS_STR_EXP"/>,
  1162. /// <see cref="ReturnCode.SPSS_SHORTSTR_EXP"/>,
  1163. /// <see cref="ReturnCode.SPSS_INVALID_MISSFOR"/>,
  1164. /// <see cref="ReturnCode.SPSS_EXC_STRVALUE"/>, or
  1165. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  1166. /// </returns>
  1167. /// <remarks>
  1168. /// This function sets missing values for a short string variable. The argument
  1169. /// missingFormat must be set to a value in the range 0–3 to indicate the number of missing
  1170. /// values supplied. When fewer than three missing values are to be defined, the redundant
  1171. /// arguments must still be present, although their values are not inspected. For example,
  1172. /// if missingFormat is 2, missingVal3 is unused. The supplied missing values must be nullterminated
  1173. /// and not longer than the length of the variable unless the excess length is
  1174. /// made up of blanks, which are ignored. If the missing value is shorter than the length of
  1175. /// the variable, trailing blanks are assumed.
  1176. /// </remarks>
  1177. public static ReturnCode spssSetVarCMissingValues(int handle, string varName, MissingValueFormatCode missingFormat, string missingVal1, string missingVal2, string missingVal3)
  1178. {
  1179. return SpssThinWrapper.spssSetVarCMissingValuesImpl(handle, ref varName, missingFormat,
  1180. ref missingVal1, ref missingVal2, ref missingVal3);
  1181. }
  1182. /// <summary>
  1183. /// Sets the column width of a variable.
  1184. /// </summary>
  1185. /// <param name="handle">
  1186. /// Handle to the data file.
  1187. /// </param>
  1188. /// <param name="varName">
  1189. /// Variable name.
  1190. /// </param>
  1191. /// <param name="columnWidth">
  1192. /// Column width. If negative, a value of zero is (quietly) used instead.
  1193. /// </param>
  1194. /// <returns>
  1195. /// <see cref="ReturnCode.SPSS_OK"/>,
  1196. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1197. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  1198. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>,
  1199. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>, or
  1200. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>.
  1201. /// </returns>
  1202. /// <remarks>
  1203. /// This function sets the value of the column width attribute of a variable. A value of zero
  1204. /// is special and means that the SPSS Data Editor, which is the primary user of this
  1205. /// attribute, is to set an appropriate width using its own algorithm.
  1206. /// </remarks>
  1207. public static ReturnCode spssSetVarColumnWidth(int handle, string varName, int columnWidth)
  1208. {
  1209. return SpssThinWrapper.spssSetVarColumnWidthImpl(handle, ref varName, columnWidth);
  1210. }
  1211. /// <summary>
  1212. /// Sets the label of a variable.
  1213. /// </summary>
  1214. /// <param name="handle">
  1215. /// Handle to the data file.
  1216. /// </param>
  1217. /// <param name="varName">
  1218. /// Variable name.
  1219. /// </param>
  1220. /// <param name="varLabel">
  1221. /// Variable label. The length of the string should not exceed
  1222. /// <see cref="SpssThinWrapper.SPSS_MAX_VARLABEL"/> characters.
  1223. /// If varLabel is the empty string, the existing label, if any, is deleted.
  1224. /// </param>
  1225. /// <returns>
  1226. /// <see cref="ReturnCode.SPSS_OK"/>,
  1227. /// <see cref="ReturnCode.SPSS_EXC_LEN120"/>,
  1228. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1229. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  1230. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>,
  1231. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  1232. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>, or
  1233. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  1234. /// </returns>
  1235. /// <remarks>
  1236. /// This function sets the l…

Large files files are truncated, but you can click here to view the full file