Posts: 439
Threads: 17
Joined: Apr 2022
Reputation:
21
(11-03-2022, 03:26 PM)Kernelpanic Wrote: Quote:mnrvovrfc - This is the BASIC program, name it whatever you want, but place in the same directory as "hourminsec.h". Recommended both files on the same directory as QB64PE executable.
Thanks, the clock runs well. But even if both files are in the same directory, the full path must still be specified; at least at me.
Code: (Select All) Declare Library "D:\Lab\QuickBasic64\Extern\Libraries\hourminsec"
Sub hourminsec (ByVal h As Integer, Byval m As Integer, Byval s As Integer, sout As String)
End Declare
@Kernelpanic
Try using ".\hourminsec" instead
Ask me about Windows API and maybe some Linux stuff
Posts: 2,700
Threads: 124
Joined: Apr 2022
Reputation:
134
I can't believe anyone is seriously considering this as an option. Just my opinion but WTH?
b = b + ...
Posts: 714
Threads: 36
Joined: May 2022
Reputation:
13
11-03-2022, 03:59 PM
Quote:Try using ".\hourminsec" instead
Thanks for the tip, works.
Posts: 439
Threads: 17
Joined: Apr 2022
Reputation:
21
I'm confused why the external sub is using an out string rather than just returning the string. Breaks up the flow of the program with the out string style.
Ask me about Windows API and maybe some Linux stuff
Posts: 1,510
Threads: 53
Joined: Jul 2022
Reputation:
47
It's the way I was taught originally by QB64 Wiki. Go ahead and try to write it as a function; the way I write it works for me.
Another way. First this C header file called "strf.h":
Code: (Select All) #include <string.h>
#include <time.h>
void getstrftime(short h, short m, short s, char * sout)
{
struct tm tthis;
size_t fret, soutlen;
tthis.tm_sec = s;
tthis.tm_min = m;
tthis.tm_hour = h;
soutlen = strlen(sout);
fret = strftime(sout, soutlen, "%H:%M:%S", &tthis);
}
Then this BASIC file which must be in the same directory as the header file and QB64PE executable:
Code: (Select All) declare library "strf"
sub getstrftime(byval h as integer, byval m as integer, byval s as integer, soutput as string)
end declare
dim sout$
dim as integer hh, mm, ss
hh = 4
mm = 1
ss = 5
sout$ = space$(20)
getstrftime hh, mm, ss, sout$
print sout$
end
Use if it you want, but this was for showing off. My first attempt was to declare "strftime()" directly in "DECLARE" block but kept getting a C++ compilation error about the type of the last parameter. It looks like the C++ compiler expected a "double pointer" which is constant or something like that.
This duo could be customized even further, such as adding another string argument for the "format", to be able to get "2022-Nov-03" as well as the time, or something else with the date and time.
Posts: 2,700
Threads: 124
Joined: Apr 2022
Reputation:
134
Ah practicing API skills, OK!
b = b + ...
Posts: 1,510
Threads: 53
Joined: Jul 2022
Reputation:
47
11-03-2022, 05:32 PM
(11-03-2022, 05:22 PM)bplus Wrote: Ah practicing API skills, OK! In addition, I want to make it work on Linux as well as Windows. And someone else should be as interested for Macintosh.
The thing is that with Q(uick)BASIC we used to be limited to BASIC-only solutions. If someone wasn't confident enough doing mixed-language programming then he/she was content with having a mess of "LEN()" and string functions instead of "PRINT USING" only to always get two-digit date and time variables. The creators of GW-BASIC and Q(uick)BASIC didn't perceive that somebody wanted to format an arbitrary date and/or time; they felt "DATE$" and "TIME$" were good enough. That's because back then, at least on Windows those two "function values" could be changed by the user.
In QB64 we were given the choice to look for a solution in C/C++, for somebody who knew enough about it. This is something the Wiki encouraged me to do. I modified the "fileexist" example, that used to be in the Wiki, to come up with my own function which produced full paths for a given directory on the disk, and made it work on Windows and Linux.
Before QB64PE there was no example in the Wiki which wrote a function which resided in a "dot-H" file, and declared also as function inside "DECLARE" block. Declaring the ones "directly" from C runtime library didn't count for me, I wanted to see a written example like that "fileexist" one. That's why I said I was comfortable writing it as subprogram with the final parameter being changeable.
Posts: 2,700
Threads: 124
Joined: Apr 2022
Reputation:
134
11-03-2022, 05:57 PM
(This post was last modified: 11-03-2022, 05:58 PM by bplus.)
Well I practiced making a generalized Function Pad$ because of this thread but not very useful towards specific problem of OP but WTH?
Code: (Select All) _Title "Test Pad$" ' b+ 2022-11-02
Print "When fill space > string"
s$ = "Test Pad"
Print "*" + Pad$(" ", 20, s$, "l") + "*"
Print "*" + Pad$(" ", 20, s$, "c") + "*"
Print "*" + Pad$(" ", 20, s$, "r") + "*"
Print
Print: Print "When fill space < string"
Print "*" + Pad$(" ", 6, s$, "l") + "*"
Print "*" + Pad$(" ", 6, s$, "c") + "*"
Print "*" + Pad$(" ", 6, s$, "r") + "*"
Print: Print "When fill space = string"
Print "*" + Pad$(" ", 8, s$, "l") + "*"
Print "*" + Pad$(" ", 8, s$, "c") + "*"
Print "*" + Pad$(" ", 8, s$, "r") + "*"
Print: Print "zzz... press key to test Time$ format"
Sleep
' time format
While m < 60 And _KeyDown(27) = 0
Cls
Locate 2, 1: Print Pad$("_", 80, "Press escape to quit time format demo", "C")
s = s + 1
If s > 59 Then m = m + 1: s = 0
If m > 59 Then h = h + 1: m = 0
H$ = _Trim$(Str$(h)): M$ = _Trim$(Str$(m)): s$ = _Trim$(Str$(s))
Print Pad$("0", 2, H$, "r") + ":"; Pad$("0", 2, M$, "r") + ":" + Pad$("0", 2, s$, "r")
_Limit 1000
Wend
Locate 20, 1: Print Pad$(".", 80, "End of Pad$ Demo", "C")
Function Pad$ (FillChar$, nFill As Long, s$, Align$) ' fill char, width of whole string, string to align, align: L, C, R
Dim blank$
blank$ = String$(nFill, FillChar$)
Select Case UCase$(Align$)
Case "L": Mid$(blank$, 1) = s$
Case "C": Mid$(blank$, (nFill - Len(s$)) \ 2 + 1) = s$
Case "R"
If nFill >= Len(s$) Then
Mid$(blank$, nFill - Len(s$) + 1) = s$
Else
blank$ = Mid$(s$, Len(s$) - nFill + 1, nFill)
End If
End Select
Pad$ = blank$
End Function
b = b + ...
Posts: 1,507
Threads: 160
Joined: Apr 2022
Reputation:
116
You guys really do like to complicate things.
Stick to the simple BASICs:
Code: (Select All) Do
Locate 1, 1
s = s + 1: If s > 59 Then s = 0: m = m + 1
If m > 59 Then m = 0: h = h + 1
_Limit 1
Print StopWatch(h, m, s)
Loop Until _KeyHit
Function StopWatch$ (h, m, s)
o$ = "00:00:00"
h$ = _Trim$(Str$(h)): m$ = _Trim$(Str$(m)): s$ = _Trim$(Str$(s))
Mid$(o$, 3 - Len(h$)) = h$
Mid$(o$, 6 - Len(m$)) = m$
Mid$(o$, 9 - Len(s$)) = s$
StopWatch$ = o$
End Function
Posts: 439
Threads: 17
Joined: Apr 2022
Reputation:
21
(11-03-2022, 05:17 PM)mnrvovrfc Wrote: It's the way I was taught originally by QB64 Wiki. Go ahead and try to write it as a function; the way I write it works for me.
Another way. First this C header file called "strf.h":
Code: (Select All) #include <string.h>
#include <time.h>
void getstrftime(short h, short m, short s, char * sout)
{
struct tm tthis;
size_t fret, soutlen;
tthis.tm_sec = s;
tthis.tm_min = m;
tthis.tm_hour = h;
soutlen = strlen(sout);
fret = strftime(sout, soutlen, "%H:%M:%S", &tthis);
}
Then this BASIC file which must be in the same directory as the header file and QB64PE executable:
Code: (Select All) declare library "strf"
sub getstrftime(byval h as integer, byval m as integer, byval s as integer, soutput as string)
end declare
dim sout$
dim as integer hh, mm, ss
hh = 4
mm = 1
ss = 5
sout$ = space$(20)
getstrftime hh, mm, ss, sout$
print sout$
end
Use if it you want, but this was for showing off. My first attempt was to declare "strftime()" directly in "DECLARE" block but kept getting a C++ compilation error about the type of the last parameter. It looks like the C++ compiler expected a "double pointer" which is constant or something like that.
This duo could be customized even further, such as adding another string argument for the "format", to be able to get "2022-Nov-03" as well as the time, or something else with the date and time.
Try "Declare CustomType Library" instead of "Declare Library"
Ask me about Windows API and maybe some Linux stuff
|