LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Strange bug

Hello all,
I think it's a bug in my prog rather than in CVI, but I can't explain it so
far:

I have a number of ring controls, all with identical items. When I set them
to various values, some fail:

for (i=0; i<NbRings; i++) {
SetCtrlVal(Rep, Ctrl[i], Values[i]);
CallCtrlCallback(Rep, Ctrl[i], EVENT_COMMIT, 0, 0, NULL);
}


// This is the common callback for all Ctrl[]
int CVICALLBACK cb_SelectItem (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2) {
int V;
switch (event) {
case EVENT_COMMIT:
GetCtrlVal(panel, control, &V);
// After a (repeatable) number of the above iterations, V is zero instead of
Values[i]

This could happen if the ring had no item of value Values[i], but that is
not the case...
SetCtrlVal changes the internal value immediately, even if the control
hasn't been redrawn yet, right ?
--
Guillaume Dargaud
http://www.gdargaud.net/


0 Kudos
Message 1 of 5
(3,806 Views)

Well, you could try checking for error return values for SetCtrlVal(), (and GetCtrlVal(), while you're at it) just to be absolutely sure you are addressing the control you think you are. You say that the number of iterations is repeatable - is there a clue here? (eg the Nth ring is accidentally a double one, not an int.)

 

JR

0 Kudos
Message 2 of 5
(3,799 Views)
> Well, you could try checking&nbsp;for error return values for
> SetCtrlVal(),
> (and&nbsp;GetCtrlVal(), while you're at it) just to be absolutely sure you
> are
> addressing the control you think you are. You say that the number of
> iterations is
> repeatable - is there a clue here? (eg the Nth ring is accidentally
> a&nbsp;double one,
> not an int.)&nbsp;JR

I did put a GetCtrlVal immediately after the Set and it returned 0... which
lead me to the fact that the ring was incompletely initialized (some code
sequences were out of order).

So I found the problem, but maybe SetCtrlVal should return some kind of
error when a value is not available in a ring, in addition to defaulting to
whatever it wants...
--
Guillaume Dargaud
http://www.gdargaud.net/


0 Kudos
Message 3 of 5
(3,790 Views)

Hey Guillaume,

 

If you are trying to change the value of one of the indices in the ring control, you should use ReplaceListItem.  SetCtrlVal sets the active item of a ring control to the first of its items that matches a given value.  

 

NickB

National Instruments  

0 Kudos
Message 4 of 5
(3,780 Views)

I'll just rephrase NickB in order to make it clear for myself.

Please correct me if I'm wrong.

 

For a ring, SetCtrlVal function changes the current selected item of a ring control to the one with the value given as the 3rd parameter to SetCtrlVal.

In order to be able to do it, sometime before that, some code (or the uir editor) should add some value-label pairs to that ring control.

 

If this is not obeyed, then the behaviour will not be correct.

So, probably the code given starts to fail, when it starts to set values to rings that do not have that values already.

S. Eren BALCI
IMESTEK
0 Kudos
Message 5 of 5
(3,765 Views)