HOW TO PRINT A SIMPLE REPORT IN WINDOWS FORMAT

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
swapan
Posts: 242
Joined: Mon Mar 16, 2009 4:23 am
Location: Kolkata, India
Contact:

HOW TO PRINT A SIMPLE REPORT IN WINDOWS FORMAT

Post by swapan »

Dear All,

As the continuation job of my MEMBERSHIP PROJECT, now I want to learn how we can print report in windows style. I want to print a master list from my member.dbf

My format will be:

<company name>
MEMBERS' MASTER LIST

===============================================================
MEM_TYPE | MEMBER NAME | ADDRESS
===============================================================


_______________________________________________________________________


I tried with the following coding, but how to print add2,add3,city,etc. add-related fields
under the add1:


In Clipper I would have gone for a :
SCREEN / PRINTER /FILE OPTION
SET DEVI TO PRIN
Do Whil loop
@ nRow,nCol say ....

What's the approach here ....................

#include 'minigui.ch'

procedure main()
//
define window MainForm ;
at 0,0 ;
width 100;
height 100 ;
title 'SWAPAN DAS' ;
main

DEFINE MAIN MENU
POPUP 'File'
ITEM 'Print Members List ' ACTION PrintMemList()
END POPUP
END MENU
end window
//
activate window MainForm

Return Nil

function PrintMemList()
//
use member
inde on mem_type+name to member.aaa
//
set date british
set century on
//
DO REPORT ;
TITLE 'Members List' ;
HEADERS {'','','',''} , {'Mem_Type','Name','Address1','Addres2'} ;
FIELDS {'mem_type','name','add1','add2'} ;
WIDTHS {5,40,30,30} ;
TOTALS {.F.,.F.,.F.,.F.} ;
NFORMATS {'','','',''} ;
WORKAREA MEMBER ;
LPP 50 ;
CPL 80 ;
LMARGIN 2 ;
PAPERSIZE DMPAPER_A4 ;
PREVIEW ;
SELECT ;
MULTIPLE ;
GROUPED BY 'mem_type' ;
HEADRGRP 'Mem Group'
//

Return Nil
Thanks & Regards,
Swapan Das

http://www.swapandas.com/
User avatar
sudip
Posts: 1454
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: HOW TO PRINT A SIMPLE REPORT IN WINDOWS FORMAT

Post by sudip »

Hi Swapan,

I am not sure whether this can be done with DO REPORT command.

I am sure, this can be done using DO WHILE loop.

Regards.

Sudip
With best regards,
Sudip
User avatar
sudip
Posts: 1454
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: HOW TO PRINT A SIMPLE REPORT IN WINDOWS FORMAT

Post by sudip »

Hi Swapan,

I just created a printing sample, which may be helpful to you. Frankly speaking, I never tried it before. I only tested Rathi's Grid2Print utility. I am very happy that I learned how to print, for your query. I took help from some samples.

Thanks a lot. :)

Code: Select all

#include "minigui.ch"


function main()

	define window winMain ;
		at 0, 0 width 640 height 460 ;
		title "Printing Test Sample" ;
		main  ;
		on init CreateData()
		
      DEFINE MAIN MENU
         POPUP "&File"
         	Item "Print List" action PrintList()
            Item "E&xit" action thiswindow.release()
         end popup
      END MENU	
      
	end window

	winMain.center
	winMain.activate

retur nil




function PrintList()
   Local  mPageNo, mLineNo, mPrinter
   
   mPrinter := GetPrinter()

	SELECT PRINTER mPrinter ORIENTATION PRINTER_ORIENT_PORTRAIT PREVIEW

   START PRINTDOC NAME "Address"
   START PRINTPAGE

   select addr
	GO TOP
	mPageNo:=0
	mLineNo:=0
	DO WHILE .NOT. EOF()
		DO EVENTS
	   IF mLineNo>=260 .OR. mPageNo=0
   	   IF mPageNo<>0
      	   @ mLineNo+5,105 PRINT "Continue to Page "+LTRIM(STR(mPageNo+1)) CENTER
         	END PRINTPAGE
         	START PRINTPAGE
	      ENDIF
   	   mPageNo++

      	@ 20,20 PRINT "ADDRESS LIST"
      	@ 20,190 PRINT "Page: "+LTRIM(STR(mPageNo)) RIGHT
      	@ 25,20 PRINT DATE()

	      mLineNo:=35
         @ mLineNo+4,20 PRINT LINE TO mLineNo+4,140
	      @ mLineNo,20 PRINT "First Name"
	      @ mLineNo,50 PRINT "Last Name"
	      @ mLineNo,80 PRINT "Address"
	
	      mLineNo:=mLineNo+5
	   ENDIF
	
	   @ mLineNo, 20 PRINT fname
	   @ mLineNo, 50 PRINT lname
	   @ mLineNo, 80 PRINT addr1
	   mLineNo += 5
	   @ mLineNo, 80 PRINT addr2
	   mLineNo += 5
	   @ mLineNo, 80 PRINT addr3
	   mLineNo += 5
	   
	   SKIP
	
	ENDDO

   END PRINTPAGE
   END PRINTDOC
	return nil


function CreateData()
	local aDbf := {}
	
	REQUEST DBFCDX , DBFFPT
	RDDSETDEFAULT( "DBFCDX" )
	
	if !file("addr.dbf")
		aadd(adbf,	{"fname",	"c",	20,	0})
		aadd(adbf,	{"lname",	"c",	20,	0})
		aadd(adbf,	{"addr1",	"c",	40,	0})
		aadd(adbf,	{"addr2",	"c",	40,	0})
		aadd(adbf,	{"addr3",	"c",	40,	0})
		
		dbcreate("addr", adbf)
		
		if select("addr") = 0
			use addr exclusive
		endif
		select addr
		
		for i = 1 to 100
			append blank
			replace fname with "First name "+ltrim(str(i))
			replace lname with "Last name "+ltrim(str(i))
			replace addr1 with "Address mLineNoe One "+ltrim(str(i))
			replace addr2 with "Address mLineNoe Two "+ltrim(str(i))
			replace addr3 with "Address mLineNoe Three "+ltrim(str(i))
		next
		
		select addr
		go top
	else
		if select("addr") = 0
			use addr exclusive
		endif
		select addr
		go top
	endif
	RETURN NIL
Please compile and run the code and send your comments.

With best regards.

Sudip
With best regards,
Sudip
User avatar
swapan
Posts: 242
Joined: Mon Mar 16, 2009 4:23 am
Location: Kolkata, India
Contact:

Re: HOW TO PRINT A SIMPLE REPORT IN WINDOWS FORMAT

Post by swapan »

Thanks a lot Sudip! I was looking for this kind of solution only. I actually never used REPORT FORM to write reports in Clipper also. Always used the Do Whil Loop concept.

Now one thing:
In Clipper-DOS printing: we know 80 cols. & 132 col. report printing with compress mode - CHR(15).

Now what's the calculation of how many characters can be printed horizontally with respect to 80 characters in Clipper-DOS printing on a Dot Matrix Printer? Is it pixel based here and the character based calculation will not work here?
Thanks & Regards,
Swapan Das

http://www.swapandas.com/
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: HOW TO PRINT A SIMPLE REPORT IN WINDOWS FORMAT

Post by Rathinagiri »

For this we can have a brief introduction, w.r.t. fonts and printing as such. This is from Win32 Programmer's reference and all the credit goes to the original creator.

In Windows, a font is a collection of characters and symbols that share a common design. The three major elements of this design are referred to as typeface, style, and size.

Typeface

The term typeface refers to specific characteristics of characters and symbols in the font, such as the width of the thick and thin strokes that compose the characters and the presence or absence of serifs. A serif is the short cross line at the ends of an unconnected stroke. A font or typeface without serifs is usually called a sans-serif font.

Style

The term style refers to the weight and slant of a font. Font weights can range from thin to black. The following list identifies possible weights for Windows fonts (beginning with the lightest and ending with the heaviest).
Thin
Extralight
Light
Normal
Medium
Semibold
Bold
Extrabold
Heavy
Three terms categorize the slant of a Windows font: roman, oblique, and italic.
The characters in a roman font are upright. The characters in an oblique font are artificially slanted. The slant is achieved by performing a shear transformation on the characters from a roman font. The characters in an italic font are truly slanted and appear as they were designed. For more information on shearing, see Coordinate Spaces and Transformations.

Size

In Windows, the size of a font is an imprecise value. It can generally be determined by measuring the distance from the bottom of a lowercase "g" to the top of an adjacent uppercase "M," as shown in the following illustration.

Image

A font's size is specified in units called points. A point is .013837 of an inch. Following the point system devised by Pierre Simon Fournier, it is common practice to approximate a point as 1/72 inch.

Character Widths

Applications need to retrieve character-width data when they perform such tasks as fitting strings of text to page or column widths. There are some functions to determine the character width in advance.

Image

Width of a character depends upon the data. For example, an 'i' requires little space where as an 'm' requires more space. Still if we don't want to use proportionate spacing, we can use "Courier New" fonts.

Now, in HMG, we have a function (which I had used in Grid2Print utility), namely GetTextWidth. To convert the width of a string into millimeters for the given fontname and size we shall use an UDF like the below:

Code: Select all

function printLen( cString,fontsize,fontname)
return round(gettextwidth(Nil,cString,fontname)*0.072/72*25.4*fontsize,2)
The returned value is the width of the given string in mm if print the same in the printer.

I am sure it might have been helpful to you.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: HOW TO PRINT A SIMPLE REPORT IN WINDOWS FORMAT

Post by esgici »

Hi Rathi

Very valuable infos, thanks a lot :D

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
sudip
Posts: 1454
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: HOW TO PRINT A SIMPLE REPORT IN WINDOWS FORMAT

Post by sudip »

Hi Rathi,

Thank you very much for this lesson. It will be very helpful for many of us. I learned many thing from this. :)

As of now your GridPrint.prg is the manual for my printing knowledge. :)

I can't find GetTextWidth() function's reference in the HMG Help.

Is there any manual for Printing in HMG, which contains Functions, constants and small examples.

(After writing this message I found that our Master, Roberto created a documentation for HMG :D . There is something for printing also. But I can't find GetTextWidth() function there in my first browse ;( )

Swapan,
I hope, this thread will be helpful to you viewtopic.php?f=15&t=185

With best regards.

Sudip
With best regards,
Sudip
User avatar
swapan
Posts: 242
Joined: Mon Mar 16, 2009 4:23 am
Location: Kolkata, India
Contact:

Re: HOW TO PRINT A SIMPLE REPORT IN WINDOWS FORMAT

Post by swapan »

Xcellent piece of information Rathi! Thanks a lot to you & the original author of this info.

The function you were referring to, is not documented in HMG manual. BTW where is your this GridPrint.prg - Sudip is referring to! I also want to enlighten myself! :D

I'm just wondering how to map the way I use to write reports in Clipper with the HMG with respect to rows & cols. coordinates & spacing.

If the FIRSTNAME col is 01 in Clipper-DOS, then what will be its equivalent col. position in HMG?
If the LASTNAME col is 22 in Clipper-DOS, then what will be its equivalent col. position in HMG?

What's the Right Generic Approach here w.r.t to row & col. position?

Regards,

Swapan
Thanks & Regards,
Swapan Das

http://www.swapandas.com/
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: HOW TO PRINT A SIMPLE REPORT IN WINDOWS FORMAT

Post by Rathinagiri »

It can be downloaded from here.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: HOW TO PRINT A SIMPLE REPORT IN WINDOWS FORMAT

Post by Rathinagiri »

swapan wrote: I'm just wondering how to map the way I use to write reports in Clipper with the HMG with respect to rows & cols. coordinates & spacing.

If the FIRSTNAME col is 01 in Clipper-DOS, then what will be its equivalent col. position in HMG?
If the LASTNAME col is 22 in Clipper-DOS, then what will be its equivalent col. position in HMG?

What's the Right Generic Approach here w.r.t to row & col. position?

Regards,

Swapan
Thanks Swapan.

In HMG, the dimension of width and height of the paper is measured in millimeters and not columns. For example, if we choose an 'A4' paper, it is 210 mm wide and 297 mm high.

From this we can reduce the top, left, right and bottom margins say 25 mms (approx. 1 inch).

Then, we start printing like this @ 25,25 print 'This is to be printed' font "Arial" size 10

Hence, if you want to have the same proportion like your old dos, we can have here a small udf to convert the column number to mm.

@ c2mm(10),c2mm(10) print 'This as the first column' font "Arial" size 10
@ c2mm(10),c2mm(20) print 'This as the second column' font "Arial" size 10

Now, the function c2mm() is like this.

function c2mm(ncol)
return (ncol/80 * 210) // 80 is the number of columns in your old dos application. 210 is the width of the paper in windows. :)

I think I hadn't messed you more.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
Post Reply