samedi 10 décembre 2016

What is wrong with my powershell script?

The quest: Database with license plate and date for tire repair. I write a time like 12:30, and then the script checks if the time is good or not. Its good if after and before 30 minutes, so like now 12-13 there isn't any date in the database. If there is, then the time isn't good, so the script have to search a good date for me. i tryed to check line by line minute per minute. after if the help variable didn't changed then it's good, but if it did, then make a random time, to check, but somehow that random time went to infinity cycle so it stops check it. Any ideas what i screw up? :/

database:
ABC-145 8:30
BDE-540 9:45
EDS-598 10:30
SDF-478 11:30
HUT-434 12:15
JEC-238 13:15
ASD-325 14:00
VRA-123 16:15
HGV-456 18:00

$file=Get-Content Desktop/database.txt
[datetime]$time=Read-Host "Time for date?"
$start=$time
$check=$time
$help=0
echo $time
foreach ($_ in $file){ #here i check if the date is free
$out = $_.split()
while($true){ #until i found a good time
for($i=0;$i -lt 30;$i++){ #check the next half hour if good
if($time-eq $out[1]){ 
    $help=1
}
$time=$time.AddMinutes(1)
}
for($i=0;$i -lt 60;$i++){ #back check the half hour
if($time-eq $out[1]){
    $help=1
}
$time=$time.AddMinutes(-1)
}
if($help-eq 0){
break
}else{
    $hour=Get-Random -Minimum 8 -Maximum 20
    $minute=Get-Random -Minimum 0 -Maximum 59
    $start="$ora`:$perc" 
    $time=$start
   #echo $time
}
}
}
if($start-ne $check){
echo "There wasnt a free date, but there is a free spot at "+$start
}else{
echo "This is free date"
}




Aucun commentaire:

Enregistrer un commentaire