CmdrRat 0 Posted March 13, 2004 I'm using StringSplit to split a string (DuH!) and then writing each element of the array to a cell of the Spreadsheet. Problem is my Strings are split into variable size arrays, so when I go to write the data I end up getting errors on the smaller strings that end up with arrays that are only 2 or 3 elements long becuase $Array[4] doesn't exist. I could check for the size of the array but I can't find a way to do that. Any recommendations? If it helps you picutre this here is the code and below is some sammple data. $line is the current line from an open text file. Func WriteName($line) Send("{HOME}") Send("{RIGHT}") $name = StringSplit($line,",") ClipPut($Name[1]) Send("^v") Send("{RIGHT}") $Middlei = StringSplit($Name[2]," ") ClipPut($Middlei[2]) Send("^v") Send("{RIGHT}") ClipPut($Middlei[3]) Send("^v") Return EndFunc brown, joe , W smith, mark foo , ba, r As you can see the second name would error out the script because there is no $middle[3] Share this post Link to post Share on other sites
scriptkitty 1 Posted March 13, 2004 (edited) UBound -------------------------------------------------------------------------------- Returns the size of array dimensions. UBound ( Array [, Dimension])put an if like if Ubound($Middlei) =4 then or since you use stringsplit, $Middlei[0]= the amount of elements besides itself. example: $Middlei=StringSplit($line,",") for $i=1 to $Middlei[0] dosomething() clipput($Middlei[$i]) dosomethingelse() next Edited March 13, 2004 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers. Share this post Link to post Share on other sites
CmdrRat 0 Posted March 13, 2004 THANKS, I spent way to much time reading the help file and not finding that function. Thanks for your help Share this post Link to post Share on other sites
Jos 2,165 Posted March 13, 2004 I spent way to much time reading the help file and not finding that function. what about : -click on Search label- type "array size"- ENTERYou get 1 guess what it returns at the top of the list ... 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. Share this post Link to post Share on other sites
CmdrRat 0 Posted March 13, 2004 DAMN ALL OF YOU AND YOUR LOGIC! :iamstupid: Share this post Link to post Share on other sites
Jos 2,165 Posted March 13, 2004 glad to help ... anytime .... 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. Share this post Link to post Share on other sites
scriptkitty 1 Posted March 13, 2004 if you wanted to write the array into a spreadsheet (as mentioned) remember stringReplace. Func WriteName($line) Send("{HOME}") Send("{RIGHT}") $name = StringReplace($line,",","{right}") Send($name) send("{home}{down}") Return EndFunc Not really the best, due to spreadsheet's autofill functions. but showing more than one way to do things. reminder: ; open spreadsheet and run winwaitactive("New Workbook"); or whatever the title $x="billybob,bill,Texas,T,aaaaaaa,aaa" $x2=StringReplace($x,",","{down}") send($x2) autofill sucks sometimes. AutoIt3, the MACGYVER Pocket Knife for computers. Share this post Link to post Share on other sites
CmdrRat 0 Posted March 14, 2004 Thanks kitty, I might end up using that. my challange here is reading in a csv file created from an OCR program. it's 95% right, but not all the way there. I was trying to ceatch common problems and look at the context of the info. AN example of my data 257504 SMITH, BOB T, CAPT USNR RET - SUZY 46 W LUCERNE CIR #4329, ORLANDO, FL, 32801-3572 112341 Williams, MARK P, COL USAF RET - SAMMANTHA 2317 DRUID ISLE RD, MAITLAND, FL, 32751-4224 407-555-5555 1153637 bhfsds23@aol.com HEDGE, SUZY J, MRS AUX - 214 MAITLAND AVE, ALTAMONTE SPG, FL, 32701-4902 407-555-5555 You can see most records have 3 lines, all of witch need to be put into one row in excel. It's proving to be harder than I thought because Of the fact that everything changes, some have emails, others don't. Sometimes the OCR program reads a "," as a "." and sometimes it's @aol.corn rather than com. But I think I got it working well now. Thank you for everyone's help Share this post Link to post Share on other sites