×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

String Function problem or any solution would be helpful
2

String Function problem or any solution would be helpful

String Function problem or any solution would be helpful

(OP)
I'm writing some cryptograms in VFP 6.0 and I am using the report generator to print out my cryptograms.

I want to place an overline (as opposed to an underline) over each letter of the encrypted sentence with a space
in between each letter so that each underline clearly represents each letter.


_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
T h e q u i c k b r o w n f o x

What is the function I would use in the report to place a line directly over each letter in an frx?

I tried just programming the underlines I want that correspond to the letters in a table, but the
underlines and the letters do not line up.

So I would I guess want to use a function for each letter of the encryption.

Thanks for any help.
When I posted my post, I noticed it took away the spaces between the words "The quick brown fox", one of the problems
I would be trying to avoid in a solution to this problem in VFP.

RE: String Function problem or any solution would be helpful

Try:

CODE

CLEAR
? CRYPTOGRAM("The Quick brown Fox Jumped over the lazy Dog")

FUNCTION CRYPTOGRAM
PARAMETERS m.INSTRING
PRIVATE m.INSTRING,m.OUTSTRING1,m.OUTSTRING2,I,m.CRLF
m.CRLF=CHR(13)+CHR(10)
m.OUTSTRING1 = ""
m.OUTSTRING2 = ""
IF LEN(m.INSTRING) > 0
	FOR I = 1 TO LEN(m.INSTRING)
		IF SUBSTR(m.INSTRING,I,1) <> " "
			m.OUTSTRING1 = m.OUTSTRING1 + "_ "
		ELSE
			m.OUTSTRING1 = m.OUTSTRING1 + "  "
		ENDIF
		m.OUTSTRING2 = m.OUTSTRING2 + SUBSTR(m.INSTRING,I,1)+" "
	NEXT


ENDIF
RETURN(m.OUTSTRING1+m.CRLF+m.OUTSTRING2)


_ _ _   _ _ _ _ _   _ _ _ _ _   _ _ _   _ _ _ _ _ _   _ _ _ _   _ _ _   _ _ _ _   _ _ _ 
T h e   Q u i c k   b r o w n   F o x   J u m p e d   o v e r   t h e   l a z y   D o g 

Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

RE: String Function problem or any solution would be helpful

It's just a matter of using a non-proportional (aka monospaced) font.

I don't see a solution to get an overline in the width of a letter together with a letter. Such modifiers are available in Unicode, but VFP is ANSI.

So use Griff's code and print these two output line with Font Courier New and you're done. The underline one line above the text is the simplest solution and the only one I think works straight out of the box. There is that foxypreviwer extension to allow some HTML like tags to format output, but as far as I remember that's more about easily mixing bold, italic and print in colors, not about Unicode or printing Unicode modifiers.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: String Function problem or any solution would be helpful

Just use a font where all characters are the same length. Is Courier one?

RE: String Function problem or any solution would be helpful

Quote:

Just use a font where all characters are the same length. Is Courier one?

Olaf already suggested that (same width rather than same length). Courier is indeed one, although nowadays it's more likely to be Courier New.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: String Function problem or any solution would be helpful

I suppose it could be done in an HTML table in a proportional font, using just one row, and enabling the
border on the top of each occupied character position, and a &nbsp; in each of the blanks.

Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

RE: String Function problem or any solution would be helpful

(OP)
Thank you GriffMG, Mike, Olaf, TheProgrammerGuy,

I appreciate all your answers - I think I will use the function that GriffMG laid out for me. As far as using a uniform font, I'll experiment with that also maybe in an export and see what happens with Courier New. Not home now, so when I get back to my project I will let you know how it goes.
Happy Holidays, looking around

RE: String Function problem or any solution would be helpful

Hello Aimskee,
Only a small point.
If you intend to use 'the quick brown fox' etc. then the word jumped should be JUMPS.
This sentence (pangram) is intended to use all the letters of the alphabet.

Regards

RE: String Function problem or any solution would be helpful

(OP)
The usage of "quick brown fox" is not applicable to what I'm doing even tho it jumps and didn't "jumped" as you reminded me. I could have said "the sky is green with blue turnips" or "dighd id sdifnd ilk". The point is, in my project I'm encrypting famous quotes and just used "any text" to show that I need to place overlines over each letter so the text lines up with the overline. .


RE: String Function problem or any solution would be helpful

(OP)
To all who gave me programming tips here: I found that even though I ran the function offered by GriffMG, on exporting the nicely aligned script to a PDF the letters and overlines once again don't line up in a report which I'm planning as my final printed output. I guess I would need a uniform font and those are hard to find on Windows PC.
I checked Courier fonts and they also didn't work (I'm using WIndows on a PC).
So I used a free app and created my own font and drew an overline over each letter I created so it was built right into the letter, and then installed the new font on my computer. That seems to work great so far. It eliminates the need for any extra programming too and it guarantees the line will always be directly above the letter. The only problem I have is that the font I created is not as pretty as professional fonts but I guess over the next week I'll perfect it and become a fontologist!
Thanks for all your help
Cheers. smile

RE: String Function problem or any solution would be helpful

Aimskee,

Good to hear that you have got it working, but you didn't need to create your own font. You simply needed to use a monospaced font, of which there are many. I'll bet you already have a few on your computer.

Examples of common monospaced fonts include Consolas, Letter Gothic, Lucida Console, Monaco, Prestite Elite, Typewriter, and anything with the word Mono in the name - as well as Courier New, which comes with all versions of Windows.

These fonts are worth knowing because you can also use them in code editors, such as the MODIFY COMMAND editor in VFP.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: String Function problem or any solution would be helpful

(OP)
I did try just about every font on my computer and eventually gave up. Maybe I missed them. I'll probably look into it in the next few days but it only took me a few minutes to make my own font.

RE: String Function problem or any solution would be helpful

Courier New exists on any Windows. You can't go wrong with that.
And yes, Griff's function output will also only align underscores and letters with such a font. Besides, I'd put that into a memo and print it in one report field, not as two separate strings in two fields. That'll give it the same left offset. Of course that report element has to have that font.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: String Function problem or any solution would be helpful

(OP)
I did courier new but it didn't line up. It was close but not perfect. by the time it got to "dog" it was off by a letter. I'll try it in a memo field. Thanks

RE: String Function problem or any solution would be helpful

In the code snippet I gave - the output was generated by the function.
Code snippets are in a monospaced font - so you can see it should stay lined up.

Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

RE: String Function problem or any solution would be helpful

I have now run Griff's function with the following monospaced fonts:

Courier New
Consolas
Lucida Console
Noto Mono

It worked fine with all of them.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: String Function problem or any solution would be helpful

Quote (aimskee)

by the time it got to "dog" it was off by a letter

The only way I see this could hapen is, you have a) two report controls, one per line and b) set up different fonts/font sizes.

Using one control and printing a memo with the two lines as one value is simpler, as you print with a single control, that can only have one font and fontsize and one offset from the left margin. So yes, go for it, but the problem can't be the font itself.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: String Function problem or any solution would be helpful

Won't printing CHR(196) once and re-printing the line with the alphabet do it? I am back to programming after a long long break (2000), so I'm not sure.

RE: String Function problem or any solution would be helpful

Quote:

Won't printing CHR(196) once and re-printing the line with the alphabet do it?

I don't think so. CHR(196) is A with an umlaut in normal alphabetic fonts.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: String Function problem or any solution would be helpful

Yes, just saw that. I'm more used to Foxpro for DOS. This CHR(196) was a long hyphen like character. We used it to draw borders.

RE: String Function problem or any solution would be helpful

(OP)


When I ran the function it did not line up perfectly. See the attached jpg of my output. I had my font set to Courier New. It was close until the last 3 words.

I need to present this in a PDF and after I export it using the suggested monospaced fonts, I still run into similar problems there where it's not quite lining up especially with longer sentences.

But it's very useful to know this function - when I play around with it some more I'll probably get it worked out when I export it into a PDF and then print out which will be the final output which has to be perfect.

I should prob. upgrade to more recent Foxpro although I do not know if it would cost benefit me at this time.

I also put
set printer font "Courier New", 12

in the program before the function runs.
Maybe you can tell by looking at my attached jpg here what the problem is.
Output does not look like Courier New so maybe my old installation of VFP 6.0 on my new computer is missing components although no errors are popping up.

RE: String Function problem or any solution would be helpful

Yes, this simply doesn't look like Courier New, it isn't Courier New and it obviously isn't monospaced.

What is your printer? Maybe it only prints an embedded font and doesn't adhere to any font settings you do.

When you use a PDF Printer, which acts as a printer hardware emulator addressable in the same ways as a real printer, just instead of printing outputting a PDF file, then you will be able to print True Type fonts. Unless you use some weird PDF printer or have some weird setting of it to always use a predefined font. But then printing the DOS way also woulndn't work. To print a layout of your choice with multiple fonts and images and more features, you can't print with ??? or @ commands, you have to migrate to FRX printing.

If you don't use an FRX to print you will not be guaranteed to define fonts used by the printer. FRXes use the GDI model of Windows and most any printer is supporting that, so you can print with any true type font (and more, but that's the usual norm for fonts also on displays).

Bye, Olaf.


Olaf Doschke Software Engineering
https://www.doschke.name

RE: String Function problem or any solution would be helpful

Aimskee, the jpg you posted is definitely not Courier New. To see what Courier New looks like, take a look at the code that Griff posted near the start of this thread - or any other formatted code in this forum. That's Courier New.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: String Function problem or any solution would be helpful

It's close - but no cigar

Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

RE: String Function problem or any solution would be helpful

Quote (Mike Lewis)

To see what Courier New looks like, take a look at the code that Griff posted near the start of this thread - or any other formatted code in this forum. That's Courier New.

Or in other words, if you set _SCREEN.Fontname = "Courier New" and run his code that would align. And if you don't see Griffs example aligned even in your browser, indeed something is wrong in the fonts of your Windows.

I still think you're actually having a printer with fixed embedded fonts.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: String Function problem or any solution would be helpful

I just tested Griff's code with CHR(151) instead of hyphen and it looked like this. There is a huge gap between lines.


I was searching a substitute for the chr(196) in DOS versions. I hope this CHR(151) can replace it.

RE: String Function problem or any solution would be helpful

I don't know where you see a hyphen in Griff's code, the underscores are generated here: "_ " in case there is a letter in the text and spaces " " in the other case, so there always is the one separation space to have individual lines and not one continuous line.

You can use whatever character fits in the DOS codepage you use. In DOS screens you'd have a character grid anyway, all DOS fonts are monospaced that way. So all that matters is the ASCII code is a line.

It will depend on what DOS codepage you're using, there are several depending on the OS locale, also for DOS. See supported codepages in the VFP help, find out the DOS codepage used in your locale and see which codes then are lines. Hyphens would obviously appear higher and not full width. In many DOS codepages you have full-width centered lines as part of a charset in the upper half that's available to draw boxes so you don't use hyphen, plus, and pipe or even exclamation mark to create pseudo boxes. There are only about 128 chars to test. Just print out all of them to see what fits.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: String Function problem or any solution would be helpful

Yeah, the Underscore, not hyphen. It's my mistake.

RE: String Function problem or any solution would be helpful

I still don't see a problem. When you program in Windows you program in a Windows Codepage. If you then run that in DOS it displays with a DOS Codepage. When you see an underscore in Windows, that might or might not be one on DOS.

If I MODIFY COMMAND new.prg AS 850 the umlauts for example become other characters. Not while editing the code, when executing it and printing to the VFP Windows _SCREEN, for example.

If you mean the gap between the underlines and letters, that looks like you have a whole line in between there. Griff's code adds CRLF. Maybe DOS only needs CR or LF? Or just by chance the character is the line at the top margin, an "overline". Then that'll also look like a whole line vertical gap.

You have to look up what codepage you're really working with under DOS Screens and learn or know some details. We're typically dealing with Windows here, that's using other codepages and under Windows CRLF is necessary just for one linefeed.

And once more, for Griff's code to use Courier new on the _SCREEN you need to set _screen.fontname = "Courier New". Literally "Courier New", There also is Curier New, that is not monospaced, for example.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: String Function problem or any solution would be helpful

I really did not expect that tiny bit of code to take on a life of it's own...

happy shades

Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

RE: String Function problem or any solution would be helpful

Your code is fine, in itself the string just has no formatting, so to show it in Courier New you have to use Courier New, and be able to use Courier New on devices used for output, too. Or any other really monospaced font.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: String Function problem or any solution would be helpful

To clarify a few things:

How FRXes can use Windows Fonts also is limited to Windows printers. Printing legacy style with SET PRINTER TO usually will be done by installing a Windows printer based on the "Generic/Text" driver and using ??? and @ commands to print. What you can do in terms of Fonts is unknown to me, I doubt the Generic/Text driver will forward any font settings to the real printer, as it's a, well, generic driver.

And if your printer uses embedded fonts you also won't be able to print with other fonts by using this driver or even a driver given by the vendor, embedded fonts are embedded fonts and you'd only have some compatibility.

And a mistake I made in my 12_16 post: "Curier New" also isn't a font I have. I just tried a bit more and it's even simpler, every time you set _SCREEN.FontName to a non-existing fontname you get some font, which looks quite similar to Courier New, looking like a typewriter font, but it's proportional with much narrower spaces than Courier New.

And setting _SCREEN.FontName won't set the font you print with, but it's the basis of what will determine the pixel positions of @say and @get commands, even if you then output with a font clause specifying another font.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: String Function problem or any solution would be helpful

Quote:

What you can do in terms of Fonts is unknown to me, I doubt the Generic/Text driver will forward any font settings to the real printer, as it's a, well, generic driver.

I think that's right. The way to use Generic/Text Only would be to send the printer-specific formatting codes (aka escape sequences). That would include codes to select the required font. But the font in question would have to already be resident in the printer.

So, yes, you can select fonts and also formatting (such as bold and italic) with Generic/Text Only, but you would have to change your code each time you moved to a different printer, or to a printer with different fonts installed. And there would be no way to preview the report on the screen.

Many older printers have Courier installed as a printer-resident font. Of course, Courier is not the same as Courier New.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: String Function problem or any solution would be helpful

Thanks Mike,

I was thinking along the lines that you may use the Generic/Text Only printer driver for a new printer, even though there are much better vendor drivers for Windows, because even without using escape sequences and detail knowledge about a printer you can at least print text the old way - while using the Windows GDI+ drivers coming with printers you can only really address them from VFP FRX reports.

Needing to know a command set of a specific printer would be a nightmare. That's not recommendable.

This way some of the functionalities work, ie printing text directly. But I doubt the SET PRINTER FONT or the FONT clause of @ commands would work. I think when a modern printer is addressed by the Generic/Text Only driver it will print with a default font, perhaps in draft mode, perhaps even a good readable but unfortunately not a monospaced font.

How the FONT setting or option worked in legacy Foxpro is beyond me, but I think that has to be in conjunction with a more general command set of printers from that era.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close