Welcome, Guest
Username: Password: Remember me
This public forum is meant for questions and discussions about Visual FoxPro
  • Page:
  • 1

TOPIC:

RAt() and ChrTran() functions 19 Apr 2020 22:09 #14120

  • Karl-Heinz
  • Karl-Heinz's Avatar
  • Topic Author


  • Posts: 774
  • 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
    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

    Please Log in or Create an account to join the conversation.

    RAt() and ChrTran() functions 20 Apr 2020 11:05 #14124

    • robert
    • robert's Avatar


  • Posts: 3595
  • 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

    Please Log in or Create an account to join the conversation.

    RAt() and ChrTran() functions 21 Apr 2020 12:14 #14125

    • mainhatten
    • mainhatten's Avatar


  • Posts: 199
  • 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

    Please Log in or Create an account to join the conversation.

    Last edit: by mainhatten.

    RAt() and ChrTran() functions 21 Apr 2020 14:00 #14126

    • FoxProMatt
    • FoxProMatt's Avatar



    @Karl-Heinz - When you said "VFP c#-Toolbox", do you mean "Visual FoxPro Toolkit for .NET"?

    github.com/mattslay/Visual-FoxPro-Toolkit-for-.NET

    Please Log in or Create an account to join the conversation.

    Last edit: by FoxProMatt.

    RAt() and ChrTran() functions 21 Apr 2020 16:23 #14127

    • Karl-Heinz
    • Karl-Heinz's Avatar
    • Topic Author


  • Posts: 774
  • 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.
    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.
    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

    Please Log in or Create an account to join the conversation.

    Last edit: by Karl-Heinz.

    RAt() and ChrTran() functions 21 Apr 2020 16:25 #14128

    • Karl-Heinz
    • Karl-Heinz's Avatar
    • Topic Author


  • Posts: 774
  • FoxProMatt wrote: @Karl-Heinz - When you said "VFP c#-Toolbox", do you mean "Visual FoxPro Toolkit for .NET"?

    github.com/mattslay/Visual-FoxPro-Toolkit-for-.NET

    Yes !

    regards
    Karl-Heinz

    Please Log in or Create an account to join the conversation.

    RAt() and ChrTran() functions 21 Apr 2020 16:36 #14129

    • kevclark64
    • kevclark64's Avatar


  • Posts: 126
  • ? QUARTER(date(), 0) ** throws runtime error "Function argument value, type, or count is invalid."

    Please Log in or Create an account to join the conversation.

    RAt() and ChrTran() functions 22 Apr 2020 18:26 #14139

    • Karl-Heinz
    • Karl-Heinz's Avatar
    • Topic Author


  • Posts: 774
  • Guys,

    i added the funcs GoMonth() and Quarter() to the viaef.
    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:
    d = {//}  
    
    ? Dtoc (d ) &&  "  .  .    "  

    regards
    Karl-Heinz

    Please Log in or Create an account to join the conversation.

    RAt() and ChrTran() functions 22 Apr 2020 18:39 #14140

    • robert
    • robert's Avatar


  • Posts: 3595
  • 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

    Please Log in or Create an account to join the conversation.

    RAt() and ChrTran() functions 22 Apr 2020 18:51 #14141

    • kevclark64
    • kevclark64's Avatar


  • Posts: 126
  • 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.

    Please Log in or Create an account to join the conversation.

    RAt() and ChrTran() functions 22 Apr 2020 18:57 #14142

    • robert
    • robert's Avatar


  • Posts: 3595
  • Kevin,
    That will not be possible in X#. Just two curly braces is an empty literal array.

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Last edit: by robert.

    RAt() and ChrTran() functions 22 Apr 2020 19:57 #14145

    • Karl-Heinz
    • Karl-Heinz's Avatar
    • Topic Author


  • Posts: 774
  • Kevin Clark wrote: 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.

    indeed, my FP-DOS results are:
    d = {}
    ? Dtoc ( d )  && "  .  .    " 
    :woohoo: :blink: :silly:

    regards
    Karl-Heinz

    Please Log in or Create an account to join the conversation.

    RAt() and ChrTran() functions 23 Apr 2020 08:29 #14158

    • Zdeněk Krejčí
    • Zdeněk Krejčí's Avatar


  • Posts: 19
  • In FP-DOS and also FVP works also {..}

    Set date german
    d={..} && empty date

    Empty date is not null.

    Please Log in or Create an account to join the conversation.

    RAt() and ChrTran() functions 26 Apr 2020 21:04 #14248

    • Karl-Heinz
    • Karl-Heinz's Avatar
    • Topic Author


  • Posts: 774
  • @Robert/Chris

    In the attachment there are two new functions.
    FUNCTION MDY ( tExpression AS DateTime ) AS STRING 
    FUNCTION MDY ( dExpression AS DATE ) AS STRING 
    	
    FUNCTION DMY ( tExpression AS DateTime ) AS STRING 
    FUNCTION DMY ( dExpression AS DATE ) AS STRING   
    When i pass a invalid date my localized FP-DOS doesn´t throw a exception but returns the german error text "*Ungültiges Datum*". Currently both functions return the hard coded text "*invalid date*". I think VFP needs, like VO, nation dependent resources where such error texts are stored.

    A few days ago I opened a ticket about the current At() and AtC() behavior.

    github.com/X-Sharp/XSharpPublic/issues/365

    I added the mentioned changes and some At() and AtC() tests to the viaef.

    regards
    Karl-Heinz
    Attachments:

    Please Log in or Create an account to join the conversation.

    RAt() and ChrTran() functions 27 Apr 2020 11:18 #14258

    • Chris
    • Chris's Avatar


  • Posts: 3980
  • Hi Karl-Heinz,

    Thanks a lot for the fixes!

    I have now adjusted the XIDE project file for the runtime in Git, so you can now test your changes against the existing test suite, enter new tests in the necessary format with Asserts etc.

    Can you please pull the latest changes, open Runtime.xiproj and see if everything compiles without errors (except for the MacroCompiler)? Then can you run the tests and see if they all pass (except for just a few related to dbfs currently)?

    When you are set, please have a look at one of the tests in the project, for example \DevRt\Runtime\XSharp.VFP.Tests\StringTests.prg, then you can create new ones in the same format, so they can be added directly to the suite.
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Last edit: by Chris.
    • Page:
    • 1