LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Getting string from control

Solved!
Go to solution

I am having a string control in the uir. This is entered by the user. ( something like a path).

How can I get this user entered path and use it as a path to save a file?  i have done something like this...is this correct??

The control has the constant name STRING_2.  I try to get the value from that control and assign it to a value pt_s.

 

Can any1 help?

 

double *pt_s;
pt_s = &s;
GetCtrlVal ( panelHandle, PANEL_STRING_2, pt_s );
int w;
FILE *OutFile = fopen("pt_p","w");
fprintf(OutFile,"This is a test to open,write and save something to a sig file");
fclose(OutFile);

 

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 1 of 15
(5,596 Views)

You need to reserve some actual space in your program for the string contents. Something along the lines:

 

    char string [512];

    GetCtrlVal (panelHandle, PANEL_STRING_2, string);

 

You can then pass this variable directly to fopen().

 

It seems from your code that you have some fundamental misunderstandings about programming in C - have you considered taking a course?

 

JR

 

 

0 Kudos
Message 2 of 15
(5,588 Views)
 char string [512];   
  GetCtrlVal (panelHandle, PANEL_STRING_2, string);
  int w;
  FILE *OutFile = fopen("string.txt","w");
  fprintf(OutFile,"This is a test to open,write and save something to a sig file");
  fclose(OutFile);

 

When i give the string obtained in the fopen(), it saves the file with name string.txt.I dont need that. I need to save the file as given in the user entered control.. For Example i give the input path as C:\\Users\\Student\\Desktop\\Tes33t.txt. The path, file name and format is already in this input. I just need to save the data enetred in to this file.

Nghtcwrlr

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

Use

  FILE *OutFile = fopen(string, "w");

The name of the file is the first argument to the function, when you use

  FILE *OutFile = fopen("string.txt","w");

you are telling fopen() to create a file named string.txt

 

There is also no reason for the line

   int w;

in your code.  The "w" in the argument to fopen() is also a string.

 

You might want to find a C tutorial.

Message 4 of 15
(5,575 Views)

ufff.. nw evrything getting complicted.

 

NON-FATAL RUN-TIME ERROR:   "StimulsSignalTestV3.c", line 195, col 9, thread id 0x00001E8C:   Library function error (return value == -4 [0xfffffffc]). Panel, pop-up, or menu bar handle is invalid

 

NON-FATAL RUN-TIME ERROR:   "StimulsSignalTestV3.c", line 199, col 25, thread id 0x00001E8C:   Library function error (return value == 0 [0x0]). (ENOENT) No such file or directory

 

FATAL RUN-TIME ERROR:   "StimulsSignalTestV3.c", line 201, col 17, thread id 0x00001E8C:   Null pointer argument to library function.

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 5 of 15
(5,569 Views)

ufff.. nw evrything getting complicted.

 

NON-FATAL RUN-TIME ERROR:   "StimulsSignalTestV3.c", line 195, col 9, thread id 0x00001E8C:   Library function error (return value == -4 [0xfffffffc]). Panel, pop-up, or menu bar handle is invalid

 

NON-FATAL RUN-TIME ERROR:   "StimulsSignalTestV3.c", line 199, col 25, thread id 0x00001E8C:   Library function error (return value == 0 [0x0]). (ENOENT) No such file or directory

 

FATAL RUN-TIME ERROR:   "StimulsSignalTestV3.c", line 201, col 17, thread id 0x00001E8C:   Null pointer argument to library function.

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 6 of 15
(5,569 Views)

Can you write your line 195 to 201 to see your problem. The first is maybe your panel handle which is not the same in your panel properties and in your fonction...

Cordialement,

Simon D.
CLA | Certified LabVIEW Architect
CTA | Certified TestStand Architect
Message 7 of 15
(5,564 Views)

thnx  Simon

 

The panel handle was not the same as in  panel properties and in my function. That was the problem. Now it worked. Thanks...

 

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 8 of 15
(5,560 Views)

I have aniothe rproblem in the same situation.

 

I obtain a file path in the main.c progrm.

 

GetCtrlVal (panelHandle, PANEL_STRING_2,string1); 

I defined this string1 outside the main like this:

char string1 [512];

 

and i created another common.h file which included :

extern char string1 [512];

 

so that i can call string1 in another function.

 

 

Now i need its value(string1) in another test.c file. I tried like this :

 

FILE *OutFile = fopen(string1,"w");

 

But i got this error. why is this:

 

error:

NON-FATAL RUN-TIME ERROR:   "generate.c", line 14, col 21, thread id 0x00000718:   Library function error (return value == 0 [0x0]). (EINVAL) Invalid argument

 

thanks

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 9 of 15
(5,475 Views)

What was the actual contents of string1 at the point the error occurred? The CVI debugger should be able to tell you - break into your program and hover the mouse over the variable name. It is likely to be an illegal OS path/filename.

 

JR

0 Kudos
Message 10 of 15
(5,468 Views)