LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

listbox

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

0 Kudos
Message 1 of 8
(4,366 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 8
(4,363 Views)

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.

0 Kudos
Message 3 of 8
(4,330 Views)

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.

0 Kudos
Message 4 of 8
(4,315 Views)

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.

0 Kudos
Message 5 of 8
(4,310 Views)

 

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....

 

0 Kudos
Message 6 of 8
(4,307 Views)

Hi agyna,

 

Are you still having trouble with this?

Tanya Visser
National Instruments
LabVIEW Group Manager
0 Kudos
Message 7 of 8
(4,148 Views)

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.

0 Kudos
Message 8 of 8
(4,136 Views)