Sign in to follow this  
Followers 0
kor

Why isn't my code deleting blank elements from my array?

3 posts in this topic

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#Include <GuiRichEdit.au3>
#include <Array.au3>

Example1()

Func Example1()
    Local $msg

    Global $maingui = GUICreate("My GUI", 200, 200) ; will create a dialog box that when displayed is centered
    
    $button = GUICtrlCreateButton("Bulk", 50, 50, 80, 30)
    GuiCtrlSetState($button, $GUI_FOCUS)

    GUISetState(@SW_SHOW) ; will display an empty dialog box

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $button
                _Create()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    GUIDelete()
EndFunc   ;==>Example1

Func _Create()
    Local $msg
    $creategui = GUICreate("bulk create", 250, 290)
    Global $edit = _GUICtrlRichEdit_Create($creategui, "FirstName,LastName" & @CR, 10, 10, 230, 230, BitOr($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    $button1 = GUICtrlCreateButton("Ready", 70, 250, 80, 30)
    GUISetState()
    
        While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $button1
                _stuff()
            Case $GUI_EVENT_CLOSE
                GUIDelete()
                Exit
        EndSwitch
    WEnd
EndFunc

Func _stuff()
    Local $sTmp = ''
    $result = _GuiCtrlRichEdit_GetText($edit)
    msgbox(0, "", $result)
    $rows = StringSplit($result, @CRLF, 2)
;$rows = StringToASCIIArray($result)
    _ArrayDisplay($rows)
    Dim $list[2]
    $list[0] = "FirstName"
    $list[1] = @CRLF
For $i = Ubound($rows) - 1 to 0 Step - 1
    For $n = 0 to UBound($list) -1
        If StringInStr($rows[$i], $list[$n]) then
            _ArrayDelete($rows, $i)
        EndIf
    Next
Next
    
    _ArrayDisplay($rows)
    Exit
EndFunc

So if you take this code and type some random lines in the richedit box and hit enter a few times, then type some more random text and click ready you will see that the an array is created with each line, however the lines where you hit enter are efficiently blank, but my code isn't deleting those rows and it's driving me nuts.

I've tried using @CRLF, @CR, @LF, @TAB in the $list array and none of them remove the blank rows.

Share this post


Link to post
Share on other sites



You're not going to have a @CRLF in the array, since that's the delimiter you used in your StringSplit() call. The delimiter is discarded.

Try simply testing for empty elements:

For $i = Ubound($rows) - 1 to 0 Step - 1
    If $rows[$i] == "" Or $rows[$i] == "FirstName" then
        _ArrayDelete($rows, $i)
    EndIf
Next

Share this post


Link to post
Share on other sites

You're not going to have a @CRLF in the array, since that's the delimiter you used in your StringSplit() call. The delimiter is discarded.

Try simply testing for empty elements:

For $i = Ubound($rows) - 1 to 0 Step - 1
    If $rows[$i] == "" Or $rows[$i] == "FirstName" then
        _ArrayDelete($rows, $i)
    EndIf
Next

makes sense. thank you.

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