Re: something similar to shortname function in filesystemobject by Stephen
Stephen
Mon Jun 05 08:37:54 CDT 2006
Just for feedback, I used code based on Mohammed's, but many thanks Josh. I
also added a double chrtran(chrtran()) function to strip out all the
unwanted characters and spaces from the original source name and eventually
got it working exactly as I required.
Thanks
Stephen
"Imaginecorp" <imaginecorp@msn.com> wrote in message
news:uqFYuVEiGHA.4044@TK2MSFTNGP03.phx.gbl...
> Like they say, hundreds of ways to skin a cat...
> I agree... a challenge is always fun...Keeps the brain sharp
> Mohammed
>
> "Josh Assing" <XjoshX@jAssing.com> wrote in message
> news:dt0782hapa5kj8ja2g1lguoc969sn2jced@4ax.com...
>> On Sun, 4 Jun 2006 20:03:17 -0400, "Imaginecorp" <imaginecorp@msn.com>
>> wrote:
>>
>>>Pardon me,
>>>But all this when simple VFP code will do... Like using a 100lb sledge
>>>hammer to swat a fly don't you think..
>>
>>
>> I dunno -- sometimes puzzles are fun.
>> Besides -- simple vfp code ? mine was pretty simple....
>> the original post was to emulate windows type getshort name, such that
>> the
>> begining X characters are like the original name, with a different end
>> number....
>>
>> anyway; puzzles are fun sometimes
>>
>>
>>>Mohammed
>>>www.imaginecorp.com/whatwedo.htm
>>>
>>>"Josh Assing" <XjoshX@jAssing.com> wrote in message
>>>news:80p682dkdqi3lqulcbkqvgirbhcai4a00g@4ax.com...
>>>> How about this, I didn't work too hard on optimizing it (well; at all)
>>>> just to
>>>> get the idea out there.
>>>>
>>>> This should work for you no matter what.....
>>>>
>>>>
>>>> * GetShortName.prg
>>>>
>>>> * These restrctions are not enforced in the code!!!
>>>> * Restrictions nShortName > nUnque + 1
>>>> * Unique must be >= 1
>>>> * unique msut be <= 7
>>>>
>>>> #DEFINE nShortName 8 && How many characters do we want the "shortname"
>>>> to
>>>> be?
>>>> #DEFINE nUnique 2 && how many do we anticipate, 2 characters = 255
>>>> collisions
>>>> #DEFINE cDataFile "ShortNameList"
>>>>
>>>> FUNCTION GetShortName
>>>> LPARAMETERS tcLongName
>>>> * Thanks to josh of vfpcoding.com for this code
>>>>
>>>> LOCAL lcShortName AS STRING, ;
>>>> loSession AS SESSION,;
>>>> lnCurrentDataSession AS INTEGER,;
>>>> lnCount AS INTEGER,;
>>>> lcDataFile AS STRING
>>>>
>>>> lnCurrentDataSession = SET("DataSession")
>>>> loSession=CREATEOBJECT("Session")
>>>> SET DATASESSION TO loSession.DATASESSIONID
>>>> IF !FILE(FORCEEXT(cDataFile,"DBF"))
>>>> lcDataFile = cDataFile && Goofy;but it's the only way with the
>>>> #define
>>>> CREATE TABLE &lcDataFile (;
>>>> LongName M,;
>>>> ShortName c(nShortName) )
>>>> INDEX ON PADR(LongName,nShortName) TAG LongName
>>>> INDEX ON ShortName TAG ShortName
>>>> USE
>>>> ENDIF
>>>> USE ShortName SHARED ORDER LongName
>>>> IF !SEEK(PADR(tcLongName, nShortName))
>>>> * Not found quickly; add it
>>>> lnCount = 0
>>>> ELSE
>>>> * It was found... rats, this might take a bit longer
>>>> LOCATE FOR tcLongName == LongName
>>>> IF FOUND()
>>>> lcShortName = ShortName
>>>> lnCount = -1 && Signal we found it.
>>>> ELSE
>>>> COUNT ;
>>>> FOR PADR(tcLongName, nShortName-nUnique) ==
>>>> PADR(LongName,nShortName-nUnique);
>>>> TO lnCount
>>>> ENDIF
>>>> ENDIF
>>>> IF lnCount # -1
>>>> lcShortName =
>>>> LEFT(PADR(tcLongName,nShortName),nShortName-nUnique)+RIGHT(TRANSFORM(lnCount,"@0"),nUnique)
>>>> INSERT INTO ShortName;
>>>> (LongName, ShortName) ;
>>>> VALUES;
>>>> (tcLongName, lcShortName)
>>>> ENDIF
>>>> USE IN ShortName
>>>> SET DATASESSION TO lnCurrentDataSession
>>>>
>>>> RETURN lcShortName
>>>> ENDFUNC
>>>>
>>>>
>>>>
>>>> --- AntiSpam/harvest ---
>>>> Remove X's to send email to me.
>>>
>>
>>
>> --- AntiSpam/harvest ---
>> Remove X's to send email to me.
>
>