Home
Thursday, September 21, 2017
3:08:25 PM
Users online: 0   You are here >> Home > Programming

Forums | Programming Forums search
Forum FAQ
   
  1  
retro programming! VB6.0 counting total RAM
Sir_Substance 
23/6/08 2:46:01 PM
Immortal

im attempting to make a program that, among other things, can count the total amount of RAM on a computer. ive had a look through the system monitor control, and i cannot find a method of counting RAM using it.

the only other method i can think of is perhaps trying to tie in the directx diagnostic tool, but ive had little luck there either. has anyone tried doing this kind of thing in VB6.0 before?

-----
The Score: LogicPr0be, Twinair, Brains, TheDrake, Caelum, Cynic*, Hallowed, OracleX, Juggalo Scrub, Bastard Child.


kikz 
23/6/08 4:19:07 PM
Immortal

Who'd use vb6?

-----
Q6600 | 4Gb PC6400 | 2 x 500Gb RAID 0 | 19" Benq FP591 + 24" Samsung 245B + 19" Dell | 8800GTS 640 Mb + 8400GS 256 Mb | Gigabyte GA-P35-DS3P | Antec P182 | Corsair HX-620 | Thermalright 120 Extreme | Vista x64

Sir_Substance 
23/6/08 4:57:59 PM
Immortal

Quote by kikz
Who'd use vb6?



a programming class that didnt get the upgrade before they needed to start making the summative task.

-----
The Score: LogicPr0be, Twinair, Brains, TheDrake, Caelum, Cynic*, Hallowed, OracleX, Juggalo Scrub, Bastard Child.


kikz 
23/6/08 6:52:35 PM
Immortal

Quote by Sir_Substance
Quote by kikz
Who'd use vb6?



a programming class that didnt get the upgrade before they needed to start making the summative task.


It's funny because I still use VB6 every day :p~

Options:
(1) Create a really long string. Keep adding to it until you run out of memory. It's lengh is how much memory you have :p

(2) Make an API call to kernel32.dll.
 
Type MEMORYSTATUS
dwLength as Long
dwMemoryLoad as Long
dwTotalPhys as Long
dwAvailPhys as Long
dwTotalPageFile as Long
dwAvailPageFile as Long
dwTotalVirtual as Long
dwAvailVirtual as Long
End Type

Declare sub GlobalMemoryStatus Lib "kernel32" (lpBuffer as MEMORYSTATUS)

-----
Q6600 | 4Gb PC6400 | 2 x 500Gb RAID 0 | 19" Benq FP591 + 24" Samsung 245B + 19" Dell | 8800GTS 640 Mb + 8400GS 256 Mb | Gigabyte GA-P35-DS3P | Antec P182 | Corsair HX-620 | Thermalright 120 Extreme | Vista x64

Sir_Substance 
23/6/08 7:40:27 PM
Immortal

your telling me kernal32 is where the system info is retrieved from?

ive spent all day trying to track it down.

"dwLength as Long "

is that the same as "Dim Length as Long"?

-----
The Score: LogicPr0be, Twinair, Brains, TheDrake, Caelum, Cynic*, Hallowed, Juggalo Scrub, Bastard Child.


kikz 
23/6/08 8:57:28 PM
Immortal

I am telling you exactly that. Core windows API's do wonderful things. You can find out a world of info about your Windows PC through the Win32 APi's kernel32.dll, user32.dll etc.

http://en.wikipedia.org/wiki/Windows_API

That is the exact code you need to do what you want. You could rename dwLength to Spaghetti if you wanted to though. Don't need the Dim.


Edited by kikz: 23/6/2008 9:01:49 PM

-----
Q6600 | 4Gb PC6400 | 2 x 500Gb RAID 0 | 19" Benq FP591 + 24" Samsung 245B + 19" Dell | 8800GTS 640 Mb + 8400GS 256 Mb | Gigabyte GA-P35-DS3P | Antec P182 | Corsair HX-620 | Thermalright 120 Extreme | Vista x64

Sir_Substance 
23/6/08 9:03:30 PM
Immortal

well, im worried about this;


dwTotalPageFile as Long
dwAvailPageFile as Long
dwTotalVirtual as Long
dwAvailVirtual as Long

wont that count the virtual memory on the hard drive as well?


Edited by Sir_Substance: 23/6/2008 09:03:46 PM

-----
The Score: LogicPr0be, Twinair, Brains, TheDrake, Caelum, Cynic*, Hallowed, Juggalo Scrub, Bastard Child.


kikz 
24/6/08 6:49:32 AM
Immortal

Yes. What you do, is pass in the type variable and call the function. After the routine returns, the type will contain a whole bunch of information about the memory of your computer, not just the information you're after. You only need to grab the bits you're interested in.
 
Type MEMORYSTATUS
dwLength as Long
dwMemoryLoad as Long
dwTotalPhys as Long
dwAvailPhys as Long
dwTotalPageFile as Long
dwAvailPageFile as Long
dwTotalVirtual as Long
dwAvailVirtual as Long
End Type

Declare sub GlobalMemoryStatus Lib "kernel32" (lpBuffer as MEMORYSTATUS)

Private Sub btnGetMemory_Click()
Dim tMemStatus as MEMORYSTATUS

tMemStatus.dwLength = Len(tMemStatus)
GlobalMemorySTatus tMemStatus
' Display the total physical memory of the system
lblTotalPhy.Caption = tMemStatus.dwTotalPhys
End Sub

That code assumes you have a Form with a Button named btnGetMemory and a Label named lblTotalPhy. When the button is clicked with the mouse the label will contain the RAM on your computer.

http://msdn.microsoft.com/en-us/library/aa366589.aspx

(It's recommended to use the Ex version instead...)

-----
Q6600 | 4Gb PC6400 | 2 x 500Gb RAID 0 | 19" Benq FP591 + 24" Samsung 245B + 19" Dell | 8800GTS 640 Mb + 8400GS 256 Mb | Gigabyte GA-P35-DS3P | Antec P182 | Corsair HX-620 | Thermalright 120 Extreme | Vista x64

Sir_Substance 
24/6/08 10:40:01 AM
Immortal

ah, that makes more sense now.

perhaps a bit of background. im making a benchmarking program for my project. its gonna make the computer count from 1 to (arbitrary large number), copy a large file to the C:\ drive and record the peak write speed, and count the ram, then assign a completely pointless score based on those things, and rank multiple computers this way. the RAM was the only thing i hadn't figured out.

-----
The Score: LogicPr0be, Twinair, Brains, TheDrake, Caelum, Cynic*, Hallowed, Juggalo Scrub, Bastard Child.


Sir_Substance 
7/8/08 10:00:59 AM
Immortal

yay, got it working ^_^

-----
The Score: LogicPr0be, Twinair, Brains, TheDrake, Caelum, Cynic*, Hallowed, Juggalo Scrub, Bastard Child, Beefeater, Damo, Nickeax.
Quote by superfireydave
Let's play spot the drunk! ;D




kikz 
7/8/08 10:38:05 AM
Immortal

awesome :D

-----
Q6600 | 4Gb PC6400 | 2 x 500Gb RAID 0 + 2 x 320 Gb RAID 0 | 19" Benq FP591 + 24" Samsung 245B + 19" Dell | 8800GTS 640 Mb + 8400GS 256 Mb | Gigabyte GA-P35-DS3P | Antec P182 | Corsair HX-620 | Thermalright 120 Extreme | Vista x64

Amiga4eva 
7/8/08 6:44:19 PM
Hero
Titan


 

'Win32 Class Access
Private WbemServices As SWbemServices

Private Sub GetSystemInf()

Dim oResult As Object
Dim strPosRAM As String
Dim loc As New SWbemLocator

Set WbemServices = loc.ConnectServer(StrServer, "root\cimv2", StrUsernm, StrPasswd)
Set ColSWBemObjectSet = WbemServices.ExecQuery("Select * From Win32_ComputerSystem")

For Each oResult In ColSWBemObjectSet
strPosRAM = Int(oResult.TotalPhysicalMemory / 1024) & " KB"
Next

Call AvailRamCheck
Call CPULoad
Call ProcessCheck

End Sub



Why not just the above? I mean.. well, both ways work, but I find that an easier method :)


Edited by Amiga4eva: 8/8/2008 08:48:47 AM

-----
Mehing the Meh Meh.....

Sir_Substance 
9/8/08 8:30:53 PM
Immortal

mine went more along the lines of
 
Private Type MEMORYSTATUS
dwLength As Long
dwMemoryLoad As Long
dwTotalPhys As Long
dwAvailPhys As Long
dwTotalPageFile As Long
dwAvailPageFile As Long
dwTotalVirtual As Long
dwAvailVirtual As Long
End Type
Private Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As MEMORYSTATUS)



up top under "options explicit", and
 

Private Sub CommandUnRAM_Click()
Dim MemStats As MEMORYSTATUS
MemStats.dwLength = Len(MemStats)
GlobalMemoryStatus MemStats
MsgBox "your Ram size is " & (MemStats.dwTotalPhys) / 1000000 & " Mb", vbInformation, "Done!"
End Sub


down the bottom on the unsaved RAM test.

the saved RAM test is rather longer, since it includes all the other tests as well.

-----
The Score: LogicPr0be, Twinair, Brains, TheDrake, Caelum, Cynic*, Hallowed, Juggalo Scrub, Bastard Child, Beefeater, Damo, Nickeax.
Quote by superfireydave
Let's play spot the drunk! ;D




battlefield_gir 
10/8/08 3:26:21 PM
Guru

substance do you want the source code for my benchmarking project

-----
Minister for Education, Innovation, Science & Research.


R.I.P Josh Woods

Goth: Am I the only one who somehow swam through the wall of the vagina and got lost/stuck inside




"There is no probl

Sir_Substance 
18/8/08 10:23:30 AM
Immortal

awesome, program is handed in. ill send anyone a copy who wants it, just email me.

-----
The Score: LogicPr0be, Twinair, Brains, TheDrake, Caelum, Cynic*, Hallowed, Juggalo Scrub, Bastard Child, Beefeater, Damo, Nickeax.
Quote by superfireydave
Let's play spot the drunk! ;D




  1  
Forums | Programming