Solved

RAM Size

Posted on 2010-08-29
8
717 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How to get a file from SqlServer DB 4 29
Vb.Net Menu 1 22
Asp/Net Validation date Issue 9 38
System32Int Error 8 44
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

10 Experts available now in Live!

Get 1:1 Help Now