Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New and improved SICK project
#9
I took your suggestion and moved the function declarations to the bottom of the code, but, the
program still exits the windows after a start..

Erik.

btw; what is "as" without any preceding variable?

WTF: does anybody out there test their code before posting it??

Now I have this snippet of code that does not work:

Code: (Select All)
' declare all default variables
DefDbl A-Z
Rem $DYNAMIC

Type MEMORYSTATUSEX
  As _Unsigned Long dwLength, dwMemoryLoad
  As _Unsigned _Integer64 ullTotalPhys, ullAvailPhys, ullTotalPageFile, ullAvailPageFile, ullTotalVirtual, ullAvailVirtual, ullAvailExtendedVirtual
End Type

Type FILETIME
  As _Unsigned Long dwLowDateTime, dwHighDateTime
End Type

Declare CustomType Library
  Sub GlobalMemoryStatusEx (ByVal lpBuffer As _Offset)
  Function GetSystemTimes& (ByVal lpIdleTime As _Offset, Byval lpKernelTime As _Offset, Byval lpUserTime As _Offset)
End Declare

Dim Shared t6 As Integer
Dim Shared t7 As Single

' start cpu timer trap
t6 = _FreeTimer
t7! = 1!
On Timer(t6, t7!) CPUtrap ' title with cpu
Timer(t6) On
Do
  _Limit 50
  x$ = InKey$
  If Len(x$) Then Exit Do
Loop
Timer(t6) Off
End

Sub CPUtrap
  S$ = Str$(Int(GetCPULoad * 10000) / 100) ' 100.00
  If InStr(S$, ".") Then
      Q$ = Mid$(S$, InStr(S$, ".") + 1)
      S$ = Left$(S$, InStr(S$, ".") - 1)
      Q$ = Left$(Q$, 3)
      S$ = S$ + "." + Q$
  Else
      S$ = S$ + ".0"
  End If
  D$ = "CPU " + S$ + "%" ' 100.00
  Cls
  Print D$
End Sub

Function MemInUsePercent~& ()
  Dim As MEMORYSTATUSEX statex
  statex.dwLength = Len(statex)
  GlobalMemoryStatusEx _Offset(statex)
  MemInUsePercent = statex.dwMemoryLoad
End Function

Function TotalPhysicalMem~&& ()
  Dim As MEMORYSTATUSEX statex
  statex.dwLength = Len(statex)
  GlobalMemoryStatusEx _Offset(statex)
  TotalPhysicalMem = statex.ullTotalPhys
End Function

Function FreePhysicalMem~&& ()
  Dim As MEMORYSTATUSEX statex
  statex.dwLength = Len(statex)
  GlobalMemoryStatusEx _Offset(statex)
  FreePhysicalMem = statex.ullAvailPhys
End Function

Function TotalPagingFile~&& ()
  Dim As MEMORYSTATUSEX statex
  statex.dwLength = Len(statex)
  GlobalMemoryStatusEx _Offset(statex)
  TotalPagingFile = statex.ullTotalPageFile
End Function

Function FreePagingFile~&& ()
  Dim As MEMORYSTATUSEX statex
  statex.dwLength = Len(statex)
  GlobalMemoryStatusEx _Offset(statex)
  FreePagingFile = statex.ullAvailPageFile
End Function

Function TotalVirtualMem~&& ()
  Dim As MEMORYSTATUSEX statex
  statex.dwLength = Len(statex)
  GlobalMemoryStatusEx _Offset(statex)
  TotalVirtualMem = statex.ullTotalVirtual
End Function

Function FreeVirtualMem~&& ()
  Dim As MEMORYSTATUSEX statex
  statex.dwLength = Len(statex)
  GlobalMemoryStatusEx _Offset(statex)
  FreeVirtualMem = statex.ullAvailVirtual
End Function

Function FreeExtendedMem~&& ()
  Dim As MEMORYSTATUSEX statex
  statex.dwLength = Len(statex)
  GlobalMemoryStatusEx _Offset(statex)
  FreeExtendedMem = statex.ullAvailExtendedVirtual
End Function

Function CalculateCPULoad! (idleTicks As _Unsigned _Integer64, totalTicks As _Unsigned _Integer64) Static
  Static As _Unsigned _Integer64 previousTotalTicks, previousIdleTicks

  Dim As _Unsigned _Integer64 totalTicksSinceLastTime: totalTicksSinceLastTime = totalTicks - previousTotalTicks
  Dim As _Unsigned _Integer64 idleTicksSinceLastTime: idleTicksSinceLastTime = idleTicks - previousIdleTicks

  Dim As Single ret
  If totalTicksSinceLastTime > 0 Then ret = 1.0 - idleTicksSinceLastTime / totalTicksSinceLastTime Else ret = 0

  previousTotalTicks = totalTicks
  previousIdleTicks = idleTicks
  CalculateCPULoad = ret
End Function

Function FileTimeToInt64~&& (ft As FILETIME) Static
  FileTimeToInt64 = _SHL(ft.dwHighDateTime, 32) Or ft.dwLowDateTime
End Function

Function GetCPULoad! ()
  Dim As FILETIME idleTime, kernelTime, userTime
  If GetSystemTimes(_Offset(idleTime), _Offset(kernelTime), _Offset(userTime)) Then GetCPULoad = CalculateCPULoad(FileTimeToInt64(idleTime), FileTimeToInt64(kernelTime) + FileTimeToInt64(userTime)) Else GetCPULoad = -1.0
End Function
Reply


Messages In This Thread
New and improved SICK project - by eoredson - 09-20-2022, 04:44 AM
RE: New and improved SICK project - by mnrvovrfc - 09-24-2022, 02:52 AM
RE: New and improved SICK project - by mnrvovrfc - 09-24-2022, 08:06 PM
RE: New and improved SICK project - by eoredson - 09-27-2022, 06:21 AM
RE: New and improved SICK project - by eoredson - 09-28-2022, 03:11 AM
RE: New and improved SICK project - by mnrvovrfc - 09-28-2022, 04:39 AM
RE: New and improved SICK project - by eoredson - 09-28-2022, 05:03 AM
RE: New and improved SICK project - by mnrvovrfc - 10-06-2022, 11:34 PM
RE: New and improved SICK project - by mnrvovrfc - 09-28-2022, 07:02 PM
RE: New and improved SICK project - by Pete - 09-28-2022, 03:48 PM
RE: New and improved SICK project - by aurel - 09-28-2022, 09:34 PM
RE: New and improved SICK project - by eoredson - 09-29-2022, 04:45 AM
RE: New and improved SICK project - by Pete - 09-28-2022, 09:46 PM
RE: New and improved SICK project - by mnrvovrfc - 09-30-2022, 04:25 PM
RE: New and improved SICK project - by eoredson - 10-01-2022, 02:30 AM
RE: New and improved SICK project - by eoredson - 10-01-2022, 03:58 AM
RE: New and improved SICK project - by mnrvovrfc - 10-04-2022, 02:20 PM
RE: New and improved SICK project - by eoredson - 10-06-2022, 12:44 AM
RE: New and improved SICK project - by mnrvovrfc - 10-06-2022, 05:12 AM
RE: New and improved SICK project - by aurel - 10-06-2022, 07:09 PM
RE: New and improved SICK project - by mnrvovrfc - 10-06-2022, 08:05 PM
RE: New and improved SICK project - by bplus - 10-06-2022, 07:46 PM
RE: New and improved SICK project - by aurel - 10-07-2022, 11:39 AM
RE: New and improved SICK project - by aurel - 10-07-2022, 12:00 PM
RE: New and improved SICK project - by mnrvovrfc - 10-07-2022, 11:41 PM
RE: New and improved SICK project - by mnrvovrfc - 10-12-2022, 05:19 PM
RE: New and improved SICK project - by eoredson - 10-21-2022, 03:15 AM
RE: New and improved SICK project - by mnrvovrfc - 10-21-2022, 07:03 AM
RE: New and improved SICK project - by eoredson - 03-11-2023, 04:34 AM
RE: New and improved SICK project - by eoredson - 04-07-2023, 03:52 AM
RE: New and improved SICK project - by eoredson - 09-15-2023, 12:17 AM



Users browsing this thread: 1 Guest(s)