LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Obtaining current value of a ring control

Solved!
Go to solution

21251iB7BA29401886BDAE

I have a ring control that has the following values. See attacment. I need to get the current value of it and use it as an input for another function, But at fiirst i would like to get the ciurrent value and save it ina text file. I tried this

 

if (event == EVENT_LEFT_CLICK_UP) || (event == EVENT_LEFT_CLICK_DOWN)
{
	int p;	
	GetCtrlVal (panelHandle, PANEL_RINGSLIDE_1, &p);
	FILE *OutFile = fopen("C:\\Users\\Student\\Desktop\\ringtest.txt","w");
	fprintf(OutFile,p);
	fclose(OutFile);

}

 I need to get the current value of the ring ( &p) to be written in the ringtest.txt file.

 

Also i need to use this value (&p) as another input in the same program.

i.e value of &p have to be used in

 

b = c*5; where c has the value of current &p.

 

Can any 1 help?

 

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 1 of 5
(3,701 Views)

Hi,

 

I could not understand where do you need the help?

Do you get compile/runtime errors or is it just the text file not appearing in the folder you specified?

 

Btw, you need to put extra paranthesis on the if statement:

 

if ((event == EVENT_LEFT_CLICK_UP) || (event == EVENT_LEFT_CLICK_DOWN))
S. Eren BALCI
IMESTEK
Message 2 of 5
(3,680 Views)

When compiling there occurs two errors. For one of them, I found oiut the reason. I think  "EVENT_LEFT_CLICK_DOWN" is not available or valid one. . there is only EVENT_LEFT_CLICK_UP. so i removed it. But I need to get the current value when ever there is a change in the slider. so I chnaged it to "EVENT_VAL_CHANGED". I hope it will work.

 

The second error is :

 

Type error in argument 2 to `fprintf'; found 'int' expected 'pointer to const char'.

 

any ideas?

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 3 of 5
(3,664 Views)
Solution
Accepted by topic author Nghtcrwlr

You're right: EVENT_LEFT_CLICK_DOWN is not a valid event for CVI. Valid events are listed in userint.h file and are the only events that can be trapped in a control callback. On the other hand, you're assuption on EVENT_VAL_CHANGED is correct: you can trap it forgetting EVENT_CLICK_UP event.

 

As per the second question, looking at the definition for fprintf you must pass a format string as the second parameter to the function, next the value for write to the file. In your case, the correct syntax is:

fprintf (OutFile, "%d", p);

 

 

fprintf(OutFile,p);


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?
Message 4 of 5
(3,627 Views)

thnx roberto.. it worked...

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 5 of 5
(3,615 Views)