Teldin Posted March 26, 2007 Share Posted March 26, 2007 (edited) This function is part of an app that checks our datebase for current logged in users. We use M$ Navision and have a limited number of licences so when the available licences get low, I want to kill idle sessions. Func _IdleUsers() $avail = 37 - $count ;$count is current number of users ;MsgBox(1,"THIS MANY LICENCES ARE FREE",$avail) if $avail < 6 then $needed = 6 - $avail ;MsgBox(1,"NEEDED TEST",$needed) While $needed < 6 for $k = _ArrayMax ($lst_qry,1) to $needed ;arraymax get the longest ide users ;_SQLCommand("DB1", "Kill " & $as_ColFilter[2], 1000) $needed = $needed+1 Next WEnd Else EndIf EndFunc I think it's something wrong with my for loop. It always loops longer then needed. I'm thinking I'm making an obvious mistake but can't see it. Any ideas? Edit typo Edited March 26, 2007 by Teldin Link to comment Share on other sites More sharing options...
Teldin Posted March 26, 2007 Author Share Posted March 26, 2007 I may have figured it out. I think it should be: $needed = $needed - 1 Instead of + 1 Link to comment Share on other sites More sharing options...
SadBunny Posted March 26, 2007 Share Posted March 26, 2007 (edited) I may have figured it out. I think it should be: $needed = $needed - 1 Instead of + 1 Well that should do something, since as you kill off idle users, the amount of needed killoffs ofcourse decreases instead of increases. But didn't you by any chance mean your code to be something like: Func _IdleUsers() While 37 - $count < 6 ;$count is current number of users; this loops while less then 6 accounts are free $index_ToKill = _ArrayMax($lst_qry, 1) ; arraymax get the longest ide user ; give your kill command to kill the one found in $index_ToKill $count -= 1 ; <-- this is exactly [b]$count = $count - 1[/b], only shorter. [b]+= -= *= /=[/b] and [b]&=[/b] are good. WEnd EndFunc As far as I can see, this does exactly the same but is way shorter and easier to follow. Edited March 26, 2007 by SadBunny Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now