#192547 - 2009-02-26 03:33 AM
Re: Hardware inventory
[Re: NTDOC]
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
i'm always around, but usually on facebook... one must keep up with the times
|
|
Top
|
|
|
|
#192551 - 2009-02-26 06:44 AM
Re: Hardware inventory
[Re: Radimus]
|
Ashpoint
Starting to like KiXtart
Registered: 1999-08-27
Posts: 192
Loc: Sydney, NSW, Australia
|
Hi Guys...
Playing with the "seed" code, I'm using the following separated lines in my routine:
$rc = WriteLine(1, "Physical Memory: " + $wmiObj.TotalPhysicalMemory + @CRLF )
And
$rc = WriteLine(1, "Hard Drive: " + $wmiObj.Size + @CRLF)
And
$rc = WriteLine(1, "Drive Space: " + $wmiObj.FreeSpace + @CRLF)
The code returns long numbers similar to the following (useless) values: Physical Memory: 2146713600 Hard Drive: 160039239680 Drive Space: 105328513024
How can I make these values look like: Physical Memory: 2.1mb Hard Drive: 160mb Drive Space: 90mb etc?
I tried doing:
$rc = WriteLine(1, "Hard Drive: " + VAL($wmiObj.Size)/1000000000 + @CRLF)
but that wasn't useful.
|
|
Top
|
|
|
|
#192553 - 2009-02-26 10:19 AM
Re: Hardware inventory
[Re: Ashpoint]
|
Lonkero
KiX Master Guru
   
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
|
|
Top
|
|
|
|
#192627 - 2009-02-27 06:13 AM
Re: Hardware inventory
[Re: Glenn Barnas]
|
Ashpoint
Starting to like KiXtart
Registered: 1999-08-27
Posts: 192
Loc: Sydney, NSW, Australia
|
Hi Glen...
Mark me as a bit dumb.
I created TEST1.Kix as follows:
$x = '160039239680'
? $x
? VAL($x)
I got 160039239680 and 1125449728
That surprised me!
So, put me out of my misery and explain (please).
Michael
|
|
Top
|
|
|
|
#192640 - 2009-02-27 01:11 PM
Re: Hardware inventory
[Re: Ashpoint]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
|
The function you were using returns the value as a string, so in my example, $X is a string - the value has quotes around it.
Val() converts strings to numbers, but is limited to Integers. What you are seeing is the result of "wrap" when the excess bits are dropped.
Because the size of your value exceeds the limit of Integer data, you need to employ double-precision math. Some languages have other (or even several) class names such as Real, Float, Single.. these simply reflect the maximum range that can be represented. The higher precision employed, the more data memory consumed, so languages like C have several options. Kix just offers Double and Integer.
So - you need to convert the string containing a large value to a double-precision value first. You need to recognize the size of your data and plan for it in the code (or adapt once you see the strange values!) One method is to use the CDbl() function, and another common "shortcut" is to multiply by 1.0, but the multiplier must come first - as so:$x = '160039239680'
$x ?
VAL($x) ?
CDbl($X) ?
1.0 * $X ? Also, it's considered a matter of preference, but.. "?" represents a CR/LF sequence - same as @CRLF. It is not a shortcut for a "print" statement as in old versions of BASIC. If you place the "?" in front of your output statements, you will always start with a blank line and leave the cursor at the end of the output. Try this:CLS
For $X = 1 to 24
? $X
Next
Get $X Where is the #1 displayed? Where is the cursor? TryCLS
For $X = 1 to 24
$X ?
Next
Get $X Now where is the #1 displayed? See how the leading "?" offsets the output? This can affect screen formatting as well as file data. In fact, not having a closing CRLF could affect some file-based applications. The CRLF sequence should follow your data instead of preceeding it.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#193691 - 2009-05-05 10:46 PM
Re: Hardware inventory
[Re: Radimus]
|
River911
Just in Town
Registered: 2007-03-29
Posts: 1
|
A little lost here on your Hardware SQL WMI queries. Is there a UDF that i am supposed to reference.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 657 anonymous users online.
|
|
|