08-12-2010 09:18 AM - edited 08-12-2010 09:21 AM
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?
Solved! Go to Solution.
08-13-2010 12:46 AM
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))
08-13-2010 06:46 AM - edited 08-13-2010 06:49 AM
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?
08-15-2010 03:20 PM
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);
08-16-2010 02:52 AM
thnx roberto.. it worked...