Visual Basic > Windows and Controls
Determine system memory status
Determine system memory status Calculate how many free and used bytes of memory you have using the following routine: Option Explicit Private Type MEMORYSTATUS memLength As Long memMemoryLoad As Long memTotalPhys As Long memAvailPhys As Long memTotalPageFile As Long memAvailPageFile As Long memTotalVirtual As Long memAvailVirtual As Long End Type Private Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As MEMORYSTATUS) 'Purpose : Returns information of the system memory usage/allocation 'Inputs : lType A long from 1 to 7 specifying the type of ' memory details you want returned 'Outputs : -1 if failed ' Or a long indicating the memory for the specified lType parameter Function Memory(lType As Long) As Long Const clKB As Long = 1024 Dim tMS As MEMORYSTATUS tMS.memLength = Len(tMS) GlobalMemoryStatus tMS Select Case lType Case 1 Memory = tMS.memMemoryLoad Case 2 Memory = tMS.memTotalPhys / clKB Case 3 Memory = tMS.memAvailPhys / clKB Case 4 Memory = tMS.memTotalPageFile / clKB Case 5 Memory = tMS.memAvailPageFile / clKB Case 6 Memory = tMS.memTotalVirtual / clKB Case 7 Memory = tMS.memAvailVirtual / clKB Case Else 'Invalid number Memory = -1 End Select End Function
Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows