Solved

RAM Size

Posted on 2010-08-29
8
726 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
Independent Software Vendors: 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 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