xsharp.eu • RAt() and ChrTran() functions
Page 1 of 2

RAt() and ChrTran() functions

Posted: Sun Apr 19, 2020 8:09 pm
by Karl-Heinz
Guys,

i looked at the VFP c#-Toolbox sources and implemented the RAt() - which supports an optinal occurrence param - and the ChrTran() function. See the attached viaef.

1. A right occurrence search is a bit tricky and using the c# code logic unchanged would sometimes throw a exception or show wrong results, but i think i made it. Because my FP-DOS doesn´t know a RAtC() func: Is it correct that there´s no VFP [center][/center] right search available that does a none case-sensitive search ? Both, RAt() and RAtC() do according the docs a case-sensitive search only, while At() does a case-sensitive and AtC() a none case-sensitive search ?

2. The only difference in the ChrTran() implementation is that i´m using the .net replace() method and not the StrTran() func like the Toolbox does.

Let me know if you find any problems.

regards
Karl-Heinz

RAt() and ChrTran() functions

Posted: Mon Apr 20, 2020 9:05 am
by robert
Karl-Heinz,
Thanks.
We will review this and include this. Not in the upcoming 2.4 build but in the build after that.

Robert

RAt() and ChrTran() functions

Posted: Tue Apr 21, 2020 10:14 am
by mainhatten
Hi Kark-Heinz,
Karl-Heinz wrote:Both, RAt() and RAtC() do according the docs a case-sensitive search only, while At() does a case-sensitive and AtC() a none case-sensitive search ?
Vfp RATC is documented to work case sensitive and does work so. I had wondered about similar name but different descriptions/implementations and asked about that - received an answer not clearly describing a bug, but perhaps miscommunication early on, like "MS sometimes follows mysterious paths"
2. The only difference in the ChrTran() implementation is that i´m using the .net replace() method and not the StrTran() func like the Toolbox does.
Have you checked perf on loooong strings? If perf gets worse relative to vfp chrtran() as strings grow a lot, working C-like on individual chars and replacing each on a once over scan of total string might be faster, depending on the work Replace() has to do on each replace (which might be not a single char, but another string). Calling CharArray.ToString at end might be worth it (dunno if calling String.ToCharArray() first will benefit over accessing single string elements), even if adding/replacing/doing nothing for each single char is certainly slower than doing a memCopy of all "in-between chars" of Replace(). But that again is offset by the length of the string with the chars searched for - in effect the in-between chars get memcopied SearchFor.Length times...

regards
thomas

RAt() and ChrTran() functions

Posted: Tue Apr 21, 2020 12:00 pm
by FoxProMatt
@Karl-Heinz - When you said "VFP c#-Toolbox", do you mean "Visual FoxPro Toolkit for .NET"?

https://github.com/mattslay/Visual-FoxP ... t-for-.NET

RAt() and ChrTran() functions

Posted: Tue Apr 21, 2020 2:23 pm
by Karl-Heinz
Hi Thomas,

Why not just simply do a VFP / X # ChrTran() speed comparison ? In the Start () there´s code where i´m using large strings.

Code: Select all

VAR x := Replicate ( "A", 200000 ) 
VAR y := Replicate ( "I", 200000 )
 
VAR f := Seconds()
VAR g := ChrTran( x ,"A" , "IE" ) 
? Seconds() - f , "secs" 
? g == y , SLen ( g ) , SLen (y ) 
my results are:

0,00 // up to 0,01 secs ;-)
.T. , 200000, 200000

BTW. I´m looking at some other interesting VFP funcs and noticed that the Quarter() function has an optional param nMonth. With this param it´s possible to retrieve the number of a financal quarter instead of the calender quarter.

Code: Select all

QUARTER(dExpression | tExpression [, nMonth])
What does VFP do if nMonth is < 1 or > 12 ? Does it throw a runtime error or does it return 0 ?

regards
Karl-Heinz

RAt() and ChrTran() functions

Posted: Tue Apr 21, 2020 2:25 pm
by Karl-Heinz
FoxProMatt wrote:@Karl-Heinz - When you said "VFP c#-Toolbox", do you mean "Visual FoxPro Toolkit for .NET"?

https://github.com/mattslay/Visual-FoxP ... t-for-.NET
Yes !

regards
Karl-Heinz

RAt() and ChrTran() functions

Posted: Tue Apr 21, 2020 2:36 pm
by kevclark64
? QUARTER(date(), 0) ** throws runtime error "Function argument value, type, or count is invalid."

RAt() and ChrTran() functions

Posted: Wed Apr 22, 2020 4:26 pm
by Karl-Heinz
Guys,

i added the funcs GoMonth() and Quarter() to the viaef.

Code: Select all

FUNCTION GoMonth( d AS DATE , iNumberOfMonths AS INT ) AS DATE 
FUNCTION GoMonth( dt AS DateTime , iNumberOfMonths AS INT ) AS DATE

FUNCTION Quarter( d AS DATE , dwMonth := 1 AS DWORD ) AS DWORD 
FUNCTION Quarter( dt AS DateTime , dwMonth := 1 AS DWORD ) AS DWORD 
Quarter() throws a argument exception if the dwMonth value is < 1 or > 12. The dwMonth default value is 1, so at that point the fiscal quarter is equal to the calendar quarter.


@Robert

in the VFP docs i found that {//} creates a empty date, but trying that with X# throws the error:

XS9002: Parser: unexpected CRLF, are you missing a token ?

I´ve tried it with my FP-DOS dinosaur and the result is:

Code: Select all

d = {//}  

? Dtoc (d ) &&  "  .  .    "  
regards
Karl-Heinz

RAt() and ChrTran() functions

Posted: Wed Apr 22, 2020 4:39 pm
by robert
Karl Heinz,
For an empty date you can use NULL_DATE.
We'll see if we can parse that VFP format for an empty date as well in a future build.

Robert

RAt() and ChrTran() functions

Posted: Wed Apr 22, 2020 4:51 pm
by kevclark64
FYI, in Foxpro you don't need the slashes for an empty date. The open and close curly brackets by themselves do the same thing.