Announcement

Collapse
No announcement yet.

equivalent for BYVAL %NULL?

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

  • equivalent for BYVAL %NULL?

    Hello folks,

    I've encountered a problem with GetDateFormat. In WIN32API.INC this API is declared as follows:
    Code:
    DECLARE FUNCTION GetDateFormat LIB "KERNEL32.DLL" _
              ALIAS "GetDateFormatA" (BYVAL Locale AS LONG, _
                                      BYVAL dwFlags AS LONG, _
                                      lpDate AS SYSTEMTIME, _
                                      lpFormat AS ASCIIZ, _
                                      lpDateStr AS ASCIIZ, _
                                      BYVAL cchDate AS LONG) AS LONG
    You can use this in 2 ways. Either you pass %DATE_LONGDATE (or shortdate) through dwFlags and BYVAL %NULL through lpFormat, or you pass a special format (such as "MMMM d") through lpFormat, while dwFlags is zero.

    First strange thing: lpFormat is declared as a null-terminated string, but in case you want to leave it empty, BYVAL %NULL, which is a numeric!, is the correct param. By what can you replace this, eventually? I want to build a FUNCTION that uses this API, but in such a way that it passes the correct variables through dwFlags or lpFormat, depending of the content of a param passed.
    This is the idea:
    Code:
    FUNCTION MakeDate(sFormat AS STRING) AS STRING
      LOCAL lFormat AS LONG, st AS SYSTEMTIME, szText AS ASCIIZ * 255
     
      lFormat = VAL(sFormat)
      IF lFormat = 1 OR lFormat = 2 THEN sFormat = xxxx [here I need a valid replacement for BYVAL %NULL]   
      GetDateFormat %LOCALE_USER_DEFAULT, lFormat, st, sFormat, szText, SIZEOF(szText)  
      FUNCTION = szText
    END FUNCTION
    I tried several sorts of string operands, but nothing worked. The only thing I can get working is an IF...ELSE structure with 2 complete API-calls, but that's not what I want. I just want to alter the vars and then use the same API-call for both situations.

    Any idea? Thanks in advance.
    Regards,
    Egbert

    ------------------


    [This message has been edited by Egbert Zijlema (edited July 04, 2000).]

    Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
    http://zijlema.basicguru.eu
    *** Opinions expressed here are not necessarily untrue ***

  • #2
    Egbert --
    You can do something like this
    Code:
       #Compile Exe
       #Register None
       #Dim All
       #Include "Win32Api.Inc"
       
       Function MakeDate(sFormat As String) As String
          Local szText As Asciiz * 255, FormatAddr As Dword, Flags As Dword
          If sFormat = "SHORTDATE" Then Flags = %DATE_SHORTDATE: FormatAddr = 0 Else _
          If sFormat = "LONGDATE" Then Flags = %DATE_LONGDATE: FormatAddr = 0 Else _
                                       Flags = 0: FormatAddr = StrPtr(sFormat)
          GetDateFormat %LOCALE_USER_DEFAULT, Flags, ByVal %Null, ByVal FormatAddr, szText, SizeOf(szText)
          Function = szText
       End Function
       
       Function PbMain
          MsgBox "ShortDate is " + MakeDate ("SHORTDATE")
          MsgBox "LongDate is " + MakeDate ("LONGDATE")
          MsgBox "Custom format is " + MakeDate("dddd dd/MM/yyyy")
       End Function

    ------------------

    Comment


    • #3
      Semen,

      Thank you. In the meantime I found out, that using BYCOPY also works.
      If you want to see an example then download my recently posted "get certain weekday from month" routine.

      Regards,
      Egbert

      ------------------


      [This message has been edited by Egbert Zijlema (edited July 06, 2000).]

      Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
      http://zijlema.basicguru.eu
      *** Opinions expressed here are not necessarily untrue ***

      Comment

      Working...
      X