A Better Way to Program Controls of the Same Kind in LabWindows/CVI
Usually, there are only one or two controls of the same kind in a normal VI(Virtual Instruments, computer based measurements and automation systems) application. And, we can write the callback functions of these controls one by one in LabWindows/CVI. But, if there are more than four in number of the same kind of control, it’ll be a hard work to write the callback functions one by one for them.
If the controls have similar functions, it’s a better idea to make them use the same callback function. It save a lot of time and make the program short and simple. Every control on the UI(User Interface) has a unique reference ID, we could build an array of reference IDs to store the ID information of every control on UI. And, in the callback function, the parameter “control” can be used to identify which control is functioning. And a loop in the callback function can be used to find out the right execution code and run it.
Code can be like this:
[sourcecode language='c']
int iControlIDs[n]; //The definition of the ID array
…….
CallbackFunction(……) //The callback function
{
for(i=0; i
if(control == iControlIDs[i])
{
…… //The execution code of the control
}
}
}
[/sourcecode]
It will make the code short and simple. And will save a lot time from writing callback function code to each control separately.
No related posts.