Solved

RAM Size

Posted on 2010-08-29
8
719 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now