resources used/free

How do I determine in vb6 the abount of system recsources are free.  For example in msinfo it tells me I have 20%free.  Same goes in many Help-abouts.
ocsscottAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DrDelphiCommented:
Take a look at the GlobalMemorystatus API.
0
lazarruCommented:
You can use the API
Public Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As MemoryStatus)

Here's a quick example

Public 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

Public Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As MemoryStatus)

Public memInfo As MemoryStatus


Private Sub Command1_Click()
memInfo.dwLength = Len(memInfo) 'size MemoryStat

Call GlobalMemoryStatus(memInfo)

MsgBox memInfo.dwTotalPhys
end sub
0
ocsscottAuthor Commented:
i did i see memory load but it shows 100 abd the correct answer should have been 80%used.  any tricks to it i dont know about
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

ocsscottAuthor Commented:
that shows total ram I need amount of resources free in the old days it was gui memory free.  the number I need is a percentage and does not apear to be memory load
0
lazarruCommented:
What about the dxTotalVirtual and dwAvailVirtual values.  You will need to compute the % yourself.  The structure contains more than just the value I displayed
0
ocsscottAuthor Commented:
I need to know what windows consider free resources and how to compute the same number.  The virtual memory items you mention are including swap file.  If I understand it correct resources refrer to heap and stack space used not pure ram,
0
RuchiCommented:
Use the GetDiskFreeSpaceEx for hard drives over 2GB. If use the GetDiskFreeSpace, API can handle hard drives up to 2GB. Place a command button on the form.


Option Explicit

Private Sub Command1_Click()
MsgBox "Free space on drive C: is: " & GetFreeSpacep("C:")
End Sub

Private Function GetFreeSpacep(pDrive As String) As String
    Dim curTotalBytes As Currency
    Dim curFreeBytesToCaller As Currency
    Dim curTotalFreeBytes As Currency
   
    Call GetDiskFreeSpaceEx(pDrive, curFreeBytesToCaller, curTotalBytes, curTotalFreeBytes)
    GetFreeSpacep = Format$((curTotalFreeBytes) / curTotalBytes, "0.00%")  ' & "pcercent is " & curTotalFreeBytes \ curTotalBytes
End Function
0
RuchiCommented:
Oh you want to know the amount of memory used... I thought that you want to get the amount of free space on a certain drive of a system. I must have been misunderstanding about your questoin...
0
ocsscottAuthor Commented:
yes memory resources.
0
RuchiCommented:
I got the following code from the web and made some modifcations. I tested it and it seemed to be working..

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)

Const fmt As String = "###,###,###,###"

Private Sub Form_Load()

   Dim MS As MEMORYSTATUS
   
   MS.dwLength = Len(MS)
   GlobalMemoryStatus MS
   
   Label1.Caption = Format$(MS.dwMemoryLoad, fmt) & " % used"

End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ocsscottAuthor Commented:
doesnt give the same anser as say msinfo32  which is what i am comparing to.  In 16bit days you could look at gdu and user res free.  I think somehow I need to call the 16bit api's from the old days.  any ideas?
0
RuchiCommented:
what is gdu?
0
RuchiCommented:
For 16-bit, the global memory and user information was obtained using the GetFreeSpace and GetFreeSystemResources APIs.

GetFreeSpace
Declare Function GetFreeSpace Lib "Kernel" (ByVal wFlags As Integer) As Long

GetFreeSystemResources
Declare Function GetFreeSystemResources Lib "User" (ByVal fuSysResource As Integer) As Integer

This is what you are looking for?

Hope this helps..
0
ocsscottAuthor Commented:
perhaps but how can I call those old api's in win 95/98 with vb6
0
RuchiCommented:
The API functions used for 3.1 uses a 16 Bit API. Windows 95 and Windows NT use a 32 bit API. At present there are four different flavors of the Windows API. These are :
Win 16 - Windows 3.1
Win 32 - Windows NT
Win 32 c - Windows 95
Win 32 s - Windows for WorkGroups.

That's all I can know of.


According to the person's comments....

It doesn't depend on the version of VB you're using, it depends on the operating system. DOS (8-bit) can't use any APIs, Windows 3.X can only use the Win16 APIs (Shell.DLL, User.DLL, GDI.DLL, Kernel.DLL etc.) and Windows 95/98 can use both Win16 APIs and Win32 APIs (Shell32.DLL, User32.DLL, GDI32.DLL, Kernel32.DLL, etc.).
There is an add-on to Windows 3.11 called Win32 Support which lets you use (slightly modified versions of) the Win32 APIs on this operating system.

Since the version of VB doesn't matter, VB4 (or even VB1 for this matter) can use the Win32 APIs, as long as it's installed on a machine running Windows 95/98.
0
RuchiCommented:
These GetFreeSpace and GetFreeSystemResources APIs were dropped and replaced with the GlobalMemoryStatus API for Win 32. That's what they said from the web.

Probably, you could not call those old APIs in Windows 95/98...

Okay, I am signing off... All the best.

0
ocsscottAuthor Commented:
well thanks for all the work.  Its not exactly what I want but I guess its as close as I'll get
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.