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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

different fonts on same line of report

Status
Not open for further replies.

muralinarayan1968

IS-IT--Management
May 13, 2012
18
IN
Hi,
I need to design & print a report wherin i need to change the font for some part of the text for eg:-
This is a test line in the report

I want "This is a" in say font kabel bd bt & test line in font times roman italic & in the report back to kabel bd bt

How do i achieve this at runtime assumin that the entire line This is a test line in the report as a single string or variable.

Regards
Murali Narayan
 
The VFP report writer was not designed to make font changes within a single text object. The best you can do is to use different text objects, each with its own font attributes.

This should not be difficult for you to do since there is clearly some data condition or program logic that dictates which part of the string should appear in which font. Use the same condition to break up the string into different report objects.
 
The other option is to use the ole doc/image report control and use RTF to print preformatted RTF texts, which can include font face/size/color changes and more, of course. Requires a bit of preprocessing and learning rtf syntax.

Bye, Olaf.
 
Yes there is some data condition but difficult to calculate position for eg:- i will illustrate below
field 1 : name
field 2 : flat no
field 3 : premises
field 4 : area / town name
field 5 : state
field 6 : telephone no.

above eg. any fields from 2 to 4 could be empty so lets say i want tel no in different font, how do i calculate the position?
again for eg. field 3 is blank then field 4-6 should move up one line, how to achieve this?

regards
murali
 
In regard to the positioning, you either live with a defined layout, which has gaps. That's not an unusual solution.

OR

You go RTF and have the freedom to put the data togehter as needed.

Easy start off is using Wordpad, Typing a line as wanted, saving as RTF, changing file extension to txt and take out the RTF code generated. It's shorter and cleaner and easier to extend, than RTF code generated by Word.

Bye, Olaf.
 
Murali,

As Olaf says, this is not an easy thing to do.

The only thing I can suggest is that you use a single field, extending over the entire six lines in height. You base this on a single memo field or character variable. In that field or variable, you store the all information that you want to display, using CR and LF characters to separate the lines, and omitting any empty lines.

That will solve the problem of not having any gaps in the information. But it doesn't solve the problem of having some lines showing in bold and not others. I can't think of any way of doing that, other than using an RTF control, in which case it would be quite easy.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
On second thoughts, maybe it would not be so difficult to do it by overlaying two fields.

You would have two fields in the report, each six lines in height, on on top of the other.

In the first field, display all the information you want to show in the normal font. Leave a blank line for any items that are missing.

Do the same with the second field, but this time just show the information you want to see in bold. Again, leave any missing lines blank. Format this field with the required bold font.

For both fields, set the Background property to Transparent (this is on the Style page of the Properties dialogue).

When you print or preview the report, you should see a single block of information, with the desired lines in bold and the others in normal. I haven't actually tried doing this, so can't be sure that it would work, but it should at least give you something to work with.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Thank you Mike,
Yes I have tried it already, having a single variable including cr+lf embedded. Unfortunately lets say i want to print a address line & then after that a line with the tel. no. something like this :-
murali narayan
108, virmani industrial estate,
navghar, vasai road east,
mumbai
TEL. No. 91-xxxxxxxxx

in this eg. i have a total of 4 lines of address + 1 line of tel.no., maybe next record i have 5 lines of address or 3 lines of address, how do i calculate the position of tel. no. whether it is going to be on 6th line or 5th line or whatever, i do not want any blank lines in between. If i can solve this then i can extract the tel. no. & put it on the next line with a different font problem solved!!!!
regards
murali
 
Murali, that shouldn't be too difficult.

I assume you want the phone number to always be the last line of the block. If so, all you have to do is to insert an appropriate number of CRLFs at the start of the phone number block. The number in question will be one more than the number of non-blank lines in the other block.

The main point is to separate that logic from the issue of formatting. It's just a question of setting up two strings so that each contains the required number of lines. It's best to do that in the calling program, not to try to do it in the report.

If you are really stuck, I could do the code for you (or maybe someone else will), but it shouldn't be too difficult.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Hi Mike,
This is the code i came up with can you please check & let me know if i am doing something wrong.

** initially set the variable to "", for main address **
m_name_addr = ""

** then check which line is empty in the address field & remove **
IF !EMPTY(ALLTRIM(offi_name))
** office name exists, add it to the next line **
m_name_addr = m_name_addr + ALLTRIM(offi_name) + CHR(13)
ENDIF
IF !EMPTY(ALLTRIM(flat_numb))
** flat number exists, add it to the next line **
m_name_addr = m_name_addr + ALLTRIM(flat_numb) + CHR(13)
ENDIF
IF !EMPTY(ALLTRIM(prem_name))
** premises name exists, add it to the next line **
m_name_addr = m_name_addr + ALLTRIM(prem_name) + CHR(13)
ENDIF
IF !EMPTY(ALLTRIM(road_name))
** road name exists, add it to the next line **
m_name_addr = m_name_addr + ALLTRIM(road_name) + CHR(13)
ENDIF
IF !EMPTY(ALLTRIM(area_name))
** area name exists, add it to the next line **
m_name_addr = m_name_addr + ALLTRIM(area_name) + CHR(13)
ENDIF
IF !EMPTY(ALLTRIM(town_name))
** town name exists, add it to the next line **
m_name_addr = m_name_addr + ALLTRIM(town_name) + CHR(13)
ENDIF

** state fullname & pincode will exist, add it to the next line **
m_name_addr = m_name_addr + ALLTRIM(stat_full) + " - " + ALLTRIM(pinc_numb) + CHR(13)
** phone no. also will exist, add it to the next line **
m_name_addr = m_name_addr + ALLTRIM(phon_full)

replace name_addr WITH m_name_addr

How do i find out how many lines does this string contain???
regards
Murali
 
How do i find out how many lines does this string contain???

One way would be to use OCCURS(CHR(13), m_name_addr).

Alternatively, initialise the second string (say, m_phone) to an empty string. Then, in your existing code, whenever you test for NOT EMTPTY(<field name>), add an ELSE clause. In that clause, add CHR(13) to the second string. Then add the phone number to the end of the string. It's that second string that you will eventually show in bold within the report.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
great i will try both the methods and let you know, it's past eleven in the night take a nap & first thing in the morning will try this.
Thanks a ton for your effort.

Regards
Murali
 
Sorry i forgot one other thing though, can we change line spacing in the reports, cause devnagiri fonts (hindi) gets jumbled up when we display in second line.
adding chr(13)+chr(10) gives me double spacing which is too much, 1-1/2 spacing would be ideal, how to achieve this.
Regards
Murali
 
I don't know any of way of getting 1½-line spacing within a field in a report. If CHR(13) + CHR(10) gives double-spacing, you could try experimenting with CHR(10) or CHR(13) on its own, but that would only give single-spacing at best.

I've no experience of Devnagiri fonts. Sorry.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Mike,
Your previous example of occurs() worked like a charm, now the problem of tel. no. is solved.
yes i did experiment with only chr(10) & chr(13) at best they only give a single line spacing, problem not solved.
Does any other reporter like foxypreview support this function???

Regards
Murali
 
I don't know about FoxyPreview. I know you can't do it in XFRX. Maybe someone else can answer that question.

Everything you have asked is easy to do in Crystal Reports. You can set a field's paragraph properties, including line spacing, just like you can in Word. You can also insert rich text fields (or HTML), so that you can vary the font or style in any way you like within the field. But switching to CR would be an expensive and time-consuming option, and almost certainly not worth doing just to solve this one problem.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I agree with you, we have crystal reports 8.0 something, i have personally not tried it at all.
Is there any guidance on how to use crystal reports with fox??
I am a little stuck on this issue though, let see!!

Anyways thanks again for taking the time to answer, really appreciate it.
Regards
Murali
 
Is there any guidance on how to use crystal reports with fox??

Yes. I've written a white paper on the subject:
Using Crystal Reports with Visual FoxPro

Also, Craig Berntston (who is a regular in this forum) has published a lot of useful material (
But I'd advise you not to rush into taking the Crystal route. If you can find a way to do it in VFP, that would probably be much simpler. You might review the advice Olaf gave you above re adding an OLE control to the report.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I'm a little late and might be missing something basic here, but could you do some pre-processing and create a cursor that has one record for each of the fields. Convert all of the fields to character if necessary. Then include some logical or numeric flags that would indicate which overlapping control to print using the Print When on the report. Each of the these overlapping controls in a detail band could have their own size, bold, underline, background, etc. This could eliminate any blank spaces and you could insert the rows in any order you want.

Auguy
Sylvania/Toledo Ohio
 
Thanks to Mike & auguy,
Yes i have previously mentioned i have solved that particular problem already with the advice mike gave me regarding the function occurs().
My next question was for the line spacing, which unfortunately VFP is not able to solve hence trying to take the crystal reports path.
If nothing i could atleast learn a some new stuff which might come in handy elsewhere.

Thanks once again
regards
murali
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top