mIRC Home    About    Download    Register    News    Help

Print Thread
#211591 24/04/09 06:03 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
How can i return free in prosent from the code below? been trying a while, but can't get it right, it return 340%, and that is apparently wrong.
Code:
alias diskz {
  var %to = $bytes($diskz_(total),3).suf
  var %ff = $bytes($diskz_(free),3).suf
  echo -a -> Total: $bytes($diskz_(total),3).suf - Free: $bytes($diskz_(free),3).suf $+($chr(40),$round($calc(%ff / %to *100),1),$chr(37),$chr(41)))
}


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
sparta #211592 24/04/09 06:59 PM
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Apparently?



- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
argv0 #211593 24/04/09 07:00 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
as you see it's wrong


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
sparta #211594 24/04/09 07:02 PM
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
echo the output of %to and %ff and you'll see you're trying to divide letters. (ex: 300MB / 500MB) -- Don't use .suf with math.

As a sidenote, "you're" wrong, not "it".


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
argv0 #211595 24/04/09 09:22 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
$gettok(763GB,1,71) remove GB from it, but still i get the wrong value, at lest i think it's the wrong answer (value) i get.
-> Total: 763GB - Free: 341GB -> (44.7%)
Code:
alias diskz {
  var %to = $bytes($diskz_(total),3).suf
  var %ff = $bytes($diskz_(free),3).suf
   echo -a -> Total: $bytes($diskz_(total),3).suf - Free: $bytes($diskz_(free),3).suf -> $+($chr(40),$round($calc($gettok(%ff,1,71) / $gettok(%to,1,71) *100),1),$chr(37),$chr(41)))
}

alias diskz_ {
  var %r = 0,%i = $disk(0)
  while (%i) {
    if ($istok(fixed removable remote,$disk(%i).type,32)) && ($disk(%i).type != removable) {
      if ($1 == free) { inc %r $disk(%i).free }
      else { inc %r $disk(%i).size }
    }
    dec %i
  }
  return %r
}


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
sparta #211596 24/04/09 09:33 PM
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
What part of "don't use .suf with math" didn't you get? Also, 341/763.. have you tried this on a calculator?


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
sparta #211597 24/04/09 09:37 PM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Two things that make me wonder:
- why do you check for $istok(removable), and then do an "&& (!= removable)" ?
- why do set $bytes().suf in variables, instead of the pure bytes integer? You can $calc your percentages with the %stored_integers, and return the sizes with $bytes(%stored_integers).suf
Code:
alias diskz {
  var %total = 0, %free = 0, %i = 1
  while ($disk(%i).type) {
    if ($istok(fixed remote,$v1,32)) {
      inc %total $disk(%i).size
      inc %free $disk(%i).free
    }
    inc %i
  }
  echo -a -> Total: $bytes(%total).suf - Free: $bytes(%free).suf -> $+($chr(40),$round($calc(%free / %total * 100),2),$chr(37),$chr(41)) 
}


Last edited by Horstl; 24/04/09 09:46 PM.
Horstl #211598 24/04/09 09:58 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
$istok(removable) <- i belived should halt the script if the drive was a removable one, but it didn't, i still get the sound from my disk drive, and it was irritating when i have to hear that noice every time i using popups in the channel. When i added ($disk(%i).type != removable) it stopped to make the sound, and for the variables i just used them for testing, i rewrite every code after i got a working one, and i can clean it up a bit smile


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
sparta #211599 24/04/09 10:21 PM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Anyway you shouldn't use preformatted values for calculations. $gettok(,71) is not only unnecessary, it will make your script fail if a value is e.g. MB or TB... smirk


Link Copied to Clipboard