Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to combine records with visual foxpro 9

Status
Not open for further replies.

sfixis

IS-IT--Management
Mar 27, 2012
4
CY
hello,
i want to know how to combine several records into 1. i.e

rec1 = 123
rec2 = 123 456
rec3 = 456 789

The result i would like to have is:
rec1 = 123 456 789

Thanks
 
I hope this is for reporting, because storing data that way would be a bad idea.

What's the role of the spaces? Is a space always a separator? Is the number of spaces between items significant?

Tamar
 
If positin matters:

[tt]
rec1 = 123
rec2 = 123 456
rec3 = 456 789
--------------------------
result = 123 456 789
[/tt]

Then what should happen with such a situation?

[tt]
rec1 = 123
rec2 = 987 456
rec3 = 789 000
--------------------------
result = ????????????????
[/tt]

Giving an example is nice, but could you a bit more descriptive rules additional to that?

Bye, Olaf.
 
Hi,
Sorry if i confused you.i will explain again.
I have file from a customer(text file) which need to be printed
on an a4 paper.
A sample of the file received from the customer is as listed below:
*********************************************************
006
3 ABC
1 DEF
1 G
3
2 TEST
0 ____
0 TEST
2
1
1
3 ZZ
0 ZZ YY
0 YY XX
0 XX MMMMM
0 MMMMM LLLLLLL
0 LLLLLLL
1 12334455
***************************************************************
The first 3 chrs indicated the line position and the 4th chr indicate the line step. i.e the 'ABC' line will be printed on line 9 because i have '006' in first 3 chrs and '3' on the 4th chr,thus 6+3 = 9.
When on the 4th chr i have '0' this means that the printer will not jump a line but it will print again on top of the existing printout. This was used by the customer to print in Bold.
I have created a vfp code to read the original file and output into another text file with the records placed at the correct line number. A sample is listed below:
*******************************************








ABC
DEF
G




TEST
____
TEST






ZZ
ZZ YY
YY XX
XX MMMMM
MMMMM LL
LL
12334455
******************************************************

The desire output must be like listed below:
**********************************************************








ABC
DEF
G




TEST*this must me underline






ZZ YY XX MMMM LL
12334455
****************************************************
My problem is how to indicate on my vfp code to overwrite on top of the existing line without replacing the existing record and also how to place the underline under the existing chr.
I hope i have managed to brief you better now.
Regards
 
Yes, I begin to understand the problem. The essential info missing was this shoiuld emulate a printer. to print several lines on one line.

So overall these are rather instructions for a dotmatrix printer in two very easy operations: 1. feed N lines (N in the first 3 chars) 2. print the text after that number N.

And if the first part of the instruction is to move 0 lines, the same line gets printed on again. In a matrix printer that would make the same text printed twice result in a bold look and underline chars printed on the same line as text was previously printed would result in underlined text.

And now you want to "emulate" that printer, right?

This is impossible to do just with string merging. Still, if that partial solution will help you, this is how you could combine two strings into one:

Code:
LOCAL lcRow1, lcRow2, lcChar

lcRow1 = "+bcdef   "
lcRow2 = "xbc _ ghi"
lcCombinedRow = ""
For lnPosition = 1 TO LEN(lcRow2) && the same as Len(lcRow1) - important for the code to work
   lcChar = " "
   DO Case
      CASE SUBSTR(lcRow1,lnPosition,1) = SUBSTR(lcRow2,lnPosition,1)
           * Characters are equal, this can be merged, taking either one
           * Should actually get bold, can't be denoted in a string.
           lcChar = SUBSTR(lcRow1,lnPosition,1) 
      CASE SUBSTR(lcRow1,lnPosition,1) = " "
           * Row1 has a space, so take char of row2
           lcChar = SUBSTR(lcRow2,lnPosition,1)
      CASE SUBSTR(lcRow2,lnPosition,1) = " "
           * Row2 has a space, so take char of row1
           lcChar = SUBSTR(lcRow1,lnPosition,1)
      OTHERWISE
           * This is a problem case
           lcChar = "?" 
   ENDCASE
   lcCombinedRow = lcCombinedRow + lcChar
ENDFOR 
? lcCombinedRow

Actually, to emulate that printing, you would rather create an image and paint the text on it, repainting further text, in the case of feeding 0 lines, then finally printing that line graphic, or concatenating it to a larger graphic.

But it wouldn't result in bold text, then.

Another option might be processing this into an RTF string, in which you can denote bold printing by "/bA/b0" (bold A) and underline with "/uA/u0" (underlined A).

But you're lost with combinations like printing a +, then a x on the same place. You rather need a printer you can control the same way to keep this going.

Still, I hope that idea to process the rows char by char helps a bit on your way to a solution.

Bye, Olaf.
 
Hi, Thanks for your reply.
I will try it and i will let you know.something which i haven't mentioned is that after i create the output file i use crystal reports to print it, so the bold is not an issue because i can flag the lines with 0 'line step' and then via crystal reports i will make them bold.The main thing i want to do now is to be able to overwrite lines with 0 'line step' without replacing the line.
I will come back with feedback of your code. I'm listing my code below if you can help me modifying it.
Regards
****************************************************
WAIT WINDOW AT 15, 40 NOWAIT 'Please wait for UNIMSTM files preparation ...'
CLOSE DATABASES
IF FILE('C:\COMPANIES\UNIVERSAL\unimstm.txt')
ERASE 'C:\COMPANIES\UNIVERSAL\unimstm.txt'
ENDIF
IF FILE('AI1.DBF')
ERASE AI1.DBF
ENDIF
SET SAFETY OFF
SET TALK OFF
CREATE TABLE AI1 (f1 C (130))
CREATE TABLE AI2 (f1 C (131))
SELECT AI1
APPEND FROM 'C:\COMPANIES\UNIVERSAL\unistm.' TYPE SDF

GOTO top
REPLACE f1 WITH SUBSTR(f1,1,123) + SUBSTR(f1,4,1) ALL


GOTO TOP
ln = 0
DO WHILE .NOT. EOF()
IF ln >= 28
ln = ln-70
ENDIF
lskip = INT(VAL(LEFT(f1, 4)))
IF lskip = 0 * This is where i have a problem*
lskip = 1
ENDIF
IF .NOT. EMPTY(LEFT(f1, 1))
lskip = lskip - ln
ENDIF
ldata = SUBSTR(f1, 5)
SELECT AI2
FOR z = 1 TO lskip
APPEND BLANK
ln = ln + 1
ENDFOR
REPLACE f1 WITH ldata
SELECT AI1
SKIP
ENDDO
SELECT AI2
GOTO TOP
REPLACE f1 WITH SUBSTR(f1,10) all
GOTO top
COPY TO 'C:\COMPANIES\UNIVERSAL\unimstm.txt' TYPE SDF
CLOSE DATABASES
ERASE AI1.DBF
ERASE AI2.DBF
QUIT
ENDPROC
********************************************************
 
Code:
     IF lskip = 0  * This is where i have a problem*
          lskip = 1
     ENDIF

At this point you need to know the previous line and the current one, to merge via a function merging the two lines. Something based upon my code.

Eg
Code:
...
     IF lskip = 0  * This is where i have a problem*
        ldata = stringmerge(ldata,SUBSTR(f1, 5))
     ENDIF
     IF  .NOT. EMPTY(LEFT(f1, 1))
          lskip = lskip - ln
     ENDIF
     If lSkip>0
        ldata = SUBSTR(f1, 5)
        SELECT AI2
        FOR z = 1 TO lskip
            APPEND BLANK
            ln = ln + 1
        ENDFOR   
        REPLACE f1 WITH ldata
     Endif
...

So you keep lSkip=0 and then don't yet append blank or replace ldata into the last row, but wait until lSkip is >0 in further lines.

At the end of the loop you might need to still add whatever has been collected in ldata, if the last line has lskip=0.

You'd then put my code into a function stringmerge and let lcRow1 and lcRow2 be the two parameter of the call. And in the last line RETURN lcCombinedRow instead of ? lcCombinedrow.

You will still have problems with underlines, also not all chars in a line with lskip=0 would get bold.

This really is something you can't do with ASCII alone. You can only come somewhat near the original output.

Bye Olaf.
 
o.k i will try what you have suggested and i will let you know. thanks for your comments.
regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top