Announcement

Collapse
No announcement yet.

Date format in textbox

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Henning Wallgren
    replied
    ian,
    thanks for the tip. i found a nice calendar routine in the
    source code that i modified and put into my program.
    big smile.
    http://www.powerbasic.com/support/pb...ad.php?t=23045


    bern,
    thanks. i copied your routine for future investigation.


    ------------------
    henning

    Leave a comment:


  • Ian Cairns
    replied
    For a neat date entry routine, why not use a Calendar Control.
    You can find some code by doing a search in the source files
    or in POFFS.

    Regards,

    ------------------
    [email protected]

    Leave a comment:


  • Bern Ertl
    replied
    Henning,

    I've been using the code posted below to handle date entries.

    It is not a mask, and the user can enter garbage if they want to,
    but you can test for validity. Basically, I convert whatever the user
    types into a SYSTEMTIME structure. That structure can then be reformatted
    as a text string in various formats using API functions. You can also
    use API Fns to convert the SYSTEMTIME to a simple UNION of QUAD & FILETIME
    to perform math on dates.

    If I rememeber correctly, credit:
    Dave Navarro - variant date API functions
    Fred Oxenby (sp?) - StringToSystemTime function

    If I remember incorrectly, someone please correct me....

    Code:
    DECLARE FUNCTION VarDateFromStr LIB "OLEAUT32.DLL" ALIAS "VarDateFromStr" (BYVAL OleString AS LONG, BYVAL lcid AS LONG, BYVAL dwFlags AS LONG, pDate AS DOUBLE) AS LONG
    DECLARE FUNCTION VariantTimeToSystemTime LIB "OLEAUT32.DLL" ALIAS "VariantTimeToSystemTime" (BYVAL vbtime AS DOUBLE, lpSystemTime AS SYSTEMTIME) AS LONG
    
    ...
    
    FUNCTION StringToSystemTime( strDateTime$, ST AS SYSTEMTIME) AS LONG
    
    LOCAL TmpDate$, rc&
    LOCAL varDate AS DOUBLE
    LOCAL LCID AS LONG
    
      LCID = GetThreadLocale()
      TmpDate$ = SPACE$(LEN(strDateTime$) * 2)
      MultiByteToWideChar %CP_ACP, _                    ' code page
                          %NULL, _                      ' performance and mapping flags
                          BYVAL STRPTR(strDateTime$), _ ' ANSI string to convert
                          LEN(strDateTime$), _          ' len of ANSI string
                          BYVAL STRPTR(TmpDate$), _     ' buffer for Unicode string
                          LEN(TmpDate$)                 ' len of Unicode buffer
      TmpDate$ = TmpDate$ & CHR$(0,0)
      rc& = VarDateFromStr(BYVAL STRPTR(TmpDate$), _
                           BYVAL LCID,BYVAL %LOCALE_NOUSEROVERRIDE, _
                           BYVAL VARPTR(varDate))
      IF rc& <> %S_OK THEN FUNCTION = rc&:EXIT FUNCTION
      VariantTimeToSystemTime varDate, ST
      FUNCTION = 0
    
    END FUNCTION
    
    ...
    
    a$ = <date input string>      'Get date string from edit box
    StringToSystemTime a$, ST     'Convert to SYSTEMTIME


    ------------------
    Bernard Ertl

    Leave a comment:


  • Henning Wallgren
    replied
    Lance,

    I found Ralph Berger's Custom Edit Control Sample and ran that.
    Copied some of the routines into my program to where I could
    display a custom edit. As for making it functional to where I
    can have a Date Only entry in my textbox... Too cryptic for
    me at this point.

    Does anybody have a routine they use to paste into their programs for
    date entries??

    ------------------
    Henning

    Leave a comment:


  • Lance Edmonds
    replied
    This is known as a masked-edit control.

    Search the Source Code forum for "masked" and you should find some code to get you started...



    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Henning Wallgren
    started a topic Date format in textbox

    Date format in textbox

    Is there a way to setup the entry field in a textbox to accept
    a date entry only?

    Like ' __/__/____ '

    ?

    ------------------
    Henning
Working...
X