The_Lorax Posted September 13, 2005 Share Posted September 13, 2005 Hello, I have a one dimentional array of varying size that contains the following data: name,time stamp for example: Bob,13.00 Anne,14:00 Bill,15:00 Bob,16:00 I want to search the array for multiple entries with the same name. If a person has 10 or more entries in the array I want to run an event. Is there a function to do this or will I need to try and code my own? I'm fairly new to AutoIt and programming and I'm not sure how to proceed. Thanks for your help! Link to comment Share on other sites More sharing options...
/dev/null Posted September 13, 2005 Share Posted September 13, 2005 I want to search the array for multiple entries with the same name. If a person has 10 or more entries in the array I want to run an event.Is there a function to do this or will I need to try and code my own?I'm fairly new to AutoIt and programming and I'm not sure how to proceed.O.K. first you should sort the array (_ArraySort). You will then have something like this:Bob, 11:00Bob, 12:00Bob, 13:00Anne,09:00Anne,10:00Anne,13:00To find multiple entries for Bob, Anne, etc. just loop through the array and count the number of occurances for each person. If the count exceeds 10, then trigger some action.CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
The_Lorax Posted September 13, 2005 Author Share Posted September 13, 2005 The thing making this hard is: 1. the array will vary in size. 2. I don't know the names of the people that are going to be placed in the array. I'm really stumped about how to check if the same name appears in the list 6 times or more. it would be easy If I knew the names in advance - i'd just have a loop with a ton of if... then statements. Link to comment Share on other sites More sharing options...
/dev/null Posted September 13, 2005 Share Posted September 13, 2005 (edited) The thing making this hard is:1. the array will vary in size.2. I don't know the names of the people that are going to be placed in the array.No problem.1.) Ubound() will give you the size of an array.2.) If you only need the information, that any name occurs serveral times in the array, you could do this:const $MAXCOUNT = 10 $name = $array[0][0]; [n][0] == name , [n][1] == "time" $occurance = 0 for $n = 1 to Ubound($array) if $array[$n][0] = $name then $occurance = $occurance +1 if $occurance >= $MAXCOUNT then do_something($name,$occurance) endif else $name = $array[$n][0] $occurance = 0 endif next func do_something($name,$howoften) msgbox(0,"INFO", "Name : " & $name & " How often: " & $howoften) endfuncCheersKurt Edited September 13, 2005 by /dev/null __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
GaryFrost Posted September 13, 2005 Share Posted September 13, 2005 (edited) No problem.1.) Ubound() will give you the size of an array.2.) If you only need the information, that any name occurs serveral times in the array, you could do this:const $MAXCOUNT = 10 $name = $array[0][0]; [n][0] == name , [n][1] == "time" $occurance = 0 for $n = 1 to Ubound($array) if $array[$n][0] = $name then $occurance = $occurance +1 if $occurance >= $MAXCOUNT then do_something($name,$occurance) endif else $name = $array[$n][0] $occurance = 0 endif next func do_something($name,$howoften) msgbox(0,"INFO", "Name : " & $name & " How often: " & $howoften) endfuncCheersKurt<{POST_SNAPBACK}>The user said 1 dimensional array, this would require splitting the stringswith some minor changes this can be done with 1 dimensional arrayfor would be from 0 to ubound($array) - 1$name would have to be stringmid($array[$n],1,stringinstr($array[$n],",") - 1)or something thereof Edited September 13, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference.  Link to comment Share on other sites More sharing options...
/dev/null Posted September 13, 2005 Share Posted September 13, 2005 (edited) The user said 1 dimensional array, this would require splitting the stringsYep, you're right. I guess I read over that. But, as you said, some minor changes will do the trick. Here we go....const $MAXCOUNT = 10 const $DELIMITER = "," $name = get_name($array[0]) $occurance = 0 for $n = 1 to Ubound($array)-1 if get_name($array[$n]) = $name then $occurance = $occurance +1 if $occurance >= $MAXCOUNT then do_something($name,$occurance) endif else $name = get_name($array[$n]) $occurance = 0 endif next func do_something($name,$howoften) msgbox(0,"INFO", "Name : " & $name & " How often: " & $howoften) endfunc func get_name($text) local $items = StringSplit($text,$DELIMITER) return $items[1] endfunc func get_time($text) local $items = StringSplit($text,$DELIMITER) return $items[2] endfuncInstead of using $DELIMITER as a global variable, we could also add a param to the functions.CheersKurt Edited September 13, 2005 by /dev/null __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
The_Lorax Posted September 13, 2005 Author Share Posted September 13, 2005 I modified your code /dev /null to work with a one dimentional array. I used this script to test it: const $MAXCOUNT = 5 $occurance = 0 dim $array[10] $array[0] = "Bob,date" $array[1] = "Sue,date" $array[2] = "Bob,date" $array[3] = "Sue,date" $array[4] = "Bob,date" $array[5] = "Sue,date" $array[6] = "Bob,date" $array[7] = "Sue,date" $array[8] = "Bob,date" $array[9] = "Sue,date" $name = stringmid($array[0],1,stringinstr($array[0],",") - 1) for $n = 1 to Ubound($array)-1 $currentstring = stringmid($array[$n],1,stringinstr($array[$n],",")-1) if $currentstring = $name then $occurance = $occurance +1 if $occurance >= $MAXCOUNT then do_something($name,$occurance) endif else $name = stringmid($array[$n],1,stringinstr($array[$n],",")-1) $occurance = 0 endif next func do_something($name,$howoften) msgbox(0,"INFO", "Name : " & $name & " How often: " & $howoften) endfunc Currently the code will only add +1 to occurance if the array directly after array[n] has an identical name. I think I'm going to need to include a nested loop in here to check all of them. It's 11pm, I can't concentrate so i'm going to go make some dinner and think about how it could be done. Thanks for your help so far Link to comment Share on other sites More sharing options...
The_Lorax Posted September 13, 2005 Author Share Posted September 13, 2005 ignore that last post.. just realised I forgot to add an _ArraySort! I'll go try that now. should work! Link to comment Share on other sites More sharing options...
/dev/null Posted September 13, 2005 Share Posted September 13, 2005 ignore that last post.. just realised I forgot to add an _ArraySort!I'll go try that now. should work!<{POST_SNAPBACK}>As you said, add _ArraySort() and it will work. CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * 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