Jump to content

how do i delete an array element that is NULL


Recommended Posts

when i try and run this i get an error - i am trying to delete any index that does not have a value - thanks for your help

#include <array.au3>

Global $hand[7] = [413, 213, 113, 115, 116, 117, 114]


_Find($hand)


Func _Find($aArray, $checkstraight = 1)

    Local $CountSuitSpades, $aArrayTempSpades[7]

    For $i = 0 To UBound($aArray) - 1
        If StringLeft($aArray[$i], 1) = 1 And $aArray[$i] > 100 Then
            $CountSuitSpades += 1
            $aArrayTempSpades[$i] = $aArray[$i]
        EndIf
    Next
    
    Select
        Case $CountSuitSpades >= 5
            $Flusher = 1
            If $checkstraight Then
                                
                _ArrayDisplay($aArrayTempSpades)
                
                For $i = 0 To UBound($aArrayTempSpades) - 1
                ;If $i = 6 Then ExitLoop
                    If $aArrayTempSpades[$i] = '' Then _ArrayDelete($aArrayTempSpades, $i)
                Next
                
                                                                _ArrayDisplay($aArrayTempSpades)
                Return $aArrayTempSpades
            Else
                Return 1;$Flush
            EndIf
    EndSelect
    
EndFunc  ;==>_Find

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

  • Developers

Pretty sure this will error out as we discussed earlier today in this thread: http://www.autoitscript.com/forum/index.php?showtopic=87242

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

Pretty sure this will error out as we discussed earlier today in this thread: http://www.autoitscript.com/forum/index.php?showtopic=87242

this points back to my thread? is it not possible?

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

  • Developers

this points back to my thread? is it not possible?

oops... try this one: http://www.autoitscript.com/forum/index.ph...st&p=625996 Edited by Jos

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

when i try and run this i get an error - i am trying to delete any index that does not have a value - thanks for your help

This is my preferred method, because it delete entries that are not null but contain only whitespace:
_ArrayDisplay($aArrayTempSpades)
                For $i = UBound($aArrayTempSpades) - 1 To 0 Step -1
                    If StringStripWS($aArrayTempSpades[$i], 8) = '' Then _ArrayDelete($aArrayTempSpades, $i)
                Next
                _ArrayDisplay($aArrayTempSpades)

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

This is my preferred method, because it delete entries that are not null but contain only whitespace:

_ArrayDisplay($aArrayTempSpades)
                For $i = UBound($aArrayTempSpades) - 1 To 0 Step -1
                    If StringStripWS($aArrayTempSpades[$i], 8) = '' Then _ArrayDelete($aArrayTempSpades, $i)
                Next
                _ArrayDisplay($aArrayTempSpades)

:)

Thanks for everyones help

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

This is my preferred method, because it delete entries that are not null but contain only whitespace:

_ArrayDisplay($aArrayTempSpades)
                For $i = UBound($aArrayTempSpades) - 1 To 0 Step -1
                    If StringStripWS($aArrayTempSpades[$i], 8) = '' Then _ArrayDelete($aArrayTempSpades, $i)
                Next
                _ArrayDisplay($aArrayTempSpades)

:)

Psalty, how can you do that. You know better not to change an array while you're iterating on it.
Link to comment
Share on other sites

Psalty, how can you do that. You know better not to change an array while you're iterating on it.

I don't think it's a problem because PsaltyDS made sure he started at Ubound -1 and worked backwards, so the the element deleted is not one of the elements still to be considered.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Psalty, how can you do that. You know better not to change an array while you're iterating on it.

As Martin pointed out, this is exactly how that's done, by walking the array backwards so your changes don't impact the elements you haven't dealt with yet.

The primary reason NOT to do it this way is speed. The function _ArrayDelete() does a lot of ReDim'ing and loops to copy data to new locations. If the performance hit becomes significant, then you can use the "SmOke_N" technique (I don't know if he came up with it, but he did the first example that gave me the 'aha!' moment on it). You assemble a delimited string of all elements to keep and then let StringSplit() or StringRegExp() produce the desired array:

_ArrayDisplay($aArrayTempSpades)
                Local $sTempStr = ''
                For $i = 0 To UBound($aArrayTempSpades) - 1
                    If StringStripWS($aArrayTempSpades[$i], 8) <> '' Then $sTempStr &= $aArrayTempSpades[$i] & Chr(1)
                Next
                $aArrayTempSpades = StringSplit(StringTrimRight($sTempStr, 1), Chr(1), 2)
                _ArrayDisplay($aArrayTempSpades)

If there are many changes to make this can be much faster.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...