Help Needed Please
Publicado: Dom Ago 26, 2007 11:58 am
Hello Ignacio
I come back with your code snippet for making own labels.
I need some exlpain on o few code lines.
Please if you have some spare time advice me.
In Method Button1Click() code everithing are clear to me.
Your code snippet was :
METHOD Button1Click( oSender ) CLASS TMyFrm
LOCAL oRep, oFont
LOCAL aEtiq
LOCAL nEtiq, n
FIELD SECTOR, NOMBRE, DIRECCION, POBLACION, CPOSTAL, PROVINCIA, PAIS,
CONTACTO
WITH OBJECT oFont := TFont():New()
:cName := "Arial"
:nSize := 10
:Create()
END WITH
aEtiq := {}
nEtiq := 0
Application:lBusy := .T.
::lEnabled := .F.
::oDbf:SaveState( .T. )
::oDbf:Select()
WITH OBJECT Printer
:lPreview := .T.
:cJobTitle := "Client labels"
:StartDoc()
:oCanvas:nMapMode := mmHIMETRICS
:oCanvas:nTextAlignment := taLEFT
:oCanvas:oFont := oFont
GO TOP
DO WHILE !Eof()
IF nEtiq == 0 .AND. Len( aEtiq ) == 0
:StartPage()
ENDIF
Aadd( aEtiq, { NOMBRE, DIRECCION, POBLACION, CPOSTAL, PROVINCIA,
PAIS, CONTACTO } )
IF Len( aEtiq ) == 2
PrintEtiqueta( :oCanvas, aEtiq, nEtiq )
aEtiq := {}
IF ++nEtiq > 9
:EndPage()
nEtiq := 0
ENDIF
ENDIF
SKIP
ENDDO
IF Len( aEtiq ) > 0
PrintEtiqueta( :oCanvas, aEtiq, nEtiq )
:EndPage()
ENDIF
:EndDoc()
::oDbf:RestoreState( .T. )
::Close()
Application:lBusy := .F.
:Preview( .T. )
END WITH
RETURN Nil
#define ETIQ_ALTO 288 <----------------------- You mean height of real
label in centimeters/100 ?
#define ETIQ_ANCHO 1050 <------------- You mean Witdh
of real label in centimeters/100?
#define ETIQ_YOFF 332 - ETIQ_ALTO + 50 <--------- You mean the left Top
Margin of the real label?
#define ETIQ_X1OFF 50 <---------------- What is
this parameter on a real label paper ?
#define ETIQ_X2OFF ETIQ_X1OFF + ETIQ_ANCHO <--------------------------- What
is this parameter on a real label paper ?
FUNCTION PrintEtiqueta( oCanvas, aEtiq, nEtiq )
LOCAL cPob
LOCAL nRow, nCol1, nCol2, nPaso
nRow := nEtiq * ETIQ_ALTO + ETIQ_YOFF
nCol1 := ETIQ_X1OFF
nCol2 := ETIQ_X2OFF
nPaso := Round( oCanvas:PixelsToMapMode( 0, Abs(
oCanvas:oFont:nHeight ) )[ 2 ] * 1.2, 0 ) <--------------------- [2] mean's
the second parameter of returning array of method oCanvas:PixelsToMapMod()?
WITH OBJECT oCanvas
:TextOut( nCol1, nRow , aEtiq[ 1, 1 ] )
nRow += nPaso
:TextOut( nCol1, nRow, aEtiq[ 1, 2 ] )
nRow += nPaso
cPob := Alltrim( Trim( aEtiq[ 1, 4 ] ) + " " + aEtiq[ 1, 3 ] )
:TextOut( nCol1, nRow, cPob )
nRow += nPaso
:TextOut( nCol1, nRow, aEtiq[ 1, 5 ] )
nRow += nPaso
:TextOut( nCol1, nRow, aEtiq[ 1, 6 ] )
nRow += nPaso
IF !Empty( aEtiq[ 1, 7 ] )
:TextOut( nCol1, nRow, aEtiq[ 1, 7 ] )
ENDIF
IF Len( aEtiq ) > 1
nRow := nEtiq * ETIQ_ALTO + ETIQ_YOFF
:TextOut( nCol2, nRow , aEtiq[ 2, 1 ] )
nRow += nPaso
:TextOut( nCol2, nRow, aEtiq[ 2, 2 ] )
nRow += nPaso
cPob := Alltrim( Trim( aEtiq[ 2, 4 ] ) + " " + aEtiq[ 2, 3 ] )
:TextOut( nCol2, nRow, cPob )
nRow += nPaso
:TextOut( nCol2, nRow, aEtiq[ 2, 5 ] )
nRow += nPaso
:TextOut( nCol2, nRow, aEtiq[ 2, 6 ] )
nRow += nPaso
IF !Empty( aEtiq[ 2, 7 ] )
:TextOut( nCol2, nRow, aEtiq[ 2, 7 ] )
ENDIF
ENDIF
END WITH
RETURN NIL
Many Thanks for your attention
Regards
Dionisis
I come back with your code snippet for making own labels.
I need some exlpain on o few code lines.
Please if you have some spare time advice me.
In Method Button1Click() code everithing are clear to me.
Your code snippet was :
METHOD Button1Click( oSender ) CLASS TMyFrm
LOCAL oRep, oFont
LOCAL aEtiq
LOCAL nEtiq, n
FIELD SECTOR, NOMBRE, DIRECCION, POBLACION, CPOSTAL, PROVINCIA, PAIS,
CONTACTO
WITH OBJECT oFont := TFont():New()
:cName := "Arial"
:nSize := 10
:Create()
END WITH
aEtiq := {}
nEtiq := 0
Application:lBusy := .T.
::lEnabled := .F.
::oDbf:SaveState( .T. )
::oDbf:Select()
WITH OBJECT Printer
:lPreview := .T.
:cJobTitle := "Client labels"
:StartDoc()
:oCanvas:nMapMode := mmHIMETRICS
:oCanvas:nTextAlignment := taLEFT
:oCanvas:oFont := oFont
GO TOP
DO WHILE !Eof()
IF nEtiq == 0 .AND. Len( aEtiq ) == 0
:StartPage()
ENDIF
Aadd( aEtiq, { NOMBRE, DIRECCION, POBLACION, CPOSTAL, PROVINCIA,
PAIS, CONTACTO } )
IF Len( aEtiq ) == 2
PrintEtiqueta( :oCanvas, aEtiq, nEtiq )
aEtiq := {}
IF ++nEtiq > 9
:EndPage()
nEtiq := 0
ENDIF
ENDIF
SKIP
ENDDO
IF Len( aEtiq ) > 0
PrintEtiqueta( :oCanvas, aEtiq, nEtiq )
:EndPage()
ENDIF
:EndDoc()
::oDbf:RestoreState( .T. )
::Close()
Application:lBusy := .F.
:Preview( .T. )
END WITH
RETURN Nil
#define ETIQ_ALTO 288 <----------------------- You mean height of real
label in centimeters/100 ?
#define ETIQ_ANCHO 1050 <------------- You mean Witdh
of real label in centimeters/100?
#define ETIQ_YOFF 332 - ETIQ_ALTO + 50 <--------- You mean the left Top
Margin of the real label?
#define ETIQ_X1OFF 50 <---------------- What is
this parameter on a real label paper ?
#define ETIQ_X2OFF ETIQ_X1OFF + ETIQ_ANCHO <--------------------------- What
is this parameter on a real label paper ?
FUNCTION PrintEtiqueta( oCanvas, aEtiq, nEtiq )
LOCAL cPob
LOCAL nRow, nCol1, nCol2, nPaso
nRow := nEtiq * ETIQ_ALTO + ETIQ_YOFF
nCol1 := ETIQ_X1OFF
nCol2 := ETIQ_X2OFF
nPaso := Round( oCanvas:PixelsToMapMode( 0, Abs(
oCanvas:oFont:nHeight ) )[ 2 ] * 1.2, 0 ) <--------------------- [2] mean's
the second parameter of returning array of method oCanvas:PixelsToMapMod()?
WITH OBJECT oCanvas
:TextOut( nCol1, nRow , aEtiq[ 1, 1 ] )
nRow += nPaso
:TextOut( nCol1, nRow, aEtiq[ 1, 2 ] )
nRow += nPaso
cPob := Alltrim( Trim( aEtiq[ 1, 4 ] ) + " " + aEtiq[ 1, 3 ] )
:TextOut( nCol1, nRow, cPob )
nRow += nPaso
:TextOut( nCol1, nRow, aEtiq[ 1, 5 ] )
nRow += nPaso
:TextOut( nCol1, nRow, aEtiq[ 1, 6 ] )
nRow += nPaso
IF !Empty( aEtiq[ 1, 7 ] )
:TextOut( nCol1, nRow, aEtiq[ 1, 7 ] )
ENDIF
IF Len( aEtiq ) > 1
nRow := nEtiq * ETIQ_ALTO + ETIQ_YOFF
:TextOut( nCol2, nRow , aEtiq[ 2, 1 ] )
nRow += nPaso
:TextOut( nCol2, nRow, aEtiq[ 2, 2 ] )
nRow += nPaso
cPob := Alltrim( Trim( aEtiq[ 2, 4 ] ) + " " + aEtiq[ 2, 3 ] )
:TextOut( nCol2, nRow, cPob )
nRow += nPaso
:TextOut( nCol2, nRow, aEtiq[ 2, 5 ] )
nRow += nPaso
:TextOut( nCol2, nRow, aEtiq[ 2, 6 ] )
nRow += nPaso
IF !Empty( aEtiq[ 2, 7 ] )
:TextOut( nCol2, nRow, aEtiq[ 2, 7 ] )
ENDIF
ENDIF
END WITH
RETURN NIL
Many Thanks for your attention
Regards
Dionisis