Page 2 of 2 <12
Topic Options
#192547 - 2009-02-26 03:33 AM Re: Hardware inventory [Re: NTDOC]
Radimus Moderator Offline
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
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#192551 - 2009-02-26 06:44 AM Re: Hardware inventory [Re: Radimus]
Ashpoint Offline
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:

 Code:
$rc = WriteLine(1, "Physical Memory: " + $wmiObj.TotalPhysicalMemory + @CRLF )

And
 Code:
$rc = WriteLine(1, "Hard Drive: " + $wmiObj.Size + @CRLF)

And
 Code:
$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:
 Code:
$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 Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
try any of these:
meminfo() - http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=83843
meminfo2() - http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=113155
memory() - http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=134637
physicalMemoryInfo() - http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=176025
_________________________
!

download KiXnet

Top
#192559 - 2009-02-26 01:17 PM Re: Hardware inventory [Re: Lonkero]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Try this:
 Code:
$X = '160039239680'
$X ?
Val($X) ?

Does the result surprise you?

Why do you think you got the answers you did?

This is a common issue in most languages.. you might recognize the problem yourself and find the solution in the manual. If not, reply and I'll explain further..

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#192627 - 2009-02-27 06:13 AM Re: Hardware inventory [Re: Glenn Barnas]
Ashpoint Offline
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:

 Code:
$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
#192639 - 2009-02-27 01:09 PM Re: Hardware inventory [Re: Ashpoint]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
before he respons, you could search the manual for "-21"
_________________________
!

download KiXnet

Top
#192640 - 2009-02-27 01:11 PM Re: Hardware inventory [Re: Ashpoint]
Glenn Barnas Administrator Offline
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:
 Code:
$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:
 Code:
CLS
For $X = 1 to 24
  ? $X
Next
Get $X
Where is the #1 displayed? Where is the cursor? Try
 Code:
CLS
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! \:D

Top
#193691 - 2009-05-05 10:46 PM Re: Hardware inventory [Re: Radimus]
River911 Offline
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
Page 2 of 2 <12


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 657 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.067 seconds in which 0.033 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org