Here's the latest UDF that I use. It's trimmed down a bit from the original, but still examines all of the appropriate bytes in the .Translated key, and uses a modified Hex conversion routine. Using Val('&' + $hex) can return negatives, probably due to a limitation of the Val() function.

[Glenn, I updated your post because your function name was missing, also updated some missing entries for the UDF header NTDOC]

;;FUNCTION		Memory() 

;;
;;AUTHOR Glenn Barnas / FRIT-EROC
;;
;;ACTION Returns the amount of Physical RAM in a local or remote 32GB system
;;
;;SYNTAX Memory([system])
;;
;;VERSION 1.0
;;
;;DATE 2005/02/25
;;
;;DATE REVISED
;;
;;PARAMETERS System - OPTIONAL - name of system to query. Default is local system
;;
;;REMARKS Returns RAM size using registry value
;; Returns @ERROR on registry read failure, or 13/"Data is Invalid" if null
;;
;;RETURNS Installed Physical RAM (in Megabytes)
;;
;;DEPENDENCIES None
;;
;;TESTED WITH WinNT, Win2K, WinXP, Win2K3
;; Tested with up to 6G of RAM
;;
;;EXAMPLES $RAM = Memory('ThatPC')
;;

Function Memory(Optional $System)

dim $, $MemKey, $HexDmp, $Pointer, $Counter, $Start, $Hex, $HVal, $Error, $Hex2Dec
$Memory = 0.0

; Insure $System has "\\System\" format if it is specified
If $System <> ''
$System = '\\' + Join(Split($System, '\'), '', 3) + '\'
EndIf

; Get the memory value from the registry
$MemKey = $System + 'HKEY_LOCAL_MACHINE\hardware\resourcemap\system resources\physical memory'
$HexDmp = ReadValue($MemKey, '.Translated')

; Check for invalid read and Return
If Len($HexDmp) = 0 Or @ERROR
$Memory = 0 ; return 0 Mbytes
$Error = IIf(@ERROR, @ERROR, 13) ; Return "Data is Invalid" if no error but data is blank
Exit $Error
EndIf

; Resequence the bytes in the HexDump, starting in the 65th position,
; and take 8 bytes every 32 bytes for the total memory amount, sum the values
For $Start = 65 to Len($HexDmp) step 32
$Hex = SubStr($HexDmp, $Start+6, 2)
+ SubStr($HexDmp, $Start+4, 2)
+ SubStr($HexDmp, $Start+2, 2)
+ SubStr($HexDmp, $Start, 2)
$Hex2Dec = 0.0
; Simply taking the Val($Hex) can return negatives for values
While $Hex
$Hex2Dec = 16.0 * $Hex2Dec + Val('&' + Left($Hex,1))
$Hex = SubStr($Hex ,2)
Loop
$Memory = $Memory + CDbl($Hex2Dec) / 1024
Next

; Reduce to meg value, add the lowest 640K that isn't referenced in the HexDump
$Memory = CInt(($Memory + 648) / 1024)

EndFunction


The section:
; Simply taking the Val($Hex) can return negatives for values
While $Hex
$Hex2Dec = 16.0 * $Hex2Dec + Val('&' + Left($Hex,1))
$Hex = SubStr($Hex ,2)
Loop
$Memory = $Memory + CDbl($Hex2Dec) / 1024

Could be replaced with:
$Memory = $Memory + CDbl(Val('&'+$Hex)) / 1024

If the "Val('&'+$Hex)" didn't return negative numbers for certain values (above 2M)


Edited by NTDOC (2005-02-24 08:35 PM)
_________________________
Actually I am a Rocket Scientist! \:D