Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Field values from a variable
Message
De
16/09/1998 06:10:52
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00136777
Message ID:
00137190
Vues:
26
>>>I have a xtab query myself. I'm trying to limit the number of fields in a report to 16 the 1st field always. and loop back every 15 of the rest. Also I would like to break the loops (a do while and a for loop), when there is no more data. Here's what I have so far:
>>>
>>>SELECT xtab
>>>GO TOP
>>>lnFieldTot = 2
>>>DO WHILE !EOF()
>>>FOR lnFCnt = 1 TO 15
>>>SELECT xtab
>>>lcFName = FIELD(lnFieldTot)
>>>lcFCnt = STR(lnFCnt)
>>>IF lnFCnt < 10
>>>lcATAFName = "ATA_Report.project"+RIGHT(lcFCnt,1)
>>>ELSE
>>>lcATAFName = "ATA_Report.project"+RIGHT(lcFCnt,2)
>>>ENDIF
>>>IF lnFCnt = 1
>>>SELECT ATA_Report
>>>GO BOTTOM
>>>APPEND BLANK
>>>REPLACE ATA_Report.ata WITH xtab.exp_1
>>>ENDIF
>>>IF !EMPTY(lcFName)
>>>lnATAFValue = EVAL('xtab.'+lcFName)
>>>lcATAFValue = STR(lnATAFValue)
>>>SELECT ATA_Report
>>>GO BOTTOM
>>>REPLACE &lcATAFName WITH TRIM(lcATAFValue)&& WILL NOT DO REPLACE
>>>ENDIF
>>>lnFieldTot = lnFieldTot + 1
>>>IF lnFCnt = 15
>>>lnFCnt = 0
>>>ENDIF
>>>IF lnFieldTot > FCOUNT()
>>>llEnd = .T.
>>>EXIT
>>>ENDIF
>>>ENDFOR
>>>SELECT xtab
>>>SKIP
>>>IF EOF()
>>>IF!llEnd
>>>GO TOP
>>>ELSE
>>>EXIT
>>>ENDIF
>>>ENDIF
>>>ENDDO
>>>
>>>TIA
>>Perry,
>>I'm not sure I understood correctly but could this be what you want :
select xtab
>>lnNeededCopies = ceiling((fcount()-1)/15)
>>for ix = 1 to lnNeededCopies  && Create n copies
>>	lcFields = field(1)
>>	for kx=(ix-1)*15+1+iif(ix=1,1,0) to min(ix*15,fcount())
>>	    lcFields = lcFields + "," + field(kx)
>>	endfor
>>	select &lcFields from xtab ;
>>	    into table ("xtab"+padl(ix,3,"0"))
>>	use in ("xtab"+padl(ix,3,"0"))
>>	select xtab
>>endfor
Cetin
>
>
>I'm taking data from xtab and inserting it into the other table the whole trouble lies in this section:
>
>
>lnATAFValue = EVAL('xtab.'+lcFName)
>lcATAFValue = STR(lnATAFValue)
>SELECT ATA_Report
>GO BOTTOM
>REPLACE &lcATAFName WITH TRIM(lcATAFValue)&& WILL NOT DO REPLACE
>
>The program won;t execute the REPLACE command. I have another FOR loop that does the same with numeric fields and it works (identical syntax). I find it a little strange and frustrating to be honest.
OK Perry,
Reread (honestly just read) your code and now I think understood.
lcATAFName = "ATA_Report.project"+RIGHT(lcFCnt,1) && Or 2 instead of 1
*Now lcATAFName is something like "ATA_Report.project3"
SELECT ATA_Report
GO BOTTOM
* Wrong one that doesn't replace
* REPLACE &lcATAFName WITH TRIM(lcATAFValue)
* If you use macrosubstition it is interpreted as
* replace /ATA_Report.project3's value/ with ...
* but you want  ATA_Report.project3 as a field name - name expression
* Change to
REPLACE (lcATAFName) WITH TRIM(lcATAFValue)

* But in all I would code this section as
go bottom in "Ata_report"
replace (lcATAFName) with TRIM(lcATAFValue) in "Ata_report"
* So you don't need to change workalias on the fly
* Also you don't need to include alias in lcATAFName
While this would cease your replace problem after tracing your code I think it's a time consuming method. Why not also check the code I sent before and just change columnnames then append - might be faster ? Here is what it does :
Takes original xtab and splits into xtab001..xtab010...xtab0nn. Each xtabnnn table now has field(1) -description- + next block of 15 fields from original xtab. ie: xtab001 would have field(1)...field(15) of xtab, and xtab002 would have field(1),field(16)..field(30) of xtab and so on. I didn't touch fieldnames at all because at the end I would like to preserve them. Your report then could have field expressions as (still preserve one report definition but called n times) :
eval(field((repnumber-1)*15+iif(repnumber=1,1,0)+1))
eval(field((repnumber-1)*15+iif(repnumber=1,1,0)+2))...
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform