Page 1 of 1 1
Topic Options
#201419 - 2011-01-19 10:58 AM unable to get the int value...
matzas Offline
Fresh Scripter

Registered: 2006-10-15
Posts: 12
hi,

i use the folowing script for getting the disk size + free size.

 Code:
$computer  = "."
$objWMIService = GetObject( "winmgmts://" + $computer + "/root/CIMV2" )
  $colDisks = $objWMIService.ExecQuery("Select * FROM Win32_LogicalDisk")
For Each $objDisk in $colDisks
   Select
      Case $objDisk.DriveType = "2"
        $Devtype = "floppy drive." 
      Case $objDisk.DriveType = "3"
        $DevType = "hard drive."
	? " "
        ? " Drive: " + $objDisk.Name
        ? " Device type:................" + $DevType
	? " File System:................" + $objDisk.FileSystem
	$dfs=CInt ($objDisk.FreeSpace)
        $dds=Cint ($objDisk.Size)
	$sss= $dds - $dfs
        ? " Free Space:................." + $objDisk.FreeSpace + " / " + $objDisk.Size
	? "amir : " + $sss + " - " + $dfs + " - " + $dds
	? " "

      Case $objDisk.DriveType = "4"
        $DevType = "mapped network drive."
      Case $objDisk.DriveType = "5"
        $DevType = "CD or DVD drive."
		? " "
        ? " Drive: " + $objDisk.Name
        ? " Device type:................" + $DevType
	    ? " "	  
      Case 1
        $DevType = "Unknown"
   EndSelect


the result i get:

Drive: C:
Device type:................hard drive.
File System:................NTFS
Free Space:.................229501284352 / 319697539072
amir : 0 - 2147483647 - 2147483647

why i get the number 2147483647 instead of: 229501284352 ??
how can i get the real numbers at the free space?? and do some math on them??

thanks...


Edited by matzas (2011-01-19 11:19 AM)

Top
#201421 - 2011-01-19 01:06 PM Re: unable to get the int value... [Re: matzas]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
Hi Matzas,

Well, I would guess since you are rounding the numbers to an integer when setting $dfs and $dds. What happens if you remove the cint from each line? Does $sss become 90196254720?

Top
#201422 - 2011-01-19 02:39 PM Re: unable to get the int value... [Re: BradV]
matzas Offline
Fresh Scripter

Registered: 2006-10-15
Posts: 12
thanks for your answer....
when i remove the cint from both of the lines i get an error in the kix script...

when i remark the line "$sss= $dds - $dfs" i see the real value...

the result are:
Drive: C:
Device type:................hard drive.
File System:................NTFS
Free Space:.................213 GB
Free Space:.................229491920896 / 319697539072
amir : - 229491920896 - 319697539072

but i can't do any math activities...

how do i asure that the values in $dds and in $dfs are numbers and not strings?.. (is that the problem??)


please help.

thanks.,


Edited by matzas (2011-01-19 02:41 PM)

Top
#201423 - 2011-01-19 02:52 PM Re: unable to get the int value... [Re: matzas]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
No, the problem is that you are exceeding the maximum value that KiXtart can handle. The numbers are too big.

One simple solution is just to drop the last 3 digits from the string to scale the number as kilobytes (give or take) and then convert to numeric. This is often close enough.

This problem comes up with disk drive sizes quite regularly, if you search the forums you will find other suggestions for workarounds.

Top
Page 1 of 1 1


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

Who's Online
2 registered (morganw, mole) and 414 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.027 seconds in which 0.011 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