LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Opening File Popup 3 times

I have created a small application to create output analog voltages.  I am currently trying to implement code to load an "*.ini" file that simply has a list of values in it (one on each line).  I have a LOAD_DEFAULTS button created in the uir file with the callback function LoadDefaults.  The problem that happens is when I click the button when the application is running, the dialog box ends up appearing three times.  So, I'll click the button, box opens, select file, hit Load, box opens, select file, hit Load, box opens, select file hit Load, values appear.
 
Also, when I hit the "Quit" button, the Load dialog box appears as well.  The Quit Callback function has no reference to the LoadDefaults function.
 
The function is below and the only reference to LoadDefaults in the .uir or the .c file is for the button.  Does anyone know what could be happening?  Thanks.
 
Here's the code:
 
int CVICALLBACK LoadDefaults (int panel, int control, int event,
    void *callbackData, int eventData1, int eventData2)
{
  if(EVENT_COMMIT)
  { 
     int i;
     if (FileSelectPopup ("", "*.ini", "*.ini", "Default File to Load",
         VAL_LOAD_BUTTON, 0, 1, 1, 0, defaults_file_name) > 0)
     {
   
        FileToArray(defaults_file_name, default_settings, VAL_DOUBLE, 17, 1,
            VAL_GROUPS_TOGETHER, VAL_GROUPS_AS_ROWS, VAL_ASCII);
     
        ramp_voltage_ch0 = default_settings[0];
        SetCtrlAttribute( AO_PANEL, AO_PANEL_RAMP_VOLTAGE_CH0, ATTR_CTRL_VAL, ramp_voltage_ch0);         
        ramp_time_ch0 = default_settings[1];
        SetCtrlAttribute( AO_PANEL, AO_PANEL_RAMP_TIME_CH0, ATTR_CTRL_VAL, ramp_time_ch0);         
        peak_time_ch0 = default_settings[2];
        SetCtrlAttribute( AO_PANEL, AO_PANEL_PEAK_TIME_CH0, ATTR_CTRL_VAL, peak_time_ch0);         
        decay_time_ch0 = default_settings[3];     
        SetCtrlAttribute( AO_PANEL, AO_PANEL_DECAY_TIME_CH0, ATTR_CTRL_VAL, decay_time_ch0);          
        }
  }
  return 0;
}
0 Kudos
Message 1 of 3
(2,981 Views)

Hello,

I noticed you wrote "if(EVENT_COMMIT)" in your Callback Function instead of "if(event == EVENT_COMMIT)". Since EVENT_COMMIT is not equal to zero, your code will executed each time the callback function is called, which is several times when the button is clicked (with event set to EVENT_GOT_FOCUS, EVENT_LEFT_CLICK and EVENT_COMMIT).

I hope this solves your problem.

Greetings,

Wim

0 Kudos
Message 2 of 3
(2,975 Views)
It worked!  Thanks for the help!
0 Kudos
Message 3 of 3
(2,970 Views)