Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old August 1st, 2006, 01:47 AM
Registered User
 
Join Date: Jul 2006
Location: , , .
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
Dim memInfo As MEMORYSTATUS

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.

Reply With Quote
  #2 (permalink)  
Old August 1st, 2006, 01:10 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

is it possible that it is just a rounding problem? Check the value of BytesTotal before converting it in a string
Reply With Quote
  #3 (permalink)  
Old August 2nd, 2006, 04:25 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Just a shot in the dark:
Try
Code:
    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.
Reply With Quote
  #4 (permalink)  
Old April 10th, 2007, 08:08 PM
Registered User
 
Join Date: Apr 2007
Location: , , Canada.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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".

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
physical address mateenmohd Classic ASP Basics 0 June 13th, 2007 10:24 AM
Logicial vs physical program structure darrenecm Visual C++ 2005 0 May 2nd, 2006 03: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 05:33 PM



All times are GMT -4. The time now is 04:48 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.