CyberGlitch Posted April 29, 2004 Share Posted April 29, 2004 I've got a list of employees and their family. I started to scrip this and then got stuck when it comes to same names and wondering if anyways else can think of a different way to do this. This is the format I have for files Employee:Spouse:Children Brian Robert Chris Jeff Brian:Kristy Brian:Kristy:Katie Brian:Kristy:Cloe Robert:Racheal Robert:Racheal:Tom Jeff:April Jeff:April:Katie I would like to output this to something that would show for example. ID:NAME 1:Brian 2:Kristy 3:Katie 4:Cloe 10:Jeff 11:April 12:Katie PARENTID:NAME 1:Brian 1:Kristy 2:Katie 2:Cloe 5:Jeff 5:April 11:Katie This way I can generate my webpages by looking at the parent ids different subject anways. Does this make sense? What I originaly did was write the line to an array and use the last variable + a number and write this to a file so everyone has an ID but that will not work because of multiple names. Link to comment Share on other sites More sharing options...
scriptkitty Posted April 29, 2004 Share Posted April 29, 2004 (edited) it can be done, but for me this was a bad way to do the info in the first place, if you wanted to have the data in there, it would have been easier to store it like this:Employee:Spouse:ChildrenChrisBrian:Kristy:Katie|CloeRobert:Racheal:TomJeff:April:KatieChildren would have been seperated by the pipes. Well back to the solution.First I would condence the list to a single line list, like the one I have shown.Then you can seperated the line by : and the first element will be the employee name every time, the second will be the spouce, and the third will be the children.You can have it export any way you like after that, with say the line numbers to be your ID#.I assume you don't have anyone whos spouse has passed away and you list children. if so they should have been listed like:Robert::TomAnyway back to my version of the solution:First grab each name of the array, and then check the array for repeats, when one is found, add the spouce name to it, when the spouce and employee match, add each child and a |once you get the names in a one line list, you can have autoit create the web pages, or even use PHP to do it.If you would like more help say so:Not sure if you wanted a solution or only a hint on how to do it. Oh and I have no idea what you were doing in the output window, why would Brian have brian's ID? Edited April 29, 2004 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
CyberGlitch Posted April 29, 2004 Author Share Posted April 29, 2004 Well I know it was stored crappy to begin with and I can't help that, whats done is done now I get to clean someone elses mess. Gotta work with what I have. I don't know about deaths but there are some single parents that look like Ken:James:Taylor so I assume that deaths were either left in or compeltly taken out. I guess Brian wouldn't have Brians ID, that doesn't make sense. Hints are fine as the only way to learn is by doing and I am still learning. Solutions are welcome though as always Link to comment Share on other sites More sharing options...
scriptkitty Posted April 29, 2004 Share Posted April 29, 2004 ok, first sort the list so it looks like:BrianBrian:KristyBrian:Kristy:CloeBrian:Kristy:KatieChrisJeffJeff:AprilJeff:April:KatieRobertRobert:RachealRobert:Racheal:Tomnow you can quickly parse each line, Compare the next line to the previous one, if the first part matches, disregaurd and place this data into memory and read the next line, if it doesn't match the next line, write the line in memory and put the line you are reading into memory. That will take care of everything but children.For children, you do the same, but only use the first two items, and keep adding the childrens names into memory. Nice thing is this data has no way for kids to not have parents.So what you will end up with will be a list that I was talking about, and that can be parsed very easily.If it sounds too complex, I will write up the solution, and all you will need to do is sort the file first. ( I am too lazy to sort it myself )Not sure on how autoit savvy you are. AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
CyberGlitch Posted April 29, 2004 Author Share Posted April 29, 2004 Ok, I think I may be over my head with this then. What you said makes sense for the post part but I can't think of the scripting. Link to comment Share on other sites More sharing options...
scriptkitty Posted April 29, 2004 Share Posted April 29, 2004 (edited) Ok, here ya go then, if you can sort your file that is: I tested with this data, to show more kids in case. Brian Brian:Kristy Brian:Kristy:Cloe Brian:Kristy:Katie Chris Fred Fred:Jan Fred:Jan:Jane Fred:Jan:Janey Fred:Jan:Jim Fred:Jan:Jimbo Fred:Jan:Jimmy Jeff Jeff:April Jeff:April:Katie Robert Robert:Racheal Robert:Racheal:Tomhere is the code: $filename="emp.txt" $file=StringReplace(Fileread($filename,FileGetSize($filename)),@LF,"")&@CR $lines=StringSplit($file,@CR) FileDelete("output.txt") $mem=$lines[1]; start with first line in memory For $i=2 To $lines[0] $temp1=StringSplit($lines[$i],":") $temp2=StringSplit($mem,":") If $temp1[1]=$temp2[1] Then If $temp2[0]=3 Then $mem=$lines[$i]&"|"&$temp2[3] Else $mem=$lines[$i] EndIf Else FileWriteLine("output.txt",$mem) $mem=$lines[$i] EndIf Next and it outputs a file like this: Brian:Kristy:Katie|Cloe Chris Fred:Jan:Jimmy|Jimbo|Jim|Janey|Jane Jeff:April:Katie Robert:Racheal:TomPS: it also works if they have no kids. I added an extra @cr to the file so that it will add one more line to the array and compare that to the previous line. If you have more than one employee with the same name, you will need to add more into the compare, or change his name, say Jim_B and Jim_A it will be easy to spot once you get the file sorted. it would only be if that employee had no spouce, I could do it for you if needed... If you need help parsing the new data, it is pretty simple to show you how to StringSplit the Empl,Spouce, and all the children if they have any. PSS: I was too lazy to sort the kids back, so they are in reverse alphabetical order. Only the kids though. Edited April 29, 2004 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
CyberGlitch Posted April 29, 2004 Author Share Posted April 29, 2004 (edited) Apreciate the help but I think we are doing different things or I didn't explain myself clearly enough. Basically I'm trying to get the list so I can import it into an access database to work with my current ASP coding to list the families. What I need is to generate a number for each unique individual plus an id that links them back to the name before them. Some strings seem to have a long list and I need to ask what these are for but it looks like more of the family. For example. Ken:Barbara:Kevin Ken:Barbara:Tom:Jenny:Richard I'm simply looking to link each of the names together with numbers to show Ken -Barbara --Tom | Keven ---Jenny ----Richard Richards parentid points to Jenny, Jennys parentid points to Tom, Toms and Kevins parentid points to Barbara, and Barbara points to Ken. My table will require ID, ParentID, Name Example: 1,0,Ken 2,1,Barbara 3,2,Kevin 4,2,Tom ^___ would be my ideal output Think of this more as webstore categories with people as thats how they will be displayed once done. Edited April 29, 2004 by CyberGlitch Link to comment Share on other sites More sharing options...
scriptkitty Posted April 29, 2004 Share Posted April 29, 2004 Well that looks like different data, if it was the original data with 1-3 fields, it would be simple. $filename="emp.txt" FileDelete("output.txt") $file=StringReplace(Fileread($filename,FileGetSize($filename)),@LF,"")&@CR $lines=StringSplit($file,@CR) $id=1 $mem=$lines[1]; start with first line in memory For $i=2 To $lines[0] $temp1=StringSplit($lines[$i],":") $temp2=StringSplit($mem,":") If $temp1[1]=$temp2[1] Then If $temp2[0]=3 Then $mem=$lines[$i]&"|"&$temp2[3] Else $mem=$lines[$i] EndIf Else FileWriteLine("output.txt",$id&":"&$mem) $mem=$lines[$i] $id=$id+1 EndIf Next import into access 3 times, first import it in : delimited and remove the spouce and children fields and call it emp_data, then import it a second time and remove emp and children, remove empty fields, and use the ID field to link them and name it spouce_data, for the children you can use autoit to split them all back out with the same ID, and import it as child_data. You are loosing me on that data, I guess you will have to know what the data means first. So this is a geneology type database, not an employee one? AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
CyberGlitch Posted April 29, 2004 Author Share Posted April 29, 2004 Yea, I'm kinda lost on the data as well just going by what they told me, not much as you can guess. Doing this for one of our clients, they said emp database but if it is then it must be the whole family tree from further investigation! Know what I want but not how to get it I supose. Thought it would be easy and I had it figured out but then I ran into the same name game. I had 2 scripts first that wrote line to an array and used the last variable and wrote that to a file with a number. 2nd script went back over the first to match names to the first scripts output file and get the number and write that name/number to my endfile and that I would later use to import to access. Problem arose with same names. My head hurts. Thankfully it's the end of the day and I can go home soon and sleep on this. Link to comment Share on other sites More sharing options...
CyberGlitch Posted April 30, 2004 Author Share Posted April 30, 2004 Ok, I'm back at the drawing board and using your script but can't for the life of me figure out the 2nd piece to my puzzle. If people had unique names it would be a problem for me. expandcollapse popup$filename="names.txt" $file=StringReplace(Fileread($filename,FileGetSize($filename)),@LF,"")&@CR $lines=StringSplit($file,@CR) FileDelete("output.txt") $count = 1 $mem=$lines[1]; start with first line in memory For $i=1 To $lines[0] $temp1=StringSplit($lines[$i],":") $temp2=StringSplit($mem,":") For $t=1 to $temp1[0] If $temp1[$t]=$temp2[1] Then If $temp2[0]=1 Then ;MsgBox(0,"",$temp2[1]) $mem=$temp2[1] Else $w = $temp1[0] $mem = $temp1[$w] EndIf Else If StringInStr($mem,":")>0 Then ContinueLoop Else ;MsgBox(0,$temp1[$t],$mem) FileWriteLine("output.txt",$count & "," & $mem) $mem=$lines[$i] $count = $count+1 EndIf EndIf Next Next names.txt Ken Ken:Barbara Ken:Barbara:Kevin Ken:Barbara:Tom Ken:Barbara:Tom:Jenny Ken:Barbara:Tom:Jenny:Kevin Ken:Barbara:Tom:Jenny:Richard This currently outputs, can't get it to add the 2nd name barbara in this example. But my output should look like this. 1,Ken 2,Barbara 3,Kevin 4,Tom 5,Jenny 6,Kevin 7,Richard Need a way to link to number with the name before it and can't think of a way to do it. You would want to match the name before it with it's given number so you know who that name belongs to. In this instance for example I would want. 1,0,Ken 2,1,Barbara 3,2,Kevin 4,2,Tom 5,4,Jenny 6,5,Kevin 7,5,Richard ^-- This is what I want the output to look like. I could easly do this if it wasn't for the multiple instances of the names. Last shot for anyone here before I give up and tell client not going to be possable unless we do it by hand!! Link to comment Share on other sites More sharing options...
Developers Jos Posted April 30, 2004 Developers Share Posted April 30, 2004 (edited) try this version.... it might need some finetuning but the result is what you are looking for: $filename = "names.txt" $file = StringReplace(FileRead($filename, FileGetSize($filename)), @LF, "") & @CR $lines = StringSplit($file, @CR) FileDelete("output.txt") Dim $SaveName[100] $SCnt = 0 $count = 1 For $i = 1 To $lines[0] $temp1 = StringSplit($lines[$i], ":") For $t = 1 To $temp1[0] For $n = 1 To $scnt If $SaveName[$n] = $temp1[$t] Then ExitLoop Next If $n > $scnt Then $y = 0 If $t > 1 Then For $y = 1 To $SCnt If $SaveName[$y] = $temp1[$t - 1] Then ExitLoop Next EndIf $SCnt = $SCnt + 1 $SaveName[$SCnt] = $temp1[$t] FileWriteLine("output.txt", $n & "," & $y & "," & $SaveName[$n]) EndIf Next Next Edited April 30, 2004 by JdeB SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
scriptkitty Posted April 30, 2004 Share Posted April 30, 2004 ok, how about if we reverse the logic here. First we alpha it: Then we reverse the elements and the second element is the parent. Ken Ken:Barbara Ken:Barbara:Kevin Ken:Barbara:Tom Ken:Barbara:Tom:Jenny Ken:Barbara:Tom:Jenny:Kevin Ken:Barbara:Tom:Jenny:Richardcode to do this would be: $filename="test.txt" FileDelete("outme.txt") $file=StringReplace(FileRead($filename,FileGetSize($filename)),@LF,"") $line=stringSplit($file,@CR) $x=1 $mem=$line[1] For $i=1 To $line[0] $rev=StringSplit($line[$i],":") $x="" For $u=$rev[0] To 1 Step -1 $x=$x&":"&$rev[$u] Next $out=StringSplit(StringTrimLeft($x,1),":") If $out[0]=1 Then FileWriteLine("outme.txt",$out[1]&",Primary") Else FileWriteLine("outme.txt",$out[1]&","&$out[2]) EndIf Next This would have the names themselves be the parentID. Ken,Primary Barbara,Ken Kevin,Barbara Tom,Barbara Jenny,Tom Kevin,Jenny Richard,Jenny Anyway, how many names are we talking about? AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
CyberGlitch Posted April 30, 2004 Author Share Posted April 30, 2004 We're talking about several thousand lines. JdeB: Exactly what I wanted but same problem I ran into before. If I have Ken:Barbara:Tom:Jenny:Kevin and then later down the page John:Deborah:Kevin In the 2nd instance Kevin is linked to Jenny and not Deborah. Link to comment Share on other sites More sharing options...
Developers Jos Posted April 30, 2004 Developers Share Posted April 30, 2004 (edited) ok.. ...nice challenge.. second try: $filename = "names.txt" $file = StringReplace(FileRead($filename, FileGetSize($filename)), @LF, "") $lines = StringSplit($file, @CR) FileDelete("output.txt") dim $SaveName[100] $SCnt =0 $count = 1 For $i = 1 To $lines[0] $temp1 = StringSplit($lines[$i], ":") $tstname ="" $prnname ="" For $t = 1 To $temp1[0] $tstname = $tstname & "|" & $temp1[$t] if $t > 1 Then $prnname = $prnname & "|" & $temp1[$t-1] For $n = 1 to $scnt if $SaveName[$n] = $tstname then ExitLoop Next If $n > $scnt Then $y = 0 if $t > 1 Then for $y = 1 to $SCnt if $SaveName[$y] = $prnname then ExitLoop next EndIf $SCnt = $SCnt + 1 $SaveName[$SCnt] = $tstname FileWriteLine("output.txt",$n & "," & $y & "," & $temp1[$t]) Endif Next Next Edited April 30, 2004 by JdeB SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
scriptkitty Posted April 30, 2004 Share Posted April 30, 2004 (edited) ok, how does this work: $filename="test.txt" FileDelete("outme.txt") $file=StringReplace(FileRead($filename,FileGetSize($filename)),@LF,"") $line=stringSplit($file,@CR) $x=1 $count=0 $mem=$line[1] For $i=1 To $line[0] $rev=StringSplit($line[$i],":") $x="" For $u=$rev[0] To 1 Step -1 $x=$x&":"&$rev[$u] Next $out=StringSplit(StringTrimLeft($x,1),":") If $out[0]=1 Then $count=$count+1 FileWriteLine("outme.txt",$out[1]&",Primary"&","&$out[1]&$count) Else FileWriteLine("outme.txt",$out[1]&","&$out[2]&$count&","&$out[1]&$count) EndIf Next on your sorted list, this should spit out: Name,parent,UniqueID example: Ken Ken:Barbara Ken:Barbara:Kevin Ken:Barbara:Tom Ken:Barbara:Tom:Jenny Ken:Barbara:Tom:Jenny:Kevin Ken:Barbara:Tom:Jenny:Richardspits out: Ken,Primary,Ken1 Barbara,Ken1,Barbara1 Kevin,Barbara1,Kevin1 Tom,Barbara1,Tom1 Jenny,Tom1,Jenny1 Kevin,Jenny1,Kevin1 Richard,Jenny1,Richard1Make sence? I thought with that many names you would need to make a unique number. You could add the depth intoit, so that barbara would not be barbara1 but barbara1_1, ken would be ken1_0, etc. in case you have an entry like Ken:Barbara Ken:Tom:Barbara:Kevin:Tom Ken:Sam:Tom Anyway this might work if your data is not too wierd. Edited April 30, 2004 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
CyberGlitch Posted April 30, 2004 Author Share Posted April 30, 2004 By George I think you got it. I racked my brain all day trying different things to get that result. further testing will have to wait till monday as it is now 5pm but what a wonderful way to go into the weekend. Now this won't be bothering me tomorrow while sailing! Is there a $ tip section around here for you personaly or the community? Defiently worth it! Link to comment Share on other sites More sharing options...
Developers Jos Posted April 30, 2004 Developers Share Posted April 30, 2004 (edited) By George I think you got it. I racked my brain all day trying different things to get that result. further testing will have to wait till monday as it is now 5pm but what a wonderful way to go into the weekend. Now this won't be bothering me tomorrow while sailing!Is there a $ tip section around here for you personaly or the community? Defiently worth it!Do you want mine or Scriptkitty's bankaccount ??? Just kidding... Jon has a PayPal account so dump it his way since AutoIt is his Baby..... Edited April 30, 2004 by JdeB SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
scriptkitty Posted April 30, 2004 Share Posted April 30, 2004 (edited) I love your solution JdeB, but...try this bit of names a bit though:KenKen:BarbaraKen:Barbara:KevinKen:Barbara:TomKen:Barbara:Tom:JennyKen:Barbara:Tom:Jenny:KevinKen:Barbara:Tom:Jenny:RichardBrianBrian:KristyBrian:Kristy:CloeBrian:Kristy:KatieBrianBrian:SueBrian:Sue:CindyBrian:Sue:JackChrisFredFred:JanFred:Jan:JaneFred:Jan:JaneyFred:Jan:JimFred:Jan:JimboFred:Jan:JimmyJeffJeff:AprilJeff:April:KatieRobertRobert:RachealRobert:Racheal:Tom Anyway I completely agree with ya JdeB ...AutoIt is his Baby.....As long as AutoIt lives, I am happy. Edited April 30, 2004 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
scriptkitty Posted April 30, 2004 Share Posted April 30, 2004 Actually thinking about some really wierd senarios, I have this one as well to make a bit more unique uniqueID. $filename="test.txt" FileDelete("outme.txt") $file=StringReplace(FileRead($filename,FileGetSize($filename)),@LF,"") $line=stringSplit($file,@CR) $x=1 $count=0 $mem=$line[1] For $i=1 To $line[0] $rev=StringSplit($line[$i],":") $x="" For $u=$rev[0] To 1 Step -1 $x=$x&":"&$rev[$u] Next $out=StringSplit(StringTrimLeft($x,1),":") If $out[0]=1 Then $count=$count+1 FileWriteLine("outme.txt",$out[1]&",Primary"&","&$out[1]&"1_"&$count) Else FileWriteLine("outme.txt",$out[1]&","&$out[2]&$out[0]-1&"_"&$count&","&$out[1]&$out[0]&"_"&$count) EndIf Next it simply adds in the depth of the person in case they have say John jr. or John the 3rd. Without knowing the what the whole file looks like it is but a guess. Ken Ken:Barbara Ken:Barbara:Kevin Ken:Barbara:Tom Ken:Barbara:Tom:Jenny Ken:Barbara:Tom:Jenny:Kevin Ken:Barbara:Tom:Jenny:Richard Brian Brian:Kristy Brian:Kristy:Cloe Brian:Kristy:Katie Brian Brian:Sue Brian:Sue:Cindy Brian:Sue:Jack Chris Fred Fred:Jan Fred:Jan:Jane Fred:Jan:Janey Fred:Jan:Jim Fred:Jan:Jimbo Fred:Jan:Jimmy Frank Frank:Jannet Frank:Jannet:Frank Frank:Jannet:Jannet Jeff Jeff:April Jeff:April:Katie Robert Robert:Racheal Robert:Racheal:Tom AutoIt3, the MACGYVER Pocket Knife for computers. 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