Solved

RAM Size

Posted on 2010-08-29
8
729 Views
Last Modified: 2012-05-10
Hi

How can i get RAM size in GB with the following code (i really wanted to be in this format fx. 4GB or 2GB etc..)

i'm using VB in Visual Studio 2010
TextBox3.Text = My.Computer.Info.TotalPhysicalMemory

Open in new window

0
Comment
Question by:ms-pro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
8 Comments
 
LVL 7

Author Comment

by:ms-pro
ID: 33553776
sorry and thank you
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 33553825
I use StrFormatByteSizeW , but you can always make your own routine that calculates this information with basic math.
Imports System.Runtime.InteropServices
Imports System.Text

Public Class Form1
    <DllImport("shlwapi.dll", SetLasterror:=True, CharSet:=CharSet.Unicode)> _
    Private Shared Function StrFormatByteSize(ByVal qdw As Long, ByVal pszBuf As StringBuilder, ByVal cchBuf As Integer) As IntPtr
    End Function
    Public Shared Function FormatByteSize(ByVal bytes As Long) As String
        Dim fbs As New StringBuilder(64)
        StrFormatByteSize(bytes, fbs, fbs.Capacity)
        Return fbs.ToString
    End Function
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Debug.Print(FormatByteSize(My.Computer.Info.TotalPhysicalMemory))
    End Sub
End Class

Open in new window

0
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33554600
It is:

TextBox3.Text = My.Computer.Info.TotalPhysicalMemory \ (1024 * 1024 * 1024)

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Accepted Solution

by:
Zhaolai earned 125 total points
ID: 33554612
Or if you want to display decimal, try this:

       TextBox3.Text = (My.Computer.Info.TotalPhysicalMemory / (1024 * 1024 * 1024)).ToString("#.00")

which will display 2 decimal points, like 3.37.
0
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33554619
Or even this simpler code:

TextBox3.Text = My.Computer.Info.TotalPhysicalMemory \ 2 ^ 30
0
 
LVL 7

Author Comment

by:ms-pro
ID: 33555041
ye of course / (1024 * 1024 * 1024)).ToString("#.00") thank you man.
 
But how can i get the Installed Memory and not just the usable number of the ran total?
0
 
LVL 7

Author Closing Comment

by:ms-pro
ID: 33555047
Thanks
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question