12-13-2010 05:04 PM
Hi there,
- I have 2 listbox with items in them. how can I read each items and write it to a text or csv file?
- I also have a string box where I have to write some name (a folder name). How can I use this name, and create a folder with that name?
Thanks.
agyna
12-13-2010 05:31 PM
Reading listbox items can be done in a loop with something like:
int idx, numItems;
char label[64];
GetNumListItems (panelHandle, PANEL_LISTBOX, &numItems);
for (idx = 0; idx < numItems; idx++) {
GetLabelFromIndex (panelHandle, PANEL_LISTBOX, idx, label);
}
File I/O can be obtained using function in ANSI C library or in Formatting And I/O library: you should take a look at those libraries and choose the best method to use based on your requirements. In doing this, consider that both TXT and CSV files are standard text files so you must open the file in ASCII mode and write to it separate lines adding the proper line feed character at the end of each line. If using Formatting And I/O Library functions, you can use WriteLine command that automatically ads the appropriate terminator if the file is opened in ASCII mode.
12-14-2010 10:50 AM
Sorry Roberto, I was not specific. Please see the attached picture:
I am trying to do this: I have 4 listbox. As shown on the picture, I would like to be able to read each selected items. From the selected items as shown on the picture I have to create a file to save in the folder. From the picture I have selected some items, so it would give me:
-AP 11 9 Full
-AP 9 9 Full
-AP 18 9 Full
-AP 11 11 Full
-AP 9 11 Full
-AP 18 11 Full
the name of the folder will be coming from the folder name box as shown on the picture.
Thank you for your help.
12-14-2010 11:44 AM
Maybe one could just give me some idea on how to print out the checked items. Meaning how to reading from each listbox (read it once checked).
Thank you.
12-14-2010 11:51 AM
Hi,
did you have a look at the sample provided with CVI, listbox.cws. It uses the functions IsListItemChecked, GetValueFromIndex and GetLabelFromIndex that should work for your case also.
12-14-2010 12:15 PM
I tried this, but this output is not good.
int CVICALLBACK SelectModulation (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int idx, numItems, checked, value;
char label[64];
GetNumListItems (panelTestDef, TEST_DEF_MODULATION_ID, &numItems);
for (idx = 0; idx < numItems; idx++) {
IsListItemChecked (panelTestDef, TEST_DEF_MODULATION_ID, idx, &checked);
if (checked) {
//
GetValueFromIndex (panelTestDef, TEST_DEF_MODULATION_ID, idx, &value);
//GetCtrlVal(panelTestDef, TEST_DEF_MODE_ID, &checked);
printf("%d\n",value);
}
}
return 0;
}
Here is output: for just selecting 11, 9 and 18:
11
11
11
11
11
11
9
11
9
11
9
1118
11
9
18
What sould I do to get 11 if I click 11, 8 if I click 8....
01-05-2011 11:18 AM
Hi agyna,
Are you still having trouble with this?
01-05-2011 12:50 PM - edited 01-05-2011 12:55 PM
agyna:
In your callback for the listbox, you need to check what event triggered the callback. Callbacks are triggered for multiple events more often than you would think, which could result in the repeated print statements you are seeing. Since you don't check what event triggered the callback, you are printing the value for each and every event. What event do you want to act on?
EVENT_COMMIT or EVENT_MARK_STATE_CHANGE or two of the more useful events for a listbox. Search CVI Help for "list box events", then go to List Box Control Overview, and then List Box Control Events to get the full list.
Normally a control callback has an if (event == EVENT_COMMIT) or a switch statement so you act only on the event of interest.