Jump to content

Size Of An Array?


Recommended Posts

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]

Link to comment
Share on other sites

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 by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

  • Developers

I spent way to much time reading the help file and not finding that function.

B) what about :

-click on Search label

- type "array size"

- ENTER

You get 1 guess what it returns at the top of the list ... :whistle:

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

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...