Hi,
Is there a way of getting the amount of memory under Win9x/NT/2000?
Thanks in advance
Printable View
Hi,
Is there a way of getting the amount of memory under Win9x/NT/2000?
Thanks in advance
Why, of course there is! :D
Create a new standard project and put a CommandButton (Command1) on the form.
Then, use this code:
Code:Option Explicit
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 MS As MEMORYSTATUS ' Declare MEMORYSTATUS structure
Dim sMsg As String
MS.dwLength = Len(MS) ' Determine the size of the structure (required for compatibility)
Call GlobalMemoryStatus(MS) ' Fill the structure with information
' Now, MS.dwAvailPhys is the amount of available RAM (in bytes)
' and MB.dwTotalPhys is the amount of total RAM (in bytes).
' To determine the amount in megabytes you need to divide by 2^20 (1048576).
' You can use CLng to remove the remainder.
sMsg = "You have " & CLng(MS.dwAvailPhys / 2 ^ 20) & " megabytes of RAM available, out" & vbCrLf
sMsg = sMsg & "of " & CLng(MS.dwTotalPhys / 2 ^ 20) & " bytes of RAM. ("
' Determine percentage:
sMsg = sMsg & CLng(MS.dwAvailPhys / MS.dwTotalPhys * 100)
sMsg = sMsg & "% free)"
Call MsgBox(sMsg, vbExclamation)
End Sub
Hi,
You can use api call.
Thank you very much for the information. I really appreciate that.