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

How to beautify text merge - endtext in VFP 7 2

Status
Not open for further replies.

gryff15

Programmer
Sep 21, 2016
47
0
0
PH
Using Tools > Beautify does not indent the TEXT TO xvariable TEXTMERGE even when there are multiple indentions, it sticks to the leftmost edge..

VFP said:
lcSAMPLE = "SAMPLE"​
TEXT TO sqlHandle TEXTMERGE NOSHOW
SELECT count(acct) AS xcount FROM SAMPLE.DBO.SAMPLE​
ENDTEXT
If SQLEXEC(connhandle, sqlHandle, 'sample') < 0
Aerror(laErrors)
Messagebox(laErrors[2],16,"Error in SQL exec for sample")​
Endif​

- gryff15 -
 
This is by design. As you know, Beautify handles indentation in program code. But TEXT / ENDTEXT is not only used for program code. It is used for all kinds of text. Beautify has no way of knowing whether any particular piece of text is program code or something else.

The solution is to temporarily comment-out the TEXT and ENDTEXT statements while you are running Beautify. If you want the entire block within the TEXT/ENDTEXT to be indented, then highlight the block and hit the TAB key.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Gryff,

If you want code to look right here in the forum, use the code tags, not quote tags.

I took your code and added another nesting by another IF, and here's how TEXT..ENDTEXT indentation by beautiy has to work:
Code:
If llTekTipscodesample
   lcSAMPLE = "SAMPLE"
   TEXT TO sqlHandle TEXTMERGE NOSHOW
SELECT count(acct) AS xcount FROM SAMPLE.DBO.SAMPLE
   ENDTEXT
   If SQLExec(connhandle, sqlHandle, 'sample') < 0
      Aerror(laErrors)
      Messagebox(laErrors[2],16,"Error in SQL exec for sample")
   Endif
Endif

You see the lines with TEXT and ENDTEXT do get indented, but the SELECT-SQL query sticks to the left. That's because indentation here would not only indent the code, it would change the textmerge result. In case of an SQL you execute that would not matter, but in cases of other things like mail merge text you'd cause indentation where it is not wanted.

Because TEXT ENDTEXT are the begin an end of a code section that suggests all lines within could be indented but the inner text is never indented (also not in VFP9) - that's normal. Again, because the indentation would influence the result.

VFP8 or 9 introduced a PRETEXT clause of TEXT..ENDTEXT, that make it possible to indent the inner text, as you finally can remove leading space with the right PRETEXT constant but that also does not make indentation automatic in beautify. So you're not missing anything in regard to how this behaves in future versions.

The only good news I can tell you is that once you manually indent this, it will stay that way also with further beautify. And the reason is again the same, changing the indentation would change the result of TEXT..ENDTEXT, so VFP beautify never touches it and always leaves it the way you write it, unindented or indented.

Chriss
 
Gryff15, if you desperately want Beautify to always work within TEXT / ENDTEXT, you could consider modifying the Beautify code. The source code for Beautify.PRG is available in the XSource directory. After modifying it, you would have to compile it to an APP, and then ensure that [tt]_Beautify[/tt] points to that app.

Whether it's worth going to that much trouble is something for you to decide for yourself. I've just had a quick look at Beautify.PRG, and I can't immediately see how to do it - not least because most of its functionality seems to be contained in an FLL (FD3.FLL) for which the source code appears not to be available.

Still, it's an option to consider.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike and Chris,

Thank you very much for your detailed and generous help. For now I'd just stick with manually indenting the TEXT/ENDTEXT every time I beautify. It just really bugs me sometimes when the codes have many chunks of it. I personally prefer using the traditional x = "value" in initializing strings instead of text/endtext.
I might want to consider editing the beautify.prg, but I can't seem to find its location.

- gryff15 -
 
Gryff15, manually indenting the construct is definitely a good approach. It involves a slight bit of effort, but it's not as if you are going to be doing a large number of times.

Regarding the location of beautify.prg, look in the tools\xsource directory within your VFP program directory. You will see a compressed folder named xsource.zip. If you unpack that, you will see the Beautify folder which in turn contains Beautify.prg plus a project file.

However, Beautify.Prg also requires an FLL called FD3.FLL, and it is that FLL that you would probably need to modify. Unfortunately I haven't been able to find the source of that.

It's worth getting to know the contents of XSource. As well as Beautify, it contains the contents of many other VFP tools, and it is quite rewarding to get to know them.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top