LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

write in a text file

You can look at fpeditor.prj sample located in <cvidir>\samples\apps\fpeditor: BrowseForFile function is exactly what you need, a callback function that uses FileSelectPopup to locate a file on disk.

Note, however, that FileSelectPopup function DOES NOT do anything on the selected file: it is aimed to returning the pathname of the file, leaving to you the responsibility to operate on it.



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?
0 Kudos
Message 21 of 44
(2,821 Views)
ok ...well..i bascially want to do this,

I want to generate a report file everytime i run the code...and i want to store this report file in one directory only.

What comman do i use....

isn't fH=Openfile (etc...) going to dump all that code into just one place...every single time?

i want to generate new report files like report1.csv
report2.csv
report3.csv

say in a folder that has path as C:\Project\FIles\Data\

why is this that hard to implement?it's pretty straightforward i think
0 Kudos
Message 22 of 44
(2,816 Views)
i've been trying to modify some code that there's been generated in this program

-------------------------------------------------------------------------------------------------------------------------
static void getRecommendedReportName(char reportFileName[], char reportPath[],
        char reportPathName[]) {

    char selectedStudyFile[MAX_PATHNAME_LEN];
    char driveName[MAX_PATHNAME_LEN];
    char dirName[MAX_PATHNAME_LEN];
    char fileName[MAX_PATHNAME_LEN];
    char temp[MAX_PATHNAME_LEN];
   
    /* this gets us the complete path and name to the selected study file */
//    (void) GetCtrlVal (panelHdl, PNL_REPORT_STR_STUDY_FILE_PATH,
//                               selectedStudyFile);  --------------->//i've commented this because it gave an error...the machine generated code said the PNL_REPORT_etc etc is an undeclared  //Identifier...it's something that's generated in a machine code .h file..i have a feeling this might be causing the error in reading the input file name.
 
           
    SplitPath (selectedStudyFile, driveName, dirName, fileName);
           
    /* extract just the name without extension */
    (void) Scan(fileName, "%s>%s[t46xq]", temp);
           
    /* add REPORT_FILE_SUFFIX to it to generate the suggested name */
    (void) Fmt(reportFileName, "%s[qw*]<%s%s", MAX_PATHNAME_LEN -1, temp,
            REPORT_FILE_SUFFIX);           
    /* construct the complete path to the selected report dir */
    (void) Fmt(reportPath, "%s[qw*]<%s%s", MAX_PATHNAME_LEN -1, driveName,
            dirName);
    /* the complete path name of the recommended report file */
    (void) Fmt(reportPathName, "%s[qw*]<%s%s", MAX_PATHNAME_LEN -1,reportPath,
            reportFileName);
           
    return;

}

is there basically a simpler way to get the filename,the path and plug it into this part of the code

------------------------------------------------------------------------------------------------------------SUPPRESS(715)  /* Standard CVI Callback method signature */
SUPPRESS(818)  /* Standard CVI Callback method signature */
int CVICALLBACK cmdSelectReportCB (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2) {

    int statusCode = AMI_ERROR;  
    char selectedFile[MAX_PATHNAME_LEN];
    char reportPathName[MAX_PATHNAME_LEN];
    char reportFileName[MAX_PATHNAME_LEN];
    char reportPath[MAX_PATHNAME_LEN]=REPORT_PATH;
   

    switch (event) {
        case EVENT_COMMIT:
       
            getRecommendedReportName(reportFileName, reportPath, reportPathName);            
       
            //statusCode = FileSelectPopup (reportPath, reportFileName,
            //        STUDY_FILENAME_EXT, "Select Report File", VAL_SAVE_BUTTON,
            //        FALSE, FALSE, TRUE, FALSE, selectedFile);
       
   
       
        statusCode = FileSelectPopup (reportPath, reportFileName,
                    STUDY_FILENAME_EXT1, "Select Report File", VAL_SAVE_BUTTON,
                    FALSE, FALSE, TRUE, FALSE, selectedFile);
           
            if (statusCode != VAL_NO_FILE_SELECTED) {                                       
                                                                                            
                (void) SetCtrlVal (panelHdl, PNL_REPORT_STR_REPOR_FILE_PATH,
                        selectedFile);
                                                                 
            }    
           
            break;
           
        default:

            break;
    }
    return 0;
}
--------------------------------------------------------------------------------------------------------------------

i'd like you to kindly send me an email regarding this...my email is abhayvnadkarni@yahoo.com

thanks a lot roberto



0 Kudos
Message 23 of 44
(2,783 Views)
isthere anyonethat can help me with the previous code fragment?
0 Kudos
Message 24 of 44
(2,744 Views)

nadster, take a look at the sample project attached. It:

  • permits the user to choose output directory via DirSelectPopup function
  • Scans the directory to search for existing files with a given pattern (TempData*.dat)
  • Generates a new filename with the first free index
  • writes the desired number of rows with "random" data

File I/O error checking is missing in the source code. I wrote some notes on error checking procedures that you can find here: you may find them useful while developing your error checking strategy.

Message Edited by Roberto Bozzolo on 02-21-2007 05:32 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?
0 Kudos
Message 25 of 44
(2,715 Views)
oh cool..thanks so much...i was also wondering about one more thing...is there any way to time stamp the out file name as in suppose i want the output file name by default to look like


*2-21-2007_13:20.csv  (i.e. *date_time.csv)


0 Kudos
Message 26 of 44
(2,704 Views)
It seems not so difficult to build the file name using date and time ...
Just look at my sample and modify it as you want!


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?
0 Kudos
Message 27 of 44
(2,701 Views)
Well..i wasn't saying with refrence to your source...i was trying to use FileSelectPopup and return the file with the path...

here's what i'm doing...
switch (event) {
        case EVENT_COMMIT:
       
      statusCode = FileSelectPopup (reportPath,"*.csv", STUDY_FILENAME_EXT1, "Select Report File", VAL_SAVE_BUTTON,
                    FALSE, FALSE, TRUE, TRUE, selectedFile);
           
            if (statusCode != VAL_NO_FILE_SELECTED) {
               
        //create the file name      
        sprintf(selectedFile,"CO %s_%s", DateStr(),TimeStr());
                (void) SetCtrlVal (panelHdl, PNL_REPORT_STR_REPOR_FILE_PATH,
                        selectedFile);
   
                MakePathname (reportPath,selectedFile,selectedFile);
                               }

so i basically want to timestamp the file that i choose by using MakePathname...it doesn't  seem to be working ... selectedFile is then got back via GetCtrlVal and is opened up to be written into...


0 Kudos
Message 28 of 44
(2,693 Views)
so it doesn't append the filename to the required directory specified by reportPath

that's the problem...it just  shows the sprintf argument without the pathname as a prefix...so it just doesn't save the file anywhere since the files not specified in any path...

the MakePathName should append selectedFile to the directory specified by reportPath...but it doesn't seem to work...
0 Kudos
Message 29 of 44
(2,695 Views)

It may happen that DateStr and TimeStr introduce in the pathname illegal caracthers: for example in a filename it's surey illegal the ":" separator included in hour string.

Anyway, you sould be able to obtain your filename. Is makePathname returning any error? Can you set a breakpoint on this function and verify the values passed to the it?



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?
0 Kudos
Message 30 of 44
(2,691 Views)