Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Month to numeric value

  1. #1
    Senior Member
    Join Date
    Jul 2013
    Location
    Ontario, Canada
    Posts
    658

    Month to numeric value

    Hello,

    Is there a function to convert a month name to its numeric value?
    Ex. "March" would be 3.

    Thanks,
    Cory

  2. #2
    Quote Originally Posted by CGibson View Post
    Hello,

    Is there a function to convert a month name to its numeric value?
    Ex. "March" would be 3.

    Thanks,
    Cory
    Hi Cory,

    Not that I'm aware of, however, it shouldn't be hard to write one. Maybe an array and ASCAN()?

  3. #3
    Member
    Join Date
    Feb 2012
    Location
    Earth.Europe.Germany.Bavaria.Obing
    Posts
    47
    And how would you handle different languages?

    But for starters you can solve it with a 1-liner:
    cSearch = "march"
    ? ASCAN( aMonth, cSearch, 1, ALINES( aMonth, "January,February,March,April,May,June,July,August ,September,October,November,December", 1, ","),1,1)
    wOOdy

  4. #4
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    657
    If you want different languages I'd set up the data in a table with month name, in each language, then the month number and just look it up.

    That way it is future proof as you can just add new entries and is much easier for teh end user to deal with as it is no longer hard coded.

  5. #5
    Senior Member
    Join Date
    Jul 2013
    Location
    Ontario, Canada
    Posts
    658
    Thank you for the replies and suggestions.

    Cory

  6. #6
    Senior Member
    Join Date
    Jul 2013
    Location
    Ontario, Canada
    Posts
    658
    Woody,

    I think you have too many parameters in the code. It crashed Lianja.
    Separating the code, it all worked fine.

    cSearch = "march"
    declare (or dimension if preferred) aMonth[12]
    ?ALINES(aMonth, "January,February,March,April,May,June,July,August ,September,October,November,December" , 1, ",")
    ?ASCAN(aMonth, proper(cSearch), 1)

    Result: 3

    Thanks for the help.

    Cory
    Last edited by CGibson; 2014-03-25 at 08:46.

  7. #7
    Member
    Join Date
    Feb 2012
    Location
    Earth.Europe.Germany.Bavaria.Obing
    Posts
    47
    Hi Cory,
    no, the main problem is, that Lianja's implementation of ASCAN is not (yet) on VFP9 level, where there is another parameter. That's also why you need the Proper in your code. I admit that I tested my sample only in VFP9, sorry for that.
    wOOdy

  8. #8
    Lianja Support Team lianjasupport's Avatar
    Join Date
    Feb 2012
    Location
    Boston USA, Wokingham UK
    Posts
    1,259
    Crashed Lianja? In what way?

  9. #9
    Lianja Support Team lianjasupport's Avatar
    Join Date
    Feb 2012
    Location
    Boston USA, Wokingham UK
    Posts
    1,259
    Please submit a ticket for that so it gets fixed.

  10. #10
    Senior Member
    Join Date
    Jul 2013
    Location
    Ontario, Canada
    Posts
    658
    Quote Originally Posted by lianjasupport View Post
    Crashed Lianja? In what way?
    Lianja froze then a message box appeared indicating I needed to close the program.
    This happened a second time when I tried it.

    Ticket has been submitted, although now if I try it, I'm getting an error message returned "ARRAY name was expected" instead of a program crash.

    I'm not sure why it's behaving differently.
    I've tried a computer reboot and it's no longer crashing the program.

    No worries, Woody.
    You helped to point me in the right direction.

    Cory

Bookmarks

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
  •  
Journey into the Cloud
Join us