Post by dragonjim on Feb 1, 2024 18:21:54 GMT 1
Not as exciting as shaders, but for anyone like me frustrated by the gap in GB32, the following functions return names for Days and Months (unless I've missed some arcane function in the depths of the Help file...).
Declare Function GetThreadLocale Lib "kernel32" () As Long
Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long
Global Const LONGNAME = 1, SHORTNAME = 2
Trace DayName(WeekDay(Now)) // User Locale
Trace DayName(WeekDay(Now), SHORTNAME)
Mode Lang "PTG" // Portugal
Trace MonthName(Month(Now))
Trace MonthName(Month(Now), SHORTNAME)
Trace DayName(WeekDay(Now), , 1043) // Netherlands
Trace DayName(WeekDay(Now), SHORTNAME, 1043) // Netherlands
Trace MonthName(Month(Now), , 1031) // Germany
Trace MonthName(Month(Now), SHORTNAME, 1031) // Germany
Function DayName(day|, Optional length| = LONGNAME, Optional locale%)
$Export Func DayName "(day|, Optional length| = LONGNAME, Optional locale%)"
Local Const LOCALE_SDAYNAME1 As Long = &H2A // long name for Monday
Local Const LOCALE_SABBREVDAYNAME1 As Long = &H31 // abbreviated name for Monday
// Check to see if day| is valid
If day| < 1 Or day| > 7 Then Message "The day value must be between 1 and 7" : Return ""
// Check locale and make local if not specified
If locale% = 0 Then locale% = GetThreadLocale()
// Adjust day| to match constant values...
If day| = 1 Then day| = 8
// Retrieve the day name
Local d$ = GetUserLocaleInfo(locale%, Iif(length| = LONGNAME, LOCALE_SDAYNAME1, LOCALE_SABBREVDAYNAME1) + day| - 2)
If d$ = "" Then Message "Error in retrieving Day Name"
Return d$
EndFunction
Function MonthName(month|, Optional length| = LONGNAME, Optional locale%)
$Export Func MonthName "(month|, Optional length| = LONGNAME, Optional locale%)"
Local Const LOCALE_SMONTHNAME1 As Long = &H38 // long name for January
Local Const LOCALE_SMONTHNAME13 As Long = &H100E // long name for 13th month (if exists)
Local Const LOCALE_SABBREVMONTHNAME1 As Long = &H44 // abbreviated name for January
Local Const LOCALE_SABBREVMONTHNAME13 As Long = &H100F // abbreviated name for 13th month (if exists)
// Check locale and make local if not specified
If locale% = 0 Then locale% = GetThreadLocale()
// Check to see if locale has a 13th month
Local m13? = (Trim(GetUserLocaleInfo(locale%, LOCALE_SABBREVMONTHNAME13)) <> "")
// Check that month| is valid
If month| < 1 Or month| > Iif(m13?, 13, 12) Then Message "The month value must be between 1 and " & Trim(Iif(m13?, 13, 12)) : Return ""
// Retrieve the month name
Local m$
If month| = 13 : m$ = GetUserLocaleInfo(locale%, Iif(length| = LONGNAME, LOCALE_SMONTHNAME13, LOCALE_SABBREVMONTHNAME13))
Else : m$ = GetUserLocaleInfo(locale%, Iif(length| = LONGNAME, LOCALE_SMONTHNAME1, LOCALE_SABBREVMONTHNAME1) + month| - 1)
EndIf
If m$ = "" Then Message "Error in retrieving Month Name"
Return m$
EndFunction
Function GetUserLocaleInfo(ByVal dwLocaleID As Long, ByVal dwLCType As Long) As String
Dim sReturn As String
Dim r As Long
// Call the function passing the Locale type variable to retrieve the required size of the string buffer needed
r = GetLocaleInfo(dwLocaleID, dwLCType, sReturn, Len(sReturn))
// If successful..
If r Then
// ...pad the buffer with spaces
sReturn = Space$(r)
// ...and call again passing the buffer
r = GetLocaleInfo(dwLocaleID, dwLCType, sReturn, Len(sReturn))
// If successful (r > 0)
If r Then
// r holds the size of the string including the terminating null
GetUserLocaleInfo = Left$(sReturn, r - 1)
EndIf
EndIf
EndFunction