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:
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