Sign in to follow this  
Followers 0
jtrout

_Array to tell the last element number?

6 posts in this topic

I'm looking at all the last element number for an array so that way I can check it against an array from a file.

CODE

_FileReadToArray("My.txt", $Servers)

$newdrives = _ArrayCreate("TEMP")

For $x = 1 To $Servers[0]

$Driveletter = DriveMapAdd("*", $path, 0, $user, $password)

If $Driveletter = "" Then

MsgBox(0, "Error", "Error while mapping the drive to " & $Servers[$x] & "." & @CRLF & @error)

Else

_ArrayInsert($newdrives, $x, $Driveletter & "," & $Servers[$x])

EndIf

Next

_ArrayDelete($newdrives, 0)

If $Servers[0] = **WHAT DO I PUT HERE?** Then

msgbox(0,"TEST","YEP they are the same.")

Else

msgbox(0,"TEST","Nope they are not the same.")

Endif

Share this post


Link to post
Share on other sites



You can use Ubound($yourarray)-1 to get the array size, so that...

$lastelement = $yourarray[Ubound($yourarray)-1]

that should get you what you want.

Share this post


Link to post
Share on other sites

Well that gave me what was in the last element but I need to know what the numeric value of that numbered element is. like if the array had 0 - 5 I need to know is 6. How would I get that?

You can use Ubound($yourarray)-1 to get the array size, so that...

$lastelement = $yourarray[Ubound($yourarray)-1]

that should get you what you want.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Well that gave me what was in the last element but I need to know what the numeric value of that numbered element is. like if the array had 0 - 5 I need to know is 6. How would I get that?

If you just wanted to know the array size, you would do

$size = Ubound($yourarray)-1
Edited by Leighwyn

Share this post


Link to post
Share on other sites

... like if the array had 0 - 5 I need to know is 6. ..How would I get that?

$Servers[0]

or

Ubound($Servers)

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

DUH! Thank you!

$Servers[0]

or

Ubound($Servers)

8)

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  
Followers 0