Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 1st, 2006, 12:47 AM
Registered User
Join Date: Jul 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Total Physical Memory mismatch

I have developed a VB app using visual basic 6. This will display the total physical memory in the system and other configuration details.

My system has 512 MB physical memory. If i open My Computer --> Properties, it shows 512 MB of RAM.

But my app shows only 511.01 MB. Why this difference ?

I am using the following Win32 API in my app for getting the total physical memory:

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

The function for getting the total physical memory is

Private Function GetMemory() As String
Dim BytesTotal As Double

GlobalMemoryStatus memInfo
BytesTotal = memInfo.dwTotalPhys
GetMemory = Format(CStr((BytesTotal / 1024) / 1024), "0.00")

End Function

Any help is highly appreciated. Please help me...

Thanks in advance.

Old August 1st, 2006, 12:10 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts

is it possible that it is just a rounding problem? Check the value of BytesTotal before converting it in a string
Old August 2nd, 2006, 03:25 PM
Friend of Wrox
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts

Just a shot in the dark:
    GetMemory = Format((BytesTotal / CDbl(1024)) / CDbl(1024), "0.00")
(the Cstr() is unnecessary, as Format() always converts to String.) This will ensure that the literal numbers are treated as doubles. Might address what Marco mentioned by preventing the quotient being converted to an integer.
Old April 10th, 2007, 07:08 PM
Registered User
Join Date: Apr 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts

Try this:
 int((BytesTotal + 1048575.0) / 1048576.0)

This will round the number up to the highest megabyte. The reason you are getting an unusual number for the physical memory is some of the memory is not accessible between the 640KB to 1024KB memory range. There may also be other memory ranges where the memory is not accessible for memory mapped I/O or ACPI memory ranges. Windows actually rounds up the value in the system properties dialog to make it look "right".

Similar Threads
Thread Thread Starter Forum Replies Last Post
physical address mateenmohd Classic ASP Basics 0 June 13th, 2007 09:24 AM
Logicial vs physical program structure darrenecm Visual C++ 2005 0 May 2nd, 2006 02:54 PM
Can we access physical location of objects? baburman Javascript How-To 6 January 24th, 2005 07:59 AM
Hi. Question regarding physical paths in XSL. vlad027 XSLT 0 June 26th, 2003 04:33 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.