Sign in to follow this  
Followers 0
jfcby

ListBox Load From Array [Resolved]

4 posts in this topic

#1 ·  Posted (edited)

I'm trying to understand how to get the listbox to load the array from line 67 - $ar = _IETableWriteToArray($oTable, True).

But I keep getting this error:

Array Option- Dictionary:C:\Program Files\AutoIT3\My Projects\ArticleWriterVibes\SpellCheck\SpellCheckExample.au3 (93) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$sListData &= "|" & $ar[0][$i]

$sListData &= "|" & ^ ERROR

How can I get the listbox to load the data from the array?

#include <GuiConstantsEx.au3>
#include <EditConstants.au3>
#include <GuiEdit.au3>
#include <WindowsConstants.au3>
#include <array.au3>
#include <GuiListBox.au3>
#include <StaticConstants.au3>
#include <IE.au3>

Global $filemenu, $fileitem
Global $helpmenu, $saveitem, $infoitem, $exititem, $recentfilesmenu
Global $separator1, $viewmenu, $viewstatusitem, $okbutton, $cancelbutton
Global $msg, $file

$hWidth = 395
$hHeight = 425
$hLeft = $hWidth / 2
$hTop = $hHeight / 2

$hGUI = GUICreate("Spell Check Example", $hWidth, $hHeight, (@DesktopWidth / 2) - $hLeft, (@DesktopHeight / 2) - $hTop)

    $Label1 = GUICtrlCreateLabel("Editor", 5, 1, 100, 15)
    GUICtrlSetFont(-1, 9, 600)  
    
    $Edit1 = GUICtrlCreateEdit("Coutn adn splel", 5, 25, 385, 350, _
        BitOR($ES_AUTOVSCROLL, $ES_MULTILINE, $ES_NOHIDESEL, $ES_WANTRETURN))
    
    $Button1 = GUICtrlCreateButton("Spell Check", 325, 380) 
    
GUISetState()

$nOffset = 1

While 1
    $Msg = GUIGetMsg()
    Select
        Case $Msg = $GUI_EVENT_CLOSE
            Exit        
        Case $Msg = $Button1            
            _SpellCheck()
    EndSelect
WEnd

Func _SpellCheck()
    ;
    
    ;Select individual word.
    $array = StringRegExp(GUICtrlRead($Edit1), "[\s\.:;,]*([a-zA-Z0-9-_]+)[\s\.:;,]*", 3, $nOffset) 
    If @error = 0 Then
        $nOffset = @extended
    Else
        ;ExitLoop
    EndIf
    
    For $i = 0 to UBound($array) - 1
;~      msgbox(0, "RegExp Test with Option 1 - " & $i, $array[$i])
        
        $oIE = _IECreate("http://dictionary.reference.com/search?q=" & $array[$i], 0, 0)
        $oTable = _IETableGetCollection($oIE, 0)
        If IsObj($oTable) Then 
            $ar = _IETableWriteToArray($oTable, True)
            Global $ar[2][2]
;~          _ArrayDisplay($ar)          
            ConsoleWrite("Array Option- " & $ar[0][0])
            If $ar[0][0] = "Dictionary:" Then               
                ;Create ChildGUI
                ;Center Child GUI in Main GUI:  parent width/2 minus the child's width/2
                $cWidth = 250
                $cHeight = 250              
                $cLeft = $hWidth / 2 - $cWidth / 2
                $cTop = $hHeight /2 - $cHeight / 2
                $cGUI = GUICreate("Spell Check", $cWidth, $cHeight, $cLeft, $cTop, Default, BitOR($WS_EX_MDICHILD, $WS_EX_TOOLWINDOW), $hGUI)
                $Label1 = GUICtrlCreateLabel("Original Text:", 5, 5, 75, 20)
                $Label2 = GUICtrlCreateLabel("Replace With:", 5, 30, 75, 20)    
                $Input1 = GUICtrlCreateInput("", 100, 5, 145, 20)
                GUICtrlSetState(-1, $GUI_DISABLE)   ; the label is in disable state
                $Input2 = GUICtrlCreateInput("", 100, 30, 145, 20)
                $ListBox1 = GUICtrlCreateList("", 5, 55, 155, 200)
                $Button1 = GUICtrlCreateButton("Replace", 170, 65, 75, 20)
                $Button2 = GUICtrlCreateButton("Ignore", 170, 85, 75, 20)   
                $Button3 = GUICtrlCreateButton("Close", 170, 225, 75, 20)
                GUISetState(@SW_SHOW)
                
                ; Add files
                $sListData = ""
                For $i = 0 To Ubound($ar)-1
                   $sListData &= "|" & $ar[0][$i]
                Next
                GUICtrlSetData($ListBox1, $sListData)
                
                
                While 1

                    $aMsg = GUIGetMsg(1)

                    If $aMsg[1] = $cGUI Then ; Check we are getting messages from the child
                        Switch $aMsg[0]
                            Case $GUI_EVENT_CLOSE
                                GUIDelete($cGUI)
                                ExitLoop
                            Case $Button1
                    
                            Case $Button2
                            
                            Case $ListBox1
                            
                        EndSwitch
                    EndIf

                WEnd
                
            EndIf
        EndIf
        _IEQuit($oIE)
    Next
        
EndFunc     ;==>_SpellCheck

Thank you for your help,

jfcby

Update 1/11/2010: For full example code go to: Xamp Spell Check

Edited by jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Take a look in the help file for _ArrayToString()

GuiCtrlSetData($SomeList, _ArrayToString($Array))

Just writing it from memory because I don't have AutoIt on any systems right now so double check the parameters for _ArrayToString() and check that the separator is "|".

Also Don't create controls in a function like that. Create them with the rest of the GUI controls.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Hi,

I'm still not understanding something because I made the following changes and now I am not getting an error but there is no data loaded into the listbox.

; Add files
$sListData = ""
For $i = 0 To UBound($ar, 2) -1
  $ar2 = $ar[0][$i]
Next
GuiCtrlSetData($ListBox1, _ArrayToString($ar2))

#include <GuiConstantsEx.au3>
#include <EditConstants.au3>
#include <GuiEdit.au3>
#include <WindowsConstants.au3>
#include <array.au3>
#include <GuiListBox.au3>
#include <StaticConstants.au3>
#include <IE.au3>

Global $filemenu, $fileitem
Global $helpmenu, $saveitem, $infoitem, $exititem, $recentfilesmenu
Global $separator1, $viewmenu, $viewstatusitem, $okbutton, $cancelbutton
Global $msg, $file

$hWidth = 395
$hHeight = 425
$hLeft = $hWidth / 2
$hTop = $hHeight / 2

$hGUI = GUICreate("Spell Check Example", $hWidth, $hHeight, (@DesktopWidth / 2) - $hLeft, (@DesktopHeight / 2) - $hTop)

    $Label1 = GUICtrlCreateLabel("Editor", 5, 1, 100, 15)
    GUICtrlSetFont(-1, 9, 600)  
    
    $Edit1 = GUICtrlCreateEdit("Coutn adn splel", 5, 25, 385, 350, _
        BitOR($ES_AUTOVSCROLL, $ES_MULTILINE, $ES_NOHIDESEL, $ES_WANTRETURN))
    
    $Button1 = GUICtrlCreateButton("Spell Check", 325, 380) 
    
GUISetState()

$nOffset = 1

While 1
    $Msg = GUIGetMsg()
    Select
        Case $Msg = $GUI_EVENT_CLOSE
            Exit        
        Case $Msg = $Button1            
            _SpellCheck()
    EndSelect
WEnd

Func _SpellCheck()
    ;
    
    ;Select individual word.
    $array = StringRegExp(GUICtrlRead($Edit1), "[\s\.:;,]*([a-zA-Z0-9-_]+)[\s\.:;,]*", 3, $nOffset) 
    If @error = 0 Then
        $nOffset = @extended
    Else
        ;ExitLoop
    EndIf
    
    For $i = 0 to UBound($array) - 1
;~      msgbox(0, "RegExp Test with Option 1 - " & $i, $array[$i])
        
        $oIE = _IECreate("http://dictionary.reference.com/search?q=" & $array[$i], 0, 0)
        $oTable = _IETableGetCollection($oIE, 0)
        If IsObj($oTable) Then 
            $ar = _IETableWriteToArray($oTable, True)
            Global $ar[2][2]
;~          _ArrayDisplay($ar)          
            ConsoleWrite("Array Option- " & $ar[0][0])
            If $ar[0][0] = "Dictionary:" Then               
                ;Create ChildGUI
                ;Center Child GUI in Main GUI:  parent width/2 minus the child's width/2
                $cWidth = 250
                $cHeight = 250              
                $cLeft = $hWidth / 2 - $cWidth / 2
                $cTop = $hHeight /2 - $cHeight / 2
                $cGUI = GUICreate("Spell Check", $cWidth, $cHeight, $cLeft, $cTop, Default, BitOR($WS_EX_MDICHILD, $WS_EX_TOOLWINDOW), $hGUI)
                $Label1 = GUICtrlCreateLabel("Original Text:", 5, 5, 75, 20)
                $Label2 = GUICtrlCreateLabel("Replace With:", 5, 30, 75, 20)    
                $Input1 = GUICtrlCreateInput("", 100, 5, 145, 20)
                GUICtrlSetState(-1, $GUI_DISABLE)   ; the label is in disable state
                $Input2 = GUICtrlCreateInput("", 100, 30, 145, 20)
                $ListBox1 = GUICtrlCreateList("", 5, 55, 155, 200)
                $Button1 = GUICtrlCreateButton("Replace", 170, 65, 75, 20)
                $Button2 = GUICtrlCreateButton("Ignore", 170, 85, 75, 20)   
                $Button3 = GUICtrlCreateButton("Close", 170, 225, 75, 20)
                GUISetState(@SW_SHOW)
                
                ; Add files
                $sListData = ""
                For $i = 0 To UBound($ar, 2) -1
                   $ar2 = $ar[0][$i]
                Next
                GuiCtrlSetData($ListBox1, _ArrayToString($ar2))
                
                
                While 1

                    $aMsg = GUIGetMsg(1)

                    If $aMsg[1] = $cGUI Then ; Check we are getting messages from the child
                        Switch $aMsg[0]
                            Case $GUI_EVENT_CLOSE, $Button3
                                GUIDelete($cGUI)
                                ExitLoop
                            Case $Button1
                    
                            Case $Button2
                            
                            Case $ListBox1
                            
                        EndSwitch
                    EndIf

                WEnd
                
            EndIf
        EndIf
        _IEQuit($oIE)
    Next
        
EndFunc     ;==>_SpellCheck

Also Don't create controls in a function like that. Create them with the rest of the GUI controls.

GEOSoft,

Do you mean to create the Child GUI, the list, labels, buttons, and inputs underneath the Main GUI controls?

Thank you for your help,

jfcby


Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Share this post


Link to post
Share on other sites

Hi,

I'm still not understanding something because I made the following changes and now I am not getting an error but there is no data loaded into the listbox.

GEOSoft,

Do you mean to create the Child GUI, the list, labels, buttons, and inputs underneath the Main GUI controls?

Thank you for your help,

jfcby

Yes and then use GUISetState if you want to show or hide the window.

Try the code below. It should be what you want

; Add files  I still don't see what you are trying to accomplish here but it could be something that only you would know
$sListData = ""
For $i = 0 To UBound($ar, 2) -1
  $ar2 = $ar[0][$ar[$i]]
Next
GuiCtrlSetData($ListBox1, _ArrayToString($ar));;  I think this is what you want

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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