09-28-2011 04:15 PM
int rows; char **table_array; char save_file_name[MAX_PATH]; if (FileSelectPopup ("", "*.csv", "*.csv", "Select File Name to Save", VAL_SAVE_BUTTON, 0, 1, 1, 1, save_file_name) > 0) { GetNumTableRows(mainHandle,PANEL_LOGGING,&rows); table_array = malloc(rows*6*sizeof(char *)); GetTableCellRangeVals (mainHandle, PANEL_LOGGING, MakeRect(1,1,rows,6), table_array, VAL_ROW_MAJOR); ArrayToFile (save_file_name, table_array, VAL_STRING, 6*rows, rows, VAL_GROUPS_TOGETHER, VAL_GROUPS_AS_ROWS, VAL_SEP_BY_COMMA, 10, VAL_ASCII, VAL_TRUNCATE); FreeTableValStrings(table_array,rows*6); free(table_array); } break;
Doing this outputs a file with 5 commas on two lines (3rd line empty). But no data/strings are saved within them. (CVI 2010SP1)
The data in the array is sorted such the first 6 elements are row 1, next 6 are row 2, etc.
Any ideas?
Thanks
09-29-2011 04:43 AM
Hi ngay,
CVI2010 should be able to treat strings, at least this datatype is available in the function whereas it was not till CVI2009 (see function help for 2010 and 2009) so I don't understand what's happening.
I don't have a 2010 machine ready at the moment but I can offer you an alternative using the clipboard:
int fH = 0; char *table_array; ClipboardPutTableVals (panel, Impo_c, VAL_TABLE_ENTIRE_RANGE); ClipboardGetText (&table_array, NULL); fH = OpenFile ("test.txt", VAL_WRITE_ONLY, VAL_TRUNCATE, VAL_ASCII); WriteFile (fH, table_array, strlen (table_array)); CloseFile (fH); free (table_array);
This code actually saves the table content into the clipboard, then retrieves it and writes it to a file. Text is automatically separated into rows / cols with tab as column separator.
Note that I have used VAL_TABLE_ENTIRE_RANGE to select all the table, but yo can tailor this parameter to the exact table range you want (actually that macro translates to the appropriate MakeRange statement).
A benefit of using the clipboard is that you can retrieve data of several data types (e.g. numeric and strings, don't know what it does with images) in a single pass.
07-11-2013 09:42 AM
did you ever get the ArrayToFile to work with the string words