新建From1(窗体),新建Command1(按钮CommandButton),代码:
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)
Private Sub Command1_Click()
Dim xmem As MEMORYSTATUS
Dim amem, pmem, avirt, tvirt As Long
GlobalMemoryStatus xmem
amem = xmem.dwAvailPhys
pmem = xmem.dwTotalPhys
avirt = xmem.dwAvailVirtual
tvirt = xmem.dwTotalVirtual
Debug.Print "Total Physical Memory is " & Format(pmem / 1024, "###,###,###") & " KB"
Debug.Print "Available Physical Memory is " & Format(amem / 1024, "###,###,###") & " KB"
Debug.Print "Total Virtual Memory is " & Format(tvirt / 1024, "###,###,###") & " KB"
Debug.Print "Available Virtual Memory is " & Format(avirt / 1024, "###,###,###") & " KB"
End Sub