Alpha Video Training
Results 1 to 18 of 18

Thread: a combination function alltrim(str())

  1. #1
    "Certified" Alphaholic Mike Wilson's Avatar
    Real Name
    mike wilson
    Join Date
    Apr 2005
    Location
    Grand Rapids, Michigan
    Posts
    4,198

    Default a combination function alltrim(str())

    I imagine a UDF would cover this but I can't grasp how to write it at this moment.

    I want a base function in A5 that combines alltrim() and str() which I would virtually always use instread of str(). I almost always forget about the default variable lengths, and therefore the leading/trailing blanks, which causes me problems.
    Mike W
    __________________________
    "I rebel in at least small things to express to the world that I have not completely surrendered"

  2. #2
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: a combination function alltrim(str())

    Code:
    FUNCTION allstr AS C (num AS N )
    	allstr = alltrim(str(num))
    END FUNCTION
    Code:
    ? ALLSTR(4654445)
    = "4654445"
    Doesn't work for numbers over ten digits or decimals but it'll get you started.

    Maybe better....

    Code:
    FUNCTION allstr AS C (num AS N, dec as N )
    	if mod(num,1)<>0 'has decimals
    		allstr = alltrim(str(num,15,dec))
    	else 'integer
    		allstr = alltrim(str(num,15,dec))
    	end if
    END FUNCTION
    Last edited by Stan Mathews; 03-26-2008 at 12:36 PM.

  3. #3
    "Certified" Alphaholic Mike Wilson's Avatar
    Real Name
    mike wilson
    Join Date
    Apr 2005
    Location
    Grand Rapids, Michigan
    Posts
    4,198

    Default Re: a combination function alltrim(str())

    Thanks Stan,

    I'm trying to develop reciprocals similar to dtoc() and ctod() for dow() and make one for month of year also.
    Mike W
    __________________________
    "I rebel in at least small things to express to the world that I have not completely surrendered"

  4. #4
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: a combination function alltrim(str())

    Quote Originally Posted by Mike Wilson View Post
    I'm trying to develop reciprocals similar to dtoc() and ctod() for dow()
    Like cdow() ??

    No you probably mean to get a return value of "4" for April?

  5. #5
    Member
    Real Name
    Steve Andrews
    Join Date
    Jan 2004
    Location
    Mahwah, NJ
    Posts
    644

    Default Re: a combination function alltrim(str())

    Quote Originally Posted by Mike Wilson View Post
    I want a base function in A5 that combines alltrim() and str() which I would virtually always use instread of str().
    This has been proposed long ago:
    http://msgboard.alphasoftware.com/al...light=strimpad

    I created strim() and strimpad() for myself and I use them very frequently.
    Code:
    'Date Created: 12-Apr-2005 04:21:23 PM
    'Last Updated: 18-Apr-2005 10:02:30 AM
    'Created By  : Steve Andrews
    'Updated By  : Steve Andrews
    FUNCTION strim AS C (nValue AS N )
    'DESCRIPTION: This is the equivalent of alltrim(str(nValue)).
    	strim=alltrim(str(nValue))
    END FUNCTION
    Code:
    'Date Created: 12-Apr-2005 04:19:58 PM
    'Last Updated: 10-May-2005 02:34:23 PM
    'Created By  : Steve Andrews
    'Updated By  : Steve Andrews
    FUNCTION strimpad AS C (nValue AS N, nLen = 8, cFill = "0")
    'DESCRIPTION: This is the equivalent of padl(alltrim(str(nValue)),nLen,cFill) where nLen defaults to 8 and cFill defaults to "0".
    	strimpad=padl(alltrim(str(nValue)),nLen,cFill)
    END FUNCTION

  6. #6
    "Certified" Alphaholic Tim Kiebert's Avatar
    Real Name
    Tim Kiebert
    Join Date
    Jul 2004
    Location
    Geelong, Victoria, Australia
    Posts
    2,785

    Default Re: a combination function alltrim(str())

    Alpha has automatic conversion to character when using the concatenation character '+' with another character value. So I regularly use "" + NumValue as in
    Code:
    NumValue = 12
    Strg = "" + NumValue
    ?Strg
    ="12"
    Tim Kiebert
    Eagle Creek Citrus
    A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

  7. #7
    "Certified" Alphaholic Mike Wilson's Avatar
    Real Name
    mike wilson
    Join Date
    Apr 2005
    Location
    Grand Rapids, Michigan
    Posts
    4,198

    Default Re: a combination function alltrim(str())

    Stan,
    Yes,

    Code:
    ? cmofd(date())   ' this exists as  cmonth()
    = "March"
    
    ? nmofd(date())              ' this exists as month()
    = 3
    
    ? nmtocm(4)
    = "April"
    
    ? cmtonm("April")
    = 4
    Steve,
    Thanks for the examples. I have a host of them to make now.

    Tim,
    Nice! I did not know that. Pretty simple, thanks.
    Mike W
    __________________________
    "I rebel in at least small things to express to the world that I have not completely surrendered"

  8. #8
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default Re: a combination function alltrim(str())

    Hi Mike,

    Quote Originally Posted by Mike Wilson View Post
    Thanks Stan,

    I'm trying to develop reciprocals similar to dtoc() and ctod() for dow() and make one for month of year also.
    Do you mean effectively these built in functions?
    ?MONTH_NUMBER("april")
    = 4
    ?DAY_NUMBER("Monday")
    = 2
    To convert a dow number to a string
    cdow=word("Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday",dow_num,",")
    Similarly, to convert a month number to a string
    cmonth=word("January,February,March,April,May,June,July,August,September,October,November,December",month_num,",")
    I'd argue that use of the above is seldom ever really needed, as your source and target are almost always complete dates. If that is the case, you could use the built_in function to reverse those values
    Date_Value as D = DATE_VALUE( Year as N, Month as N, Day as N )
    Regards,

    Ira J. Perlow
    Computer Systems Design


    CSDA A5 Products
    New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
    CSDA Barcode Functions

    CSDA Code Utility
    CSDA Screen Capture



  9. #9
    "Certified" Alphaholic
    Real Name
    Cal Locklin
    Join Date
    Mar 2000
    Location
    S.E. Michigan
    Posts
    5,763

    Default Re: a combination function alltrim(str())

    Quote Originally Posted by Steve Andrews View Post
    I created strim() and strimpad() for myself and I use them very frequently.
    Steve (and anyone else doing things like this), be careful using simple function names like "strim" or even "strimpad". This may get you into the same trap I've run into a couple times in the past. I developed my own function then Alpha came up with their own function with the same name in a latter version of A5. This can certainly result in confusion and, in some cases, errors.

    This is why any "generic" function I create like this that could possibly be used by Alpha is named something like AIMS_xxxx. (My company name is AIMS DataCom.)

    Even something as simple as, for example, adding a "9" on the end would keep it unique - e.g., strim9().

  10. #10
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default Re: a combination function alltrim(str())

    Hi Cal,

    Quote Originally Posted by CALocklin View Post
    This is why any "generic" function I create like this that could possibly be used by Alpha is named something like AIMS_xxxx. (My company name is AIMS DataCom.)

    Even something as simple as, for example, adding a "9" on the end would keep it unique - e.g., strim9().
    This is a good warning, but adding a number at the end can create issues as well. Just take a look at some of the built-in functions ending in numbers, just a few such as ;

    • a5_toolbar_editor_V6()
    • create_shadow2()
    • md5()
    • convert_a4_to_a5()
    • a5_ADOFormMethods3()
    • a5_html_editor3()
    • ui_get_list2()
    Regards,

    Ira J. Perlow
    Computer Systems Design


    CSDA A5 Products
    New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
    CSDA Barcode Functions

    CSDA Code Utility
    CSDA Screen Capture



  11. #11
    "Certified" Alphaholic
    Real Name
    Cal Locklin
    Join Date
    Mar 2000
    Location
    S.E. Michigan
    Posts
    5,763

    Default Re: a combination function alltrim(str())

    Yeah. That's why I picked "9". I don't think that one is used anywhere - yet. The simpler the "addition" to the name, the greater the chance for duplication.

  12. #12
    Member
    Real Name
    Steve Andrews
    Join Date
    Jan 2004
    Location
    Mahwah, NJ
    Posts
    644

    Default Re: a combination function alltrim(str())

    Cal,

    Thanks for pointing that out. It's painful to think of how many field rules, filters, calculated fields, etc. I would have to change if they ever put a function named strim() into a future version.

    I have many more UDF's which are more dangerous along these lines. One is Get_Name() and another is Get_Title(). Thanks again.

    Steve

  13. #13
    "Certified" Alphaholic Mike Wilson's Avatar
    Real Name
    mike wilson
    Join Date
    Apr 2005
    Location
    Grand Rapids, Michigan
    Posts
    4,198

    Default Re: a combination function alltrim(str())

    Ira,
    Thanks for your imput. When all is said-and-done, meaning when I have hopefully absorbed all the documentation and others imput (likely incomplete even still) the only function missing is the "converts the month integer value to a month character name". It might be right in front of my nose but I am missing it.

    4-->"APRIL"

    What I found very cool, yet not in the docs, which I found out by trial and error is this:

    Code:
    ? month_number("jan")
    = 1
    The docs say nothing about the 3 letter abbreviation being equal to the full month name, yet the function does this. Which is in good part what I needed which started off this whole thread.

    So for the "converts the month integer value to a month character name" I came up with this:

    Code:
    FUNCTION mn_to_mc AS C (num as N)
    		
    dim vcM as C
    for i = 1 to 12
    	vcM = cmonth(ctod(str(i)+"/01/2008"))
    	if num = i
    		mn_to_mc = vcM
    		end
    	end if
    next
    
    END FUNCTION
    I am not concise, and I miss alot.. but this one is working for me.

    Cal,
    Thank you, thank you, thank you on the function naming tip. Yes you are keen to naming and nomenclature. Great tip. I'm wondering of your thoughts on my choice above: mn_to_mc() = MonthNumeic_To_MonthCharacter? Chances A5 will use this within their propietary? Maybe so, so then John Michael Wilson might use mn_to_mc_jmw().

    OK.. thanks!! Great stuff!
    Mike W
    __________________________
    "I rebel in at least small things to express to the world that I have not completely surrendered"

  14. #14
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default Re: a combination function alltrim(str())

    Hi Mike,

    Hellooooo.....Is this thing on?!?:D

    Did you read my post above with month_number() and day_number() as well as the reverse code (that could be placed in a function)?

    month_number() only looks at the 1st 3 characters and day_number() only the 1st 2 characters of the day of week.
    Regards,

    Ira J. Perlow
    Computer Systems Design


    CSDA A5 Products
    New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
    CSDA Barcode Functions

    CSDA Code Utility
    CSDA Screen Capture



  15. #15
    "Certified" Alphaholic Mike Wilson's Avatar
    Real Name
    mike wilson
    Join Date
    Apr 2005
    Location
    Grand Rapids, Michigan
    Posts
    4,198

    Default Re: a combination function alltrim(str())

    Quote Originally Posted by Mike Wilson View Post
    It might be right in front of my nose but I am missing it.
    Quote Originally Posted by csda1 View Post
    Similarly, to convert a month number to a string
    [INDENT] cmonth=word("January,February,March,April,May,June,July,August,September,October,November,December",month_num,",")
    Hey Ira,
    See what I mean.... right in front of my nose!:o
    So which is faster.... your word() method or my for-next method. I'm betting word(). Your the master of speed... the answer behind door number 3......?
    Word_number_get() well explains/exemplifies the functions capabilities to use partials of the word. Month_number() does not.
    month_number() only looks at the 1st 3 characters and day_number() only the 1st 2 characters of the day of week.
    From where does this come from.... your trial and error experience? Or do you have a special docs version not available to us small guys?

    So is there a reciprocal of Word_number_get() where the number produces the value of the number position in a list. I swear I have seen this, but I can't see it now.

    So, at the end of the day... if the docs had a hyperlink or something to the reciprocal of a function.......how cool would that be? ( it would be for me.... I'm a pretty simpleton guy!).
    Mike W
    __________________________
    "I rebel in at least small things to express to the world that I have not completely surrendered"

  16. #16
    "Certified" Alphaholic Tim Kiebert's Avatar
    Real Name
    Tim Kiebert
    Join Date
    Jul 2004
    Location
    Geelong, Victoria, Australia
    Posts
    2,785

    Default Re: a combination function alltrim(str())

    Hi Mike,
    Quote Originally Posted by Mike Wilson View Post

    So is there a reciprocal of Word_number_get() where the number produces the value of the number position in a list. I swear I have seen this, but I can't see it now.
    Isn't that what Word() does?
    WORD() returns one or more words, specified by the Word_Number and Word_Count and delimited by Word_Delimiter, from the supplied Input_String.
    Tim Kiebert
    Eagle Creek Citrus
    A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

  17. #17
    "Certified" Alphaholic Mike Wilson's Avatar
    Real Name
    mike wilson
    Join Date
    Apr 2005
    Location
    Grand Rapids, Michigan
    Posts
    4,198

    Default Re: a combination function alltrim(str())

    Oh.... yes.:o Clearly, a level of cognition ended somewhere before 2AM. I have, however, decided to generate a list of reciprocal functions, to assist me as my Alzheimer's creeps in.
    Mike W
    __________________________
    "I rebel in at least small things to express to the world that I have not completely surrendered"

  18. #18
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default Re: a combination function alltrim(str())

    Quote Originally Posted by Mike Wilson View Post
    From where does this come from.... your trial and error experience? Or do you have a special docs version not available to us small guys?
    .....
    So, at the end of the day... if the docs had a hyperlink or something to the reciprocal of a function.......how cool would that be? ( it would be for me.... I'm a pretty simpleton guy!).
    I'll start with your last question 1st, as that is most important!

    http://support.alphasoftware.com/alphafivehelpv8/ version 8 help
    http://support.alphasoftware.com/alphafivehelpv9/ version 9 help

    Under the Help's search tab, search for Month_Number(), Day_number(). They are both there. Search Date, go to Date and Time functions and you'll see a full list of functions

    Quote Originally Posted by Mike Wilson View Post
    So which is faster.... your word() method or my for-next method. I'm betting word(). Your the master of speed... the answer behind door number 3......?
    Any time you have a loop, you want to try to eliminate them, including any used by any functions (built-in or otherwise) it may call. How do you know which internal functions use them? By measuring their speed with some utility (Do you know of any?:)) or timing code.

    In your case, the operative part of your code doesn't require a loop and could have been
    ?cmonth(ctod(str(num)+"/01/2008"))
    which takes .00039 seconds. (Your looped version took .00139 seconds.) Compare to my version below which takes .00036 seconds.
    ?word("January,February,March,April,May,June,July,August,September,October,November,December",num,",")
    The difference is probably the two additional function call overhead that your's had.

    Quote Originally Posted by Mike Wilson View Post
    Word_number_get() well explains/exemplifies the functions capabilities to use partials of the word. Month_number() does not.
    I believe there are oddities with this function if not using CRLF() as a delimiter. I wrote my own equivalent, that runs a bit faster anyway. For most cases, use wordat() or wordatc().

    Quote Originally Posted by Mike Wilson View Post
    So is there a reciprocal of Word_number_get() where the number produces the value of the number position in a list. I swear I have seen this, but I can't see it now.
    See word() function
    Regards,

    Ira J. Perlow
    Computer Systems Design


    CSDA A5 Products
    New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
    CSDA Barcode Functions

    CSDA Code Utility
    CSDA Screen Capture



Similar Threads

  1. alltrim in function help
    By Pat Bremkamp in forum Alpha Five Version 8
    Replies: 10
    Last Post: 05-16-2007, 10:58 AM
  2. Unique Combination
    By Gary Emms in forum Alpha Five Version 4
    Replies: 3
    Last Post: 10-17-2004, 12:42 AM
  3. Names Combination Help
    By Alan Lucas in forum Alpha Five Version 6
    Replies: 7
    Last Post: 09-15-2004, 09:13 PM
  4. Alltrim Function in Index Builder Genie
    By Allen Breen in forum Alpha Five Version 5
    Replies: 5
    Last Post: 03-10-2003, 07:00 AM
  5. A bug in the STR() function?
    By Geoffrey Hollander in forum Alpha Five Version 4
    Replies: 2
    Last Post: 03-28-2001, 05:48 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •