Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Cvs files date field missing

Posted on 2016-10-13
3
Medium Priority
?
76 Views
Last Modified: 2016-11-21
I want to collect the dates of each filename. I am getting all the data of each filename except the dates. The date comes from the filenames like the building number. The building in the filenames are being stored with the other data except the dates. The filenames, for example, looks like this 100_2016-10-03_20-31.  The first three numbers are the building numbers, then the date, and the _10-31 is the time. How can I get the dates stored as well?  I have received an error message with this code that is in the program.                                   FOR lnI = 1 TO m.LnCnt
      LcDateStr= Chrtran (StrExact(laFiles.         [m.lnI,1],'_','_')
The error message was File 'strexact.prg' does not exist.
       LdFileDate = Date (Val (m.lcDateStr),Val(Substr (m.lcDateStr,6)),Val (Substr (m.lcDateStr,AT ('-',m.lcDateStr,2)+1)))
DO ImportFile WITH m.lcPath, laFiles [m.lnI,1], m.ldFileDate

 The error message was Function argument value, type, or count is invalid.

OR IF I use the code below, I get an error message saying, " File 'strexact.prg' does not exist", and Function name is missing.
 

This is the code that is being used.

&&& CVS START

Create cursor mycursor (;
                              Building N (3,0), ;
                              Item no i,;
                              Quantity I , ;
                              Description c (21),;
                              Date d)

* ---- Load cursor with CSV data.

Set order to building ascending

Lcpath = "H:\\Obra\Ldy\"
LcFileMask="*.cvs"

LnCnt = ADIR (laFiles, m.lcPath + m.lcFileMask)

Set century on
Set date American

LOCAL lcFileName, ldFileDate, LcDateStr

FOR lnI = 1 TO m.LnCnt
      LcDateStr = Chrtran (StrExact (laFiles[m.lnI,1],'_','_')
      DO ImportFile WITH m.lcPath, laFiles [m.lnI,1], Date (&lcDateStr)
NEXT
SELECT Mycursor

Procedure Import File
LPARAMETERS lcPath, lcFileName, lcDate, lcFileMask
LOCAL lcLine, lnFH, lnBuilding, date, lcDateStr, FileName,

LnFH = FOPEN (m.lcPath +m.lcFileName)
IF m.lnFH > 0
   LnBuilding = VAL (m.lcFileName)
   FOR lnI= 1TO 3
          lcLine = FGETS (m.lnFH, 1000)
   NEXT
   DO WHILE !FEOF (m.lnFH)
         LcLine = FGETS (m.lnFH, 1000)
         LnA = VAL (LEFT (m.lcLine, AT (',', m.lcLine)-1))
         LcLine = Substr (m.lcLine, AT (',', m.lcLine)+1)
         LnB= VAL (LEFT (m.lcLine, AT (',', m.lcLine)-1))

         LcLine = SUBSTR (m.lcLine, AT (',', m.lcLine)+1
          LcC= ALLTRIM (SUBSTR (m.lcLine, AT ('"', m.lcLine)+1))
          LcC= LEFT(m.lcC, LEN (m.lcC)-1)
          INSERT INTO MyCursor (building, date, itemno, quantity, description) VALUES (m.lnBuilding, lcDateStr, m.lnA, m.lnB, m.lcC)

    ENDDO
    = FCLOSE (m.lnFH)
ELSE
ENDIF
0
Comment
Question by:campbme
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 43

Accepted Solution

by:
pcelba earned 2000 total points (awarded by participants)
ID: 41842467
First of all StrExact should be  STREXTRACT  (case does not matter but note two missing letters).
I'll write more but you may study this function in VFP help. The latest help version is available at http://vfpx.codeplex.com

Update:
This processing loop should work:
FOR lnI = 1 TO m.LnCnt
      LcDateStr = Chrtran (StrExTRact (laFiles[m.lnI,1],'_','_'), '-', ',')  &&  this will convert the filename to a string, e.g. "2016,10,31"
      DO ImportFile WITH m.lcPath, laFiles [m.lnI,1], Date (&lcDateStr)   && which can then be used as a macro parameter in the DATE() function
NEXT

Open in new window

A small update is also necessary in the INSERT command:
 INSERT INTO MyCursor (building, date, itemno, quantity, description) VALUES (m.lnBuilding, lcDateStr, m.lnA, m.lnB, m.lcC)
which contains lcDateStr invisible in this context

Correct command is:
 INSERT INTO MyCursor (building, date, itemno, quantity, description) VALUES (m.lnBuilding, lcDate, m.lnA, m.lnB, m.lcC)

where the lcDate is of date data type.
0
 
LVL 43

Expert Comment

by:pcelba
ID: 41863050
I've provided tested solution and my comments are explaining what was wrong in the original code. Lets wait a few more days for the author response.
0
 
LVL 43

Expert Comment

by:pcelba
ID: 41895617
The solution was tested and works correctly in my environment.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question