QB64 Phoenix Edition
A func.bas makes a func.exe - Can I Call(SHELL?) to func.exe? - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: A func.bas makes a func.exe - Can I Call(SHELL?) to func.exe? (/showthread.php?tid=406)



A func.bas makes a func.exe - Can I Call(SHELL?) to func.exe? - dcromley - 05-13-2022

Sub: A func.bas makes a func.exe - Can I SHELL to func.exe?  Yes I can, but it is SLOW.  My func.bas program is msecs.bas, which gets milliseconds since midnight.

Program 1 shows that the API call is FAST.  BUT I don't want to have all the baggage (Type..End Type, Declare..EndDeclare, Function..EndFunction), I'd rather compile it and call (SHELL?) it.


Code: (Select All)
_Title "Test IncodeMsecs"
Option _Explicit
DefLng A-Z

Type typeTime
  yr As Integer
  mo As Integer
  ddWk As Integer
  dd As Integer
  hh As Integer
  mm As Integer
  ss As Integer
  ms As Integer
End Type

Declare Dynamic Library "Kernel32"
  Sub GetSystemTime (lpSystemTime As typeTime)
End Declare

Dim i, nloops, ms0 ' start
For i = 1 To 20
  ms0 = IncodeMsecs
  Do Until IncodeMsecs <> ms0: Loop ' start a new ms
  nloops = 0 ' start counting
  ms0 = IncodeMsecs ' during this 1 ms
  Do Until IncodeMsecs <> ms0: nloops = nloops + 1: Loop
  Print nloops; " loops in 1 millisecond"
Next i

Function IncodeMsecs () ' This is FAST, but how to compile it and use it as an exe file?
  Dim sysTime As typeTime, hh, mm, ss, ms
  GetSystemTime sysTime
  hh = sysTime.hh
  mm = sysTime.mm
  ss = sysTime.ss
  ms = sysTime.ms
  IncodeMsecs = ms + 1000 * (ss + 60 * (mm + 60 * hh))
End Function

Program 2 is THE msecs.bas (with the baggage) which makes msecs.exe which returns milliseconds:

Code: (Select All)
_Title "msecs"
Option _Explicit
DefLng A-Z

Type typeTime
  yr As Integer
  mo As Integer
  ddWk As Integer
  dd As Integer
  hh As Integer
  mm As Integer
  ss As Integer
  ms As Integer
End Type

Declare Dynamic Library "Kernel32"
  Sub GetSystemTime (lpSystemTime As typeTime)
End Declare

Dim Shared sysTime As typeTime
GetSystemTime sysTime
Dim hh, mm, ss, ms
hh = sysTime.hh
mm = sysTime.mm
ss = sysTime.ss
ms = sysTime.ms
System ms + 1000 * (ss + 60 * (mm + 60 * hh))

Program 3 (without the baggage) shows that IT WORKS, but is SLOW.  You spend 1000 ms to get the current ms.

Code: (Select All)
_Title "Test2 msecs"
Option _Explicit
DefLng A-Z

Print Shell("msecs") ' SLOW!
Print Shell("msecs")
Print Shell("msecs")
Print Shell("msecs")
Print Shell("msecs")
Print Shell("msecs")
Print Shell("msecs")
Print Shell("msecs")
Print Shell("msecs")
Print Shell("msecs")

1) I don't want to hear about something like that _Millisecs() already exists -- I want to pursue doing this. [ I found out about Timer(.001) ! ]
2) Apparently msecs.exe is not staying in memory - is being re-loaded each call.
3) Apparently msecs.exe is opening/closing an unused/unwanted console window.
4) This makes it SLOW.  Can I fix these issues?

I would appreciate your solutions.


RE: A func.bas makes a func.exe - Can I Call(SHELL?) to func.exe? - SMcNeill - 05-13-2022

You're shelling to an external program, opening that program, running that program, closing that program... Of course it's going to be slow -- that's a lot of system calls to be making to get your result.

Instead, find some other way for your programs to communicate, without having to shell/load/run/close them each time you want something from them.

https://qb64phoenix.com/forum/showthread.php?tid=302 -- -like here, my mini messenger is using open connection to chat with each other.

If you've got a RAM Drive up and going, you could always write the data to a file with the first program, and then read the data with the second program, as needed. (I wouldn't want to beat my poor hard drive to death using such a means of interaction, but it'd be easy to do with a ram drive.)


RE: A func.bas makes a func.exe - Can I Call(SHELL?) to func.exe? - dcromley - 05-13-2022

> SMcNeill: " .. my mini messenger .. "
So far I've chatted with myself (2 windows), but not my wife upstairs. I'll be looking at this. Thanks.

> " .. RAM Drive .. "
I had one, but don't now, I will consider that. Thanks.

Please give me a link to an example or something to find out how to not have a console and just return a number (System [return_code%]).