Jump to content

Arrrays


Recommended Posts

hehe, I've never dealt with arrays, and im trying to continously add to a combo box from arrays the user declares, but im having trouble making a loop that does it until theres no more existing arrays (and yes, I dont have any Idea what im talking about)

Func ComboBox($cTitle,$cText,$cButtonText,$cX,$cY)
GUICreate($cTitle, 193, 167, $cX, $cY)
$cCombo = GUICtrlCreateCombo("", 10, 136, 140, 25)
$cButton = GUICtrlCreateButton($cButtonText, 150, 136, 30, 25)
GUICtrlCreateLabel($cText, 10, 10, 169, 121)
GUISetState(@SW_SHOW)
$i=0
Do ;Problem Area
    GUICtrlSetData($cCombo,$ComboAdd[$i],GUICtrlRead($cCombo))
    $i=$i+1
Until @error = 1 ;erm... this is my try at it
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $cButton
            Return(GUICtrlRead($cCombo))
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
EndFunc

[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

Link to comment
Share on other sites

ok I guess I'll clear i up a bit:

Local $ComboAdd[4];truthfully, I dont know what this does
$ComboAdd[0] = "ONE"
$ComboAdd[1] = "TWO"
$ComboAdd[2] = "1"
$ComboAdd[3] = "2"
ComboBox("Test","Hey!","Ok",-1,-1)

Func ComboBox($cTitle,$cText,$cButtonText,$cX,$cY)
GUICreate($cTitle, 193, 167, $cX, $cY)
$cCombo = GUICtrlCreateCombo("", 10, 136, 140, 25)
$cButton = GUICtrlCreateButton($cButtonText, 150, 136, 30, 25)
GUICtrlCreateLabel($cText, 10, 10, 169, 121)
GUISetState(@SW_SHOW)
$i=0
Do;Problem Area
    GUICtrlSetData($cCombo,$ComboAdd[$i],GUICtrlRead($cCombo))
    $i=$i+1
Until @error = 1;erm... this is my try at it
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $cButton
            Return(GUICtrlRead($cCombo))
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
EndFunc

Array variable has incorrect number of subscripts or subscript dimension range exceeded

[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

Link to comment
Share on other sites

Local $ComboAdd[4];truthfully, I dont know what this does

This declares an array, the [4] is the number of subscripts it has.

[0]

[1]

[2]

[3]

Theres your 4.

When you add to it you need to do a

ReDim $Vari[uBound($Vari)+1]

In your case

ReDim $ComboAdd[uBound($ComboAdd)+1]

Link to comment
Share on other sites

now how do I stop it after the arrays dont exist anymore?

Do

Sleep(100)

GUICtrlSetData($cCombo,$ComboAdd[$i])

ReDim $ComboAdd[uBound($ComboAdd)+1]

Until <===============I don't know how to stop it

I tried @error = 1 but there appearently no error when it tries to use a non existant array...

Edited by MethodZero

[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

Link to comment
Share on other sites

now how do I stop it after the arrays dont exist anymore?

Do

Sleep(100)

GUICtrlSetData($cCombo,$ComboAdd[$i])

ReDim $ComboAdd[uBound($ComboAdd)+1]

Until <===============I don't know how to stop it

I tried @error = 1 but there appearently no error when it tries to use a non existant array...

Hi, try

;ComboAdd.au3
#include <GUIConstants.au3>
Local $ComboAdd[4];dimension of the array (number of elements)
$ComboAdd[0] = "ONE"
$ComboAdd[1] = "TWO"
$ComboAdd[2] = "1"
$ComboAdd[3] = "2"
ComboBox("Test", "Hey!", "Ok", -1, -1)

Func ComboBox($cTitle, $cText, $cButtonText, $cX, $cY)
    GUICreate($cTitle, 193, 167, $cX, $cY)
    $cCombo = GUICtrlCreateCombo($ComboAdd[0], 10, 136, 140, 25)
    $cButton = GUICtrlCreateButton($cButtonText, 150, 136, 30, 25)
    GUICtrlCreateLabel($cText, 10, 10, 169, 121)
    GUISetState(@SW_SHOW)
    $i = 0
    For $sArrayElement In $ComboAdd
        GUICtrlSetData($cCombo, $sArrayElement, GUICtrlRead($cCombo))
    Next
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $cButton
                Return (GUICtrlRead($cCombo))
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>ComboBox
Randall Edited by randallc
Link to comment
Share on other sites

thanks very very very very much!

Both of you, thank you!

[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

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...