In the 16-bit world of Windows, the global memory and user information was obtained using the GetFreeSpace and GetFreeSystemResources APIs. Under Win32, these were dropped and replaced with the GlobalMemoryStatus API. This demo is a quickie, showing how to retrieve the memory information of the system and display it in a label control array. Combined with other system information-based calls, a concise summary of the users current environment can be displayed. To create this project, add a command button (cmdEnd) and two control arrays of seven labels each to the form (Label1(0)-(6) for the line descriptions and lbMemStat(0)-(6) for the API results).

Form

Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2000 VB net , Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' You are free to use this code within your own applications,
' but you are expressly forbidden from selling or otherwise
' distributing this source code without prior written consent.
' This includes both posting free demo projects made from this
' code as well as reproducing the code in text or html format.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Type MEMORYSTATUS
dwLength As Long
dwMemoryLoad As Long
dwTotalPhys As Long
dwAvailPhys As Long
dwTotalPageFile As Long
dwAvailPageFile As Long
dwTotalVirtual As Long
dwAvailVirtual As Long
End Type

Private Declare Sub GlobalMemoryStatus Lib "kernel32" _
(lpBuffer As MEMORYSTATUS)

'constants used to shorten the output strings
Const fmt As String = "###,###,###,###"
Const skb As String = " Kbyte"
Const nkb As Long = 1024


Private Sub cmdEnd_Click()

Unload Me
Set Form1 = Nothing

End Sub

Private Sub Form_Load()

Dim MS As MEMORYSTATUS

MS.dwLength = Len(MS)
GlobalMemoryStatus MS

'divide the memory variables by 1024 (nkb)
'to obtain the size in kilobytes
lbMemStat(0) = Format$(MS.dwMemoryLoad, fmt) & " % used"
lbMemStat(1) = Format$(MS.dwTotalPhys / nkb, fmt) & skb
lbMemStat(2) = Format$(MS.dwAvailPhys / nkb, fmt) & skb
lbMemStat(3) = Format$(MS.dwTotalPageFile / nkb, fmt) & skb
lbMemStat(4) = Format$(MS.dwAvailPageFile / nkb, fmt) & skb
lbMemStat(5) = Format$(MS.dwTotalVirtual / nkb, fmt) & skb
lbMemStat(6) = Format$(MS.dwAvailVirtual / nkb, fmt) & skb

End Sub
'--end block--'

COMMENTS
Save & run the project. The current system memory status will be displayed in the labels. The information returned by the GlobalMemoryStatus function is volatile .... there is no guarantee that two sequential calls to this function will return the same information. The MSDN describes the various members of the MEMORYSTATUS structure as:
dwLength
The size in bytes of the MEMORYSTATUS data structure. You do not need to set this member before calling the GlobalMemoryStatus function; the function sets it.

dwMemoryLoad
Specifies a number between 0 and 100 that gives a general idea of current memory utilization, in which 0 indicates no memory use and 100 indicates full memory use.

dwTotalPhys
Indicates the total number of bytes of physical memory.

dwAvailPhys
Indicates the number of bytes of physical memory available.

dwTotalPageFile
Indicates the total number of bytes that can be stored in the paging file. Note that this number does not represent the actual physical size of the paging file on disk.

dwAvailPageFile
Indicates the number of bytes available in the paging file.

dwTotalVirtual
Indicates the total number of bytes that can be described in the user mode portion of the virtual address space of the calling process.

dwAvailVirtual
Indicates the number of bytes of unreserved and uncommitted memory in the user mode portion of the virtual address space of the calling process.
1