Skip to content

Instantly share code, notes, and snippets.

View CarlTBarnes's full-sized avatar

Carl T. Barnes CarlTBarnes

View GitHub Profile
@CarlTBarnes
CarlTBarnes / DateSplit.clw
Created July 4, 2020 21:23
DateSplit(Date, Month, Day, Year) much faster than calling MONTH() DAY() YEAR() separately
DateSplit PROCEDURE(LONG Date2Split, *? OutMonth, *? OutDay, *? OutYear)
!==========================================================================================================
DateSplit PROCEDURE(LONG D, *? OutMonth, *? OutDay, *? OutYear)
!This is much faster than calling MONTH() DAY() YEAR()
D1 DATE
DG GROUP, OVER(D1)
D BYTE
M BYTE
Y USHORT
END
@CarlTBarnes
CarlTBarnes / DayOfWeek.clw
Created July 4, 2020 21:34
Day of Week from Clarion Date
DowName PROCEDURE(LONG pDate)!,STRING
CODE
RETURN CHOOSE( pDate % 7 + 1,'Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','???')
@CarlTBarnes
CarlTBarnes / MonthName.clw
Last active July 5, 2020 20:19
Month name from Date or Month number
MonthName PROCEDURE(LONG DateOrMonth),STRING !Pass Clarion Date or Month Number 1 to 12 - Month name from @d04
MonthName2 PROCEDURE(LONG DateOrMonth),STRING !Pass Clarion Date or Month Number 1 to 12 - Month name English Only
MonthName PROCEDURE(LONG DateOrMonth)!,STRING
N STRING(32),AUTO
CODE
IF DateOrMonth <= 12 THEN
DateOrMonth=DATE(DateOrMonth,1,2000)
END
N=FORMAT(DateOrMonth,@d04) !Format Month ##, YYYY
@CarlTBarnes
CarlTBarnes / PathExists.clw
Last active January 3, 2022 15:51
Path Exists or File Exists functions versus Clarion Exists()
!Clarion Exists() returns True whethere File or Directory. These functions will check explicitly for File or Path.
MAP
FileExists(STRING FileName,<*LONG OutAttributes>),BOOL !Return 1 if FileName exists and is File not Directory
PathExists(STRING PathName,<*LONG OutAttributes>),BOOL !Return 1 if PathName exists and is Directory not File
ExistsFileOrPath(STRING FileOrPathName,<*LONG OutAttributes>),BYTE !Return 1=File 2=Path 0=N/A
MODULE('Win32')
GetFileAttributes(*CSTRING FileName),LONG,PASCAL,RAW,DLL(1),NAME('GetFileAttributesA')
END
@CarlTBarnes
CarlTBarnes / RemoveMinButton.clw
Last active July 17, 2022 23:42
Remove Minimize button so window can have ICON() but user cannot minimize. Also CloseButtonDisable()
! This way your Window can have a pretty Icon() but not a Minimize button that causes end users to lose the form
MAP
RemoveMinButton() !Remove Minimize button on the Current Window so can have Icon() but no Minimize
MinButtonHide(BOOL HideMinimize=True),BOOL,PROC !Hide Minimize button (False Unhide) on the Current Window. Returns True if state changed.
MODULE('Win32')
GetWindowLong(LONG HndWindow, LONG nIndex),LONG,PASCAL,DLL(1),NAME('GetWindowLongA')
SetWindowLong(LONG HndWindow, LONG nIndex, LONG dwNewLong),LONG,PROC,PASCAL,DLL(1),NAME('SetWindowLongA')
END
@CarlTBarnes
CarlTBarnes / CBAltWin7Fix.tpl
Created July 5, 2020 22:10
A fix for the Alt key lockup problem with the latest version of Windows 10 that I wrote and published in ClarionMag
#TEMPLATE (CBAltFix, 'Carl Barnes fix for Alt Key Lockup in Windows 7'),FAMILY('ABC','CW20')
#!===========================================================================
#! Warning! Version 2 of the template changes things.
#! The Global template AltWin7Fix_Global has been removed and is no longer needed.
#! The Frame template AltWin7Fix_Frame has been renamed because it has new questions
#! Only the Frame Extension template is required, it is where you specify all choices.
#! It has a new name AltWin7Fix_Frame2 so you must populate it again on the Frame.
#! If you used the first version of the template you will get errors when you open
#! an APP. Ignore the errors, you should open the Frame, go to Extenstions and add the new template.
#! *** Removed ===>#EXTENSION (AltWin7Fix_Global,'Fix Windows 7 Alt Key Lockup-Global-by Carl Barnes'), APPLICATION
@CarlTBarnes
CarlTBarnes / ParseTokenStringIntoQueue.clw
Created July 5, 2020 22:39
Parse String with Delimited with Tokens into a Queue
MAP
ParseTokenStringIntoQueue(CONST *STRING pString,STRING pToken,*QUEUE OutQueue,BYTE pBlanksOk=0),LONG,PROC !Return Count
END
ParseTokenStringIntoQueue PROCEDURE(CONST *STRING pString,STRING pToken,*QUEUE OutQueue,BYTE pBlanksOk=0)!,LONG,PROC !Return Count
SLen LONG,AUTO !pString Length
Ndx LONG,AUTO
TokenVal BYTE,AUTO !When hunting for chars I like VAL compares
BegPos LONG(1) !BegPos = 1 required to work right
EndPos LONG,AUTO !EndPos = 0 required to work right
@CarlTBarnes
CarlTBarnes / SmashSpaces.clw
Created July 16, 2020 15:38
Smash (remove) spaces from a STRING
MAP
SmashSpaces PROCEDURE(*string InOutText, BYTE Leave1Space=0)
MODULE('RTL')
LenFastClip PROCEDURE(CONST *STRING Text2Measure),LONG,NAME('Cla$FASTCLIP'),DLL(dll_mode)
!RTL has had this since at least C55. It is much faster because it passes *STRING and is CLIP and LEN in one call
END
END
SmashSpaces PROCEDURE (*string Txt, BYTE Leave1Spc=0)
@CarlTBarnes
CarlTBarnes / Error4Message.clw
Created July 18, 2020 16:14
Format ErrorCode() & Error() etc ... to show in a Message() Stop() Halt(), or format on 1 line for a Log file or debug/tracing
MAP
Err4Msg PROCEDURE(Byte NoCRLF=0),STRING !Fromat ErrorCode() & Error() & FileError... for Message() Stop() Halt() or Log file (NoCRLF)
END
!-----------------------------------------
Err4Msg PROCEDURE(Byte NoCRLF=0)!,STRING
!Example: IF ERRORCODE() THEN STOP('Failed ADD(xxx)' & Err4Msg()).
!Note: Return starts '<13,10><13,10>Error Code:' so no need to put in the Message()
CODE
IF ~ERRORCODE() THEN RETURN ''.
IF ~NoCRLF THEN
@CarlTBarnes
CarlTBarnes / LenFastClip.clw
Created August 2, 2020 17:52
LenFastClip replaces LEN(CLIP()) in ClaRUN.DLL as NAME('Cla$FASTCLIP')
MODULE('RTL')
LenFastClip PROCEDURE(CONST *STRING Text2Measure),LONG,NAME('Cla$FASTCLIP'),DLL(dll_mode)
END
MODULE('RTL')
LenFastClip(CONST *STRING Text2Measure),LONG,NAME('Cla$FASTCLIP'),DLL(dll_mode)
END
!Use LenFastClip() or FastClip() instead of LEN(CLIP( string ))
!This has been around since at least C55. It runs much faster by passing *STRING.