FormatX$ in QB64 - eoredson - 09-29-2024
Find attached the file FormatX5.zip which contains FormatX.bas and is a library of format functions.
They are not a Print Using replicants but contain certain FormatX$ functions similar to the ones in QB 7.1
The functions allow for parsing formatted strings and unique to QB64 which has no Format$ functions.
Year between 1753 and 2078 increased to 0001 and 9999.
NOT backwards compatible with QB 4.5 because format date/time is stored in float Now## precision.
Read on! ejo
Code: (Select All) Format library v5.0a in BASIC for QB64 similar to BC7/VBDOS1 is PD 2024.
Version v1.0a:
Initial creation 09/30/2024.
Version v2.0a:
Adds StoreColor for Colorf function.
Adds KeyBoardLine$ function.
Adds Debug to StatusLine.
Adds some constants.
Version v3.0a:
Adds Control-Break trapping.
Adds statusline format strinng.
Adds titlebar timer trap.
Version v4.0a:
Adds extended LineInput$ function.
Version v5.0a:
Fixes date/time display in:
DateTimeClock$ and DateTimeClockSerial$ (serial##)
Now 2,590 lines.
RE: FormatX$ in QB64 - SMcNeill - 09-29-2024
https://qb64phoenix.com/forum/showthread.php?tid=2554
RE: FormatX$ in QB64 - eoredson - 09-29-2024
(09-29-2024, 07:24 AM)SMcNeill Wrote: https://qb64phoenix.com/forum/showthread.php?tid=2554
That is more to the point of what I was writing:
Code: (Select All)
Print Format(12345, "###,###")
Print Format(12345, "$###,###")
Print Format(Timer, "###,###.#####")
Function Format$ (num, using$)
Static tempimage
If tempimage = 0 Then tempimage = _NewImage(80, 1, 0)
d = _Dest: s = _Source
_Dest tempimage: _Source tempimage
Cls
Print Using using$; num;
For i = 1 To 80
p = Screen(1, i)
If p = 0 Then Exit For
text$ = text$ + Chr$(p)
Next
_Dest d: _Source s
Format$ = text$
End Function
I wrote a FormatX$ function to parse date/time such as: HH:MM:SS
RE: FormatX$ in QB64 - eoredson - 09-30-2024
(09-29-2024, 07:24 AM)SMcNeill Wrote: https://qb64phoenix.com/forum/showthread.php?tid=2554
Your code does not parse date/time:
Code: (Select All)
Print Format(Timer, "HH:MM:SS")
RE: FormatX$ in QB64 - eoredson - 09-30-2024
btw: The functions I wrote are in this list:
Code: (Select All) ' NOW() Returns a serial number of current date/time.
' Year between 1753 and 2078 increased to 0001 and 9999.
' FORMATX$(expression, fmt$) Formats a value to a string format.
' MONTH(serial) Returns the month from a serial number
' DAY(serial) Returns the day of the month from a serial number
' YEAR(serial) Returns the year from serial number
' MONTHSHORT(month%) Returns the month from m% argument
' MONTHSHORTSERIAL(serial) Returns the month from serial number
' MONTHLONG(month%) Returns the month from m% argument
' MONTHLONGSERIAL(serial) Returns the month from serial number
' WEEKDAY(month%, day%, year%) Returns the day of the week from m%, d%, y% arguments
' WEEKDAYSERIAL(serial) Returns the day of the week from serial number
' WEEKDAYSHORT(month%, day%, year%) Returns the short name day of the week from m%, d%, y% arguments
' WEEKDAYSHORTSERIAL(serial) Returns the short name day of the week from serial number
' WEEKDAYLONG(month%, day%, year%) Returns the long name day of the week from m%, d%, y% arguments
' WEEKDAYLONGSERIAL(serial) Returns the long name day of the week from serial number
' HOUR(serial) Returns the hour from a serial number
' MINUTE(serial) Returns the minute from a serial number
' SECOND(serial) Returns the seconds from a serial number
' DATESERIAL(month%, day%, year%) Returns a serial number from m%, d%, y% arguments
' TIMESERIAL(hour%, minute%, second%) Returns a serial number from h%, m%, s% arguments
' DATEVALUE(date$) Returns a serial number from a date string
' TIMEVALUE(time$) Returns a serial number from a time string
' DATETIMECLOCK$() Returns a formatted string of the current date/time
' DATETIMECLOCKSERIAL$(serial) Returns a formatted string of the sepcified date/time
' DATETIMESERIAL(hour%, minute%, second%, month%, day%, year%)
' FORMATDATE$(serial) Returns a formatted date string from a serial number
' FORMATTIME$(serial) Returns a formatted time string from a serial number
' ISLEAPYEAR(Y) Returns -1 if Y is a leapyear.
' DAYSINMONTH (month%) Returns days in a month, February is 28.
' DAYSINWEEK (Z%) Returns 7
' MONTHSINYEAR (Z%) Returns 12
' DAYSINYEAR (year%) Returns 365 or 366 if leapyear
' DAYOFYEAR (month%, day%, year%) Returns day of the year
' DAYOFYEARSERIAL (serial) Returns day of the serial date
RE: FormatX$ in QB64 - eoredson - 09-30-2024
also: The FormatX$ function parses this list:
Code: (Select All) ' Date and Time Formats
'
' Date/time serial numbers can be formatted with date/time formats or with
' numeric formats, since date/time serial numbers are stored as floating-
' point values. Date and time formats are:
'
' Symbol Description ' MM-DD-YYYY HH:MM:S
' ------ ----------------------------------------------------------
' d Display the day as a number without leading zeros (1-31)
' dd Display the day as a number with leading zeros (01-31)
' ddd Display the day as an abbreviation (Sun-Sat)
' dddd Display the day as a full name (Sunday-Saturday)
' ddddd Display a serial date number as a complete date
' (including day, month, and year)
'
' m Display the month as a number without leading zeros (1-12);
' if used immediately following h or hh, the minute rather
' than the month is displayed
' mm Display the month as a number with leading zeros (01-12);
' if used immediately following h or hh, the minute rather
' than the month is displayed
' mmm Display the month as an abbreviation (Jan-Dec)
' mmmm Display the month as a full name (January-December)
'
' y Display the year as a two-digit number (00-99)
' yyyy Display the year as a four-digit number (1900-2040)
'
' h Display the hour as a number without leading zeros (0-23)
' hh Display the hour as a number with leading zeros (00-23)
'
' m Display the minute as a number without leading zeros
' (0-59); if not used immediately following h or hh, the
' month rather than the minute is displayed
' mm Display the minute as a number with leading zeros (00-59);
' if not used immediately following h or hh, the month rather
' than the minute is displayed.
'
' s Display the second as a number without leading zeros (0-59)
' ss Display the second as a number with leading zeros (00-59)
'
' ttttt Display a time serial number as a complete time, including
' hour, minute, and second
'
' cccc Display full date/time in form Mon Jan 01 2010 hh:mm:ss
'
' AM/PM (Default) Use the 12-hour clock displaying AM or am with
' am/pm any hour before noon; PM or pm with any hour between noon
' and 11:59
' A/P Use the 12-hour clock displaying A or a with any hour
' a/p before noon; P or p with any hour between noon and 11:59
'
RE: FormatX$ in QB64 - eoredson - 10-02-2024
Does anyone think there is ever going to be a 5-digit year or will anyone implement one!?
Erik.
RE: FormatX$ in QB64 - SMcNeill - 10-02-2024
(10-02-2024, 03:49 AM)eoredson Wrote: Does anyone think there is ever going to be a 5-digit year or will anyone implement one!?
Erik.
We'll reform the calendar system and reset it before we ever get that far. Some day, when my genius if finally recognized from the world, everything will swap from Julian Calendar to Steve Calendar...
RE: FormatX$ in QB64 - Dimster - 10-02-2024
I like that Steve. An 8 day week .. Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Someday. Seems to me I already work on that calendar.
|