Jump to content
Sign in to follow this  
ioliver

Finding The Last Item In A Array

Recommended Posts

I'm using the StringSplit() command to break up a file path by "\". I need to be able to find out what the last value in the Array is, because that will be part of a Window Title. The file path may change, so I can't hardcode this, the script needs to be able to find the last array value. Is there anyway to do this?

Here is my code so far, but it don't work:

$classlist = InputBox("(Class List) Filename?", "Type in the name of the file (Class List) you downloaded:")

$clarray = StringSplit($classlist, "\")

$x = 11

Do

  $x = $x - 1

Until $clarray($x) <> ""

MsgBox(0,"Title",$clarray($x))

Thanks for your Help,

Ian


"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Share this post


Link to post
Share on other sites

No need to loop, I'd use the UBound function for this, ie;

$classlist = InputBox("(Class List) Filename?", "Type in the name of the file (Class List) you downloaded:")

$clarray = StringSplit($classlist, "\")

MsgBox(0,"Title",$clarray[uBound($clarray)-1])CODE]

Also, remember when referencing individual array elements to use [], not ().

Share this post


Link to post
Share on other sites

Remember that StringSplit will 'fail' if $classList does not contain "\", so you should check @error or use IsArray to prevent $clarray[uBound($clarray)-1] from crashing

:iamstupid: Just ignore this post. Larry (correctly) points out below that ScriptSplit will not "fail" the way I describe :whistle:

Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...