LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I get a string from a control ?

I'm a new user of Labwindows/cvi.
I have a problem with control.
I have made some controls and I use GetCtrlVal to get the value from them.
I have no problem with the controls with doubleand integer values, but when I'm trying to get a string from a control I get an error.
 
I use the function like this :
 
GetCtrlVal (panelHandle,PANEL_STRING,&model_number);
 
When I define my variable like this :     char model_number[]="";
then CVI runs the program but after putiing some data in the box and try to enter the program breaks and I get this message :
 
 FATAL RUN-TIME ERROR:   "UGI.c", line 108, col 50, thread id 0x00000A78:   Invalid argument type: found 'pointer to array 1 of char', expected 'pointer to char'.
When I define my variable like this :     char model_number;
then CVI runs the program but after putiing some data in the box and try to enter the program breaks and I get this message :
 
FATAL RUN-TIME ERROR:   "UGI.c", line 102, col 56, thread id 0x00000DCC:   Argument too small.
 
How can I solve this problem ?
 
Thanks for any help ?
0 Kudos
Message 1 of 3
(3,801 Views)

You need to reserve space in your program for the string to be stored in, so use something like:

    char model_number [100];

The syntax for the library call to fill in this string with data from the control is like this:

    GetCtrlVal (panelHandle, PANEL_STRING, model_number);

Note the & operator is not needed in this case. (The name of any array is treated by C compilers as the address of the first element of the array, without needing the address operator.)

Good luck!

JR

Message 2 of 3
(3,791 Views)

The usual way is to define an array of characters wide enough to store the whole control string, next pass it to GetCtrlVal function. Please note that you don't need to add the indirect operator ( & ) since any array name is really a pointer to its first element.

 char  msg[128];

 GetCtrlVal (panelHandle, control, msg);

 

Ouch! That's what happens when you open a page to answer some question and suddenly somebody comes to speak with you! Smiley Wink

Message Edited by Roberto Bozzolo on 02-09-2007 05:39 PM



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 3 of 3
(3,791 Views)