RAt() and ChrTran() functions

This forum is meant for questions about the Visual FoxPro Language support in X#.

Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

RAt() and ChrTran() functions

Post 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
Attachments

[The extension viaef has been deactivated and can no longer be displayed.]

User avatar
robert
Posts: 4558
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

RAt() and ChrTran() functions

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
mainhatten
Posts: 200
Joined: Wed Oct 09, 2019 6:51 pm

RAt() and ChrTran() functions

Post 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
FoxProMatt

RAt() and ChrTran() functions

Post 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
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

RAt() and ChrTran() functions

Post 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
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

RAt() and ChrTran() functions

Post 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
User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

RAt() and ChrTran() functions

Post by kevclark64 »

? QUARTER(date(), 0) ** throws runtime error "Function argument value, type, or count is invalid."
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

RAt() and ChrTran() functions

Post 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
Attachments

[The extension viaef has been deactivated and can no longer be displayed.]

User avatar
robert
Posts: 4558
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

RAt() and ChrTran() functions

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

RAt() and ChrTran() functions

Post 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.
Post Reply