VB and VBA Users Source Code: Determine system memory status
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Determine system memory status
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Sunday, October 29, 2000
Hits:
649
Category:
Windows API
Article:
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 'Author : Andrew Baker 'Date : 29/10/2000 11:09 'Notes : 'Revisions : 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
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder