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
Solved

RAM Size

Posted on 2010-08-29
8
725 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
  • 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
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…

790 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