Returns Compact Path- fnCompactPath

The place where ProMatrix users can post coding tips and utilities they create.

Returns Compact Path- fnCompactPath

Postby JessicaLawson » Sun Jun 13, 2010 3:57 pm

Just a quick utility,

I had been making menu changes for some time today (it's hard to
get back to working in vfp after a spot of time lately using c#) - just
scoping out what I though would be a logical menu structure for a small app
I am creating - it occurred to me that every time genmenux runs - it does a
poor job of formatting it's own label of the files that it is running
through - they tend to run off the form to the right (font related,
formatting related,..).

So, it seems that here is a spot for an improvement to a very, very old
utility - that is just a nice to have. Seems a small picky thing - but I
needed a break anyway <g>.

I looked around for a way to limit the characters displayed (but still have
informative information) - but didn't see any generic utilities. I wrote the
following (fnCompactPath) - which in the next day or two I will use to
adjust the display in genmenux (I will post the adjustment if folks are
interested)...

Anyway, it is generic enough to use anywhere you want to display a file
path - but in a limited number of characters or Pixels (some testing will
work out the numbers).

See the following

Cheers,

John C. Gunvaldson
San Diego, CA
ProMatrix MVP

*-- =========================================================
*-- The following is a working example for the function call to
fnCompactPath. Worked
*-- once for me <s>....
*-- =========================================================

*-- working definitions
#define CRLF chr(13)+chr(10)
#define SAMPLE_PATH "c:\path1\path2\path3\path4\path5\sample.txt"
#define MAX_PATH_PIXELS 145

*-- example call
local lcPath as String, lcResults as String
lcPath = SAMPLE_PATH
lcResults = ""
lcResults = fnCompactPath(lcPath,MAX_PATH_PIXELS)

*-- results
messagebox("The following path: " + CRLF ;
+ alltrim(SAMPLE_PATH) + CRLF + CRLF ;
+ "Trimmed to: " + transform(MAX_PATH_PIXELS) + " pixels" + CRLF ;
+ "Returns: " + alltrim(lcResults),64,"fnCompactPath Example")

*//==================================================
function fnCompactPath(tcPath as String, ;
tnPix as Integer) as String

*-- establish working substitutions
#define MAX_PATH_SIZE 1000

*-- establish working vars
local _lpbuffer as String, _lcstr as String, _lnret as Integer,
_lndx as Integer
store space(MAX_PATH_SIZE) to _lpbuffer
store 0 to _lnret, _lndx
store tcPath to _lcstr
store tnPix to _lndx

*-- declare shell lightweight utility call
DECLARE INTEGER PathCompactPath IN shlwapi;
INTEGER hdc,;
STRING @_lpbuffer,;
INTEGER dx

*-- make call
_lnret = PathCompactPath(0,@_lcstr,_lndx)

*-- format based upon location of first null inserted by call -
probably other ways to do this
_lcstr = alltrim(substr(_lcstr,1,(at(chr(0),_lcstr,1)-1)))

*-- return
return (_lcstr)

endfunc
*//==================================================
JessicaLawson
 
Posts: 79
Joined: Sun Jun 13, 2010 1:23 pm

Re: Returns Compact Path- fnCompactPath

Postby JessicaLawson » Sun Jun 13, 2010 3:58 pm

*-- first, to visually understand the use of the function
First, the call to fnCompactPath using:

"c:\path1\path2\path3\path4\path5\sample.txt" using 145 pixels

would return

"c:\path1\...\sample.txt

Some additional research this evening...

Turns out what I have been seeing all these years is a purposely truncated
string displayed on the second line of the GENMENUX display. For instance,
usually something like the following...

GENMENUX: Menu C:\VPME91\SVSAFMAN.MPR
Handling *:IF Directive for "+TranStr("String T\<ranslations. <-- and
that's it, wheres the rest? - hmmmm... Always seemed to me that it was
running right off the end of the form.

Found that within the Genmenux.prg (a fairly messy and extremely cluttered
proc. - but pretty cool anyway) there is a function call (called "SayTherm")
to write messages to it's interface. That call is usually made for example:
[ do saytherm with "some message..." ].

If you examine the procedure call, you can notice the culprit that formats
the message string uses length of the string and call to Wcols().

*/== snippet ==
ACTIVATE WINDOW gxThermCol
IF LEN(m.string)>WCOLS()-3
m.string=LEFT(m.string,WCOLS()-3)
ENDIF
*/== snippet ==

[1] I actually substituted a call to my fnCompactPath to evaluate the
results - for it really didn't matter if the string was "actually" a path or
not, the same formatting occurred --- however, it wasn't any better than the
existing truncated string from the original call above - so I took it back
out. A cool function, but not what was really needed here.

[2] After various string treatments I conclude that there is not allot one
can do with such a fragmented string. I finished with the following code
(which is visually far more pleasing than the legacy code) however, your
mileage mileage (and tollerance for fragmented strings) may vary....

*/== snippet ==
IF LEN(m.string)>WCOLS()-3
m.string = "Handling ... " + RIGHT(m.string,wcols()-25)
ENDIF
*/== snippet ==

That's enough for GENMENUX for now.

An interesting project for the future might be to reformat all of this code
into a proper class structure - but for now, I don't see a direct need for
something like "fnCompactPath" but I am sure I will find uses for it
soon....

Regards,

John C. Gunvaldson
San Diego, CA
JessicaLawson
 
Posts: 79
Joined: Sun Jun 13, 2010 1:23 pm

Re: Returns Compact Path- fnCompactPath

Postby JessicaLawson » Sun Jun 13, 2010 3:58 pm

Check out DISPLAYPATH() in VFP9...

--

---------------------------------------------------------
Bob Stone, ProMatrix MVP - Life
---------------------------------------------------------
JessicaLawson
 
Posts: 79
Joined: Sun Jun 13, 2010 1:23 pm

Re: Returns Compact Path- fnCompactPath

Postby JessicaLawson » Sun Jun 13, 2010 3:58 pm

That's it - DisplayPath() works pretty good! Didn't notice that one... It's
even easier in some respect as you can use character lengths -vs- pixel
size...

Thanks Bob,

John
JessicaLawson
 
Posts: 79
Joined: Sun Jun 13, 2010 1:23 pm

Re: Returns Compact Path- fnCompactPath

Postby JessicaLawson » Sun Jun 13, 2010 3:59 pm

Also,

It was pretty much always the first line, not the second line I was looking
at before. The first line displays the path of the menu that is being
compiled. That's why I concentrated on the path statement -but the
adjustment was needed for the first line, as that is an actual folder and
file name path...

When the menu name being displayed is down several _long_ named folders - it
was pretty much unrecognizable as it was, so...

This is what it is...
jcWait = "GENMENUX : Menu " +
IIF(LEN(jcOutFile)>50,'...'+RIGHT(jcOutfile,41),jcOutFile)

This looks better...
jcWait = "GENMENUX : Menu " + displaypath(jcOutFile,40)

Ok, now I'm done...

John
JessicaLawson
 
Posts: 79
Joined: Sun Jun 13, 2010 1:23 pm

Re: Returns Compact Path- fnCompactPath

Postby JessicaLawson » Sun Jun 13, 2010 3:59 pm

Just noticed that VPM has a method oApp.ShortenPath that does the same thing
<g>.....

--

---------------------------------------------------------
Bob Stone, ProMatrix MVP - Life
---------------------------------------------------------
JessicaLawson
 
Posts: 79
Joined: Sun Jun 13, 2010 1:23 pm

Re: Returns Compact Path- fnCompactPath

Postby JessicaLawson » Sun Jun 13, 2010 3:59 pm

Oh, for goodness sake - put a fork in me... <g>.


"Bob Stone" <rrs03@health.state.ny.us> wrote in message
news:5bb2d2df$48562b80$67a@emach1...
> Just noticed that VPM has a method oApp.ShortenPath that does the same
> thing
> <g>.....
>
JessicaLawson
 
Posts: 79
Joined: Sun Jun 13, 2010 1:23 pm


Return to ProMatrix User Library

Who is online

Users browsing this forum: No registered users and 2 guests

cron