Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...This was the ONLY place that I could find information that I could use to resolve the problem. So thanks once again to member TomSark and the SQL forum!..."

Geography

Where in the world do Tek-Tips members come from?
castgb (Programmer)
25 Jul 12 12:36
I still have problems with Clipper code to convert to VFP9.
I will return an error code in the red line,

append from

why?

Gianni


CODE -->

******************inizio processo di creazione attivit…***********
use giorni
index on giorno to gio
set index to gio
GOTO TOP
DO WHILE .NOT. EOF()
STORE RECNO() TO NREC_GIO
store giorNO to mgiorno
STORE GIORNO TO MGIO


     use dipend
        do while .not. eof()
        store recno() to nrec_dip
        store badge to mbadge
        STORE BADGE TO MBAD
        store nome to mnome
        store alltrim(file)+".dbf" to mfile

        use prd1 EXCLUSIVE 
        zap
        append from prd.dbf for giorno=mgiorno .and. badge=mbadge
        use
        
        USE prd1
        SORT ON DA TO PRD2
        use

       use PRD2
        goto top
        store recno() to nrec_tmp
        store e_u to me_u
        do while .not. eof()
        store recno() to nrec_tmp
        store e_u to me_u

       if me_u="E"
        
             
        if NREC_TMP<RECCOUNT()
        SKIP
        STORE E_U TO mE_U
        store da to mda
        store numero to mnumero
        
        GOTO NREC_TMP
        IF ME_U="U" 
        REPLACE E_U WITH "U"
        ENDIF
        replace a with mda
        replace numero with mnumero
        
        endif
       endif

      if me_u=" "
        GOTO NREC_TMP  
                  

        if NREC_TMP<RECCOUNT()
        SKIP
        STORE E_U TO mE_U
        store da to mda
        store numero to mnumero

        GOTO NREC_TMP
        IF ME_U="U" 
        REPLACE E_U WITH "U"
        ENDIF

        replace a with mda
        replace numero with mnumero
        ENDIF
      endif

      skip
      enddo
        DELETE ALL FOR E_U="U" .AND. EMPTY(A)
        DELETE ALL FOR EMPTY(E_U) .AND. EMPTY(A)
        PACK
        close all
        **** PRD2
       ***********************trasporto ore e lavorazioni negli archivi
       ***********************dei dipendenti
       use prd2
       do while .not. eof()
        store recno() to nrec_prod
        STORE DA TO MDA
        STORE A TO MA
        store val(numero) to mnumero
        store ore to more
        store e_u to me_u
       use elelav
       locate for numero=mnumero
       if found()
          store identific to mident
       ELSE
          MIDENT=" "
       endif
       use (mfile)
       locate for day(data)=day(mgio) .and. month(data)=month(mgio)
       *if .not. found()
       append blank
       replace data with mgio
       REPLACE DA WITH MDA
       REPLACE A WITH MA
       replace n_lav with mnumero
       replace descr with mident
       if empty(mda) .or. empty(ma)
       replace n_ore with 0
       else
       min11=(VAL(SUBSTR(mda,1,2))*60)+(VAL(SUBSTR(mda,4,2)))  
       min22=(VAL(SUBSTR(ma,1,2))*60)+(VAL(SUBSTR(ma,4,2)))  
       
       REPLACE N_ORE WITH (min22/60)-(min11/60)

       replace e_u with me_u
       endif
       *endif
       use
       use prd2
       GOto nrec_prod
       SKIP
       ENDDO
       USE PRD2
       ZAP
       USE
       

     use dipend
     goto nrec_dip
     skip
     enddo


use giorni index gio
goto nrec_gio
skip
enddo
********************fine ciclo giorni 

MikeLewis (Programmer)
25 Jul 12 13:17
It would be much easier for us to help you if we knew what the error code was.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy

castgb (Programmer)
25 Jul 12 14:02
Sorry Mike, forgot
returns: "giorno" variable not found ...
bat "giorno" not is variable..is field of table
as if he saw the PRD table from which data should be taken ..
maybe I have to open it first?

thanks Gianni
MikeLewis (Programmer)
25 Jul 12 15:18
Gianni,

If Giorno is a field in Giorni, then you are right. Giorni is not open at the time that you do the Append.

The problem is that you are opening several tables, but they are all in the same work area. Each time you open a table in a given work area, it will close whatever other table was already open in that area. That's why you are getting the error.

The preferred way of doing it is like this:

CODE

USE SomeTable IN 0
SELECT SomeTable 

That way, each table is in a separate work area.

Actually, your problem goes deeper than that. You appear to be constantly opening and closing tables inside your nested loops. That won't cause the error you are seeing, but it is not good practice. In general, you open a table once, and leave it open until you don't need it any more.

I suspect that this a relic of the time when we were only allowed ten open tables (or two, in the case of dBASE II).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy

danfreeman (Programmer)
25 Jul 12 15:58
There's another problem here, and it's one where Clipper behaves differently than Foxpro.

The FOR clause of APPEND FROM is scoped to the currently selected table, NOT from the "from" table. From the help file:

Quote:


FOR lExpression
Appends a new record for each record in the currently selected table for which lExpression evaluates to True (.T.).

A far better (and more Fox-like) way to do this would be:

CODE

Insert Into prd1 ;
  Select * from prd ;
  Where prd.giorno=mgiorno .and. prd.badge=mbadge 

(This would accidentally mitigate the file opening problem, but take Mike's advice on that anyway.)
castgb (Programmer)
26 Jul 12 1:58
Thanks to all
I understand I have to use SQL ..
I am converting a huge program written with Clipper Summer 87 but I have to rewrite so I correct the errors a little at a time.
But not being an expert in FoxPro often happens to me does not understand the logic.

I used:

CODE -->

Insert Into prd1 ;
  Select * from prd ;
  Where prd.giorno=mgiorno .and. prd.badge=mbadge 

and works

thanks Gianni
danfreeman (Programmer)
26 Jul 12 10:22
Glad it worked!

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close