LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

pass contains of a combo box to a variable

How is it possible to pass the contains which I insert into a combo box to a variable in lab windows.
do you have an example
thank you
regardsd
samuel
0 Kudos
Message 1 of 8
(4,522 Views)
Hi Samuel,

Take a look at the combo box sample under CVIXX\samples\userint\custctrl\combobox.  It will show you some of the details of using a combo box custom control.  The main thing to notice is the callback function, PictureSelect (which I have copied below), installed on the combo box.  You will need to create a callback for your combo box, then read the control value (GetCtrlVal) into a buffer when the callback processes the EVENT_COMMIT event.  This event is fired when the user selects an option from the pulldown menu, or if the control loses focus after the user has been typing in it.  The sample program also interprets typing the Enter key as a commit event, which you may also wish to do.

int CVICALLBACK PictureSelect (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{
    char *value;
    int vKey, length;
   
    switch (event)
    {
        case EVENT_KEYPRESS:
            vKey = eventData1 & VAL_VKEY_MASK;
            if (vKey != VAL_ENTER_VKEY) /* fake an EVENT_COMMIT if Enter Pressed */
                break;
        case EVENT_COMMIT:
            GetCtrlAttribute (panel, control, ATTR_STRING_TEXT_LENGTH, &length);
            value = (char *)malloc(length+1);
            GetCtrlVal (panel, control, value);
            
            ... /* do something with value */            

            free(value);
            break;
    }
    return 0;
}

Hope this helps you out.

Mert A.
National Instruments
0 Kudos
Message 2 of 8
(4,517 Views)
I have done this now. How can I debug into the callback function. when I set a breakpoint in the callback function, I never reach this breakpoint. I want to see if the code in the callback function is ok.
regards samuel
0 Kudos
Message 3 of 8
(4,504 Views)
Hi Samuel,

My guess is that you haven't added the callback function to your combo box control.  The callback will only get called if you install it on a control.  The easiest way to do this is to add the name of your callback in your .uir.  Open your .uir, double click on your combo box, then in the dialog that pops up, you'll see a control labeled "Callback Function" right below the constant name.  Put the name of you callback there, then rebuild your app.

If this doesn't fix your problem, let me know.

Mert A.
National Instruments
0 Kudos
Message 4 of 8
(4,493 Views)
Hello Mert,
thank you for your help
I have replaced the lines :
 
 Combo_NewComboBox (MainPanelCallback, MAINPANEL_STRING);
 InputComboValues (MainPanelCallback, MAINPANEL_STRING);
 
with:
 
Combo_NewComboBox (gMainWindow.panel, MAINPANEL_STRING);
 InputComboValues (gMainWindow.panel, MAINPANEL_STRING);
 
 
is that what you mean?
 
 
 
Although I have replaced it I get the  following error meassages now: 
  Undefined symbol '_Combo_NewComboBox@8' referenced in "TestExec.c".
  Undefined symbol '_Combo_InsertComboItem@16' referenced in "TestExec.c".
 
regards samuel

0 Kudos
Message 5 of 8
(4,474 Views)
Samuel,

We are really talking about 3 different issues, I think.  Replacing MainPanelCallback with gMainWindow.panel is the fix I suggested for your invalid parameter error in this thread.  It sounds like you are not getting that error anymore.

The second problem you mentioned was your callback not firing.  The fix for that would be to make sure your callback is installed on your combo box control (as described earlier in this thread).

By solving your previous compilation error, you have now exposed these new link errors, which mean that the compiler cannot find implementations for the combo box functions.  You are including "combobox.h", but you also need to add the combobox.fp file to your project.  Select Edit>>Add Files To Project...>>Instrument (*.fp) and pick CVIXX\toolslib\custctrl\combobox.fp to add to your project.  This will solve your problem.

Good luck.

Mert A.
National Instruments
0 Kudos
Message 6 of 8
(4,458 Views)

Hello,

The problem: I can't add Combo Box.

I add String Control. I also included "combobox.h", and combobox.fp file to the project. 

I already look at the example: "combodemo".

Even when i tryed to copy exactly the "combodemo" example to a new project it didn't work.

 

The error shown on screen when I'm trying debug the project:

 

3 Project link errors
Undefined symbol '_Combo_NewComboBox@8' referenced in "MyOwnCombo.c".
Undefined symbol '_Combo_DiscardComboBox@8' referenced in "MyOwnCombo.c".
Undefined symbol '_Combo_InsertComboItem@16' referenced in "MyOwnCombo.c".

 

Thanks

0 Kudos
Message 7 of 8
(3,741 Views)

Loading ComboBox.fp to your Instrument Libraries should eliminate that error. If the FP cannot locate combobox.obj, then you also get a popup error the first time you build. Did you get that? If so, then check to see if combobox.obj is located at C:\Program Files (x86)\National Instruments\CVI2010\toolslib\custctrl\msvc\combobox.obj

 

Alternatively, the source code is provided, so you can just add combobox.c to your project and you should be good to go.

National Instruments
0 Kudos
Message 8 of 8
(3,717 Views)