Knight Posted October 13, 2005 Posted October 13, 2005 (edited) Alright I made a function that will search an array over and over again for "None" and then delete it and when there is no more "None"'s it will return UBound of that array. #include <Array.au3> Func _TrimDownArray($ArrayToUse) Do $Found = _ArraySearch($ArrayToUse, "None") MsgBox(0, "", $Found) If Not $Found = " " Then _ArrayDelete($ArrayToUse, $Found) Until $Found = "" return UBound($ArrayToUse, 1) EndFunc The problem I have is, is that if the array only contains "None" then it UBound returns as many elements in the array as there is. Use this for example.. It returns 3 as it should.. #include <Array.au3> $Array = _ArrayCreate("Fish", "Goose", "Chicken", "None", "None") $Trim2UBound = _TrimDownArray($Array) MsgBox(4100, "Array", $Trim2UBound) Exit Func _TrimDownArray($ArrayToUse) Do $Found = _ArraySearch($ArrayToUse, "None") If Not $Found = "" Then _ArrayDelete($ArrayToUse, $Found) Until $Found = "" return UBound($ArrayToUse, 1) EndFunc now, if I replace all the animals with "None", then it will return 5 rather then 0. #include <Array.au3> $Array = _ArrayCreate("None", "None", "None", "None", "None") $Trim2UBound = _TrimDownArray($Array) MsgBox(4100, "Array", $Trim2UBound) Exit Func _TrimDownArray($ArrayToUse) Do $Found = _ArraySearch($ArrayToUse, "None") If Not $Found = "" Then _ArrayDelete($ArrayToUse, $Found) Until $Found = "" return UBound($ArrayToUse, 1) EndFunc Anyone have any ideas to solve this? I have tried numerous things to no avail. Thanks, JKnight Edited October 13, 2005 by Knight
Knight Posted October 13, 2005 Author Posted October 13, 2005 Alright I have done alot of testing and have yet to solve the problem, but I realize why it doesn't work. You can't delete every element of the array, so I have to find a way to be able to do that.
Knight Posted October 13, 2005 Author Posted October 13, 2005 After spending hours of trying to do this, I resorted to a different approach. Any help doing it the old way would be GREATLY APPRECIATED! Func _FuckThisShit($ArrayToUse) Local $TotalElements = UBound($ArrayToUse, 1) Local $Element = 0 Local $UseElements = 0 While 1 If Not $ArrayToUse[$Element] = "" Then $UseElements += 1 $Element += 1 If $Element = $TotalElements Then ExitLoop WEnd return $UseElements EndFunc
buzz44 Posted October 13, 2005 Posted October 13, 2005 (edited) #include <Array.au3> $Array = _ArrayCreate("None", "None", "None", "None", "None") $Trim2UBound = _TrimDownArray($Array) MsgBox(4100, "Array", $Trim2UBound) Func _TrimDownArray($ArrayToUse) For $I = 0 To UBound($ArrayToUse) - 1 If $ArrayToUse[$I] <> "None" Then Do $Found = _ArraySearch($ArrayToUse, "None") If Not $Found = "" Then _ArrayDelete($ArrayToUse, $Found) Until $Found = "" Return UBound($ArrayToUse) EndIf Next EndFunc Edited October 13, 2005 by Burrup qq
Skruge Posted October 13, 2005 Posted October 13, 2005 Here's what I came up with:#include <Array.au3> $Array = _ArrayCreate("Fish", "Goose", "Chicken", "None", "None") $Array = _ArrayCreate("None", "None", "None", "None", "None") $Trim2UBound = _TrimDownArray($Array) MsgBox(4100, "Array", $Trim2UBound) Exit Func _TrimDownArray($ArrayToUse) Local $StringArray $StringArray = _ArrayToString($ArrayToUse, "|") & "|" $StringArray = StringReplace($StringArray, "None|", "") $StringArray = StringLeft($StringArray, StringLen($StringArray) - 1) $ArrayToUse = StringSplit($StringArray, "|") _ArrayDelete($ArrayToUse, 0) If $StringArray = "" Then Return 0 Else Return UBound($ArrayToUse, 1) EndIf EndFunc ;==>_TrimDownArrayNote that $Array will not be altered unless it's passed by Reference. Func _TrimDownArray(ByRef $ArrayToUse) [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]
Knight Posted October 13, 2005 Author Posted October 13, 2005 (edited) @Burrup Thanks! It works perfect with one exception.. $Array = _ArrayCreate("None", "Fish", "Goose", "Mongoose", "None") The above will return 5 with your function. I don't plan on having that exception happen because the array should never appear like that anyway. Thanks again, @Skruge Oops just noticed yours, Ill test it in a sec.. -JKnight Edited October 13, 2005 by Knight
buzz44 Posted October 13, 2005 Posted October 13, 2005 Bah, I hate it when stuff doesn't work. I'll fix it in a bit . qq
buzz44 Posted October 13, 2005 Posted October 13, 2005 #include <Array.au3> $Array = _ArrayCreate("Fish", "Goose", "Chicken", "None", "None") $Trim2UBound = _TrimDownArray($Array) MsgBox(4100, "Array", $Trim2UBound) Func _TrimDownArray($ArrayToUse) Local $Temp For $I = 0 To UBound($ArrayToUse) - 1 If $ArrayToUse[$I] = "None" Then $Temp = $Temp & $I & "," EndIf Next $Split = StringSplit(StringTrimRight ($Temp, 1), ",") If $Split[0] = UBound($ArrayToUse) Then $ArrayToUse = 0 Else For $I = 1 To $Split[0] _ArrayDelete($ArrayToUse, $Split[$I]) Next EndIf Return UBound($ArrayToUse) EndFunc Fixed . When all the index's don't equal "None" it returns 4 because that is the UBound. When they all equal "None" it sets the array to 0 thus deleting it. qq
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