Jump to content

ControlID as function argument?


notta
 Share

Recommended Posts

Guys, I just threw this together and the logic may be all wrong, but I need to pass a controlID as a function parameter. In the example below I have 3 combo boxes with the numbers 1-4. When a user picks a number for the first control, say 3, I want the second control to be 1,2,4. I don't want to display 3 in the second one since 3 has already been chosen. Instead of writing a function for each I was hoping to use one function and just pass the controlID as an argument. Can this be done somehow?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $array[5] = [4,"one","two","three","four"]

$gui = GUICreate("Test")

$combo1 = GUICtrlCreateCombo("",10,20)
GUICtrlSetData($combo1,"one|two|three|four")
$combo2 = GUICtrlCreateCombo("",10,40)
$combo3 = GUICtrlCreateCombo("",10,60)

GUISetState(@SW_SHOW)



While 1
        $msg = GUIGetMsg()

        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
        
        if $msg = $combo1 Then
            _createComboList(GUICtrlRead($combo2),$combo2);<== I need to pass combo2 controlID 
        EndIf
        
        if $msg = $combo2 Then
            _createComboList(GUICtrlRead($combo3),$combo3);<== I need to pass combo3 controlID 
        EndIf
WEnd
GUIDelete()


Func _createComboList($c,$id)
    
    for $i = 1 To $array[0]
        if $array[$i] = $c Then
            ContinueLoop
        Else
            $tempVal &= $array[$i] & "|"
        EndIf
        
    Next
    
    $strip = StringTrimRight($tempVal,1)
    
    GUICtrlSetData($id,$strip);<==this is not going to work
    
EndFunc
Edited by notta
Link to comment
Share on other sites

I think I got it. I added an array of controls.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $array[5] = [4,"one","two","three","four"]

$gui = GUICreate("Test")

$combo1 = GUICtrlCreateCombo("",10,20)
GUICtrlSetData($combo1,"one|two|three|four")
$combo2 = GUICtrlCreateCombo("",10,40)
$combo3 = GUICtrlCreateCombo("",10,60)

Global $aCombos[4] = [3,$combo1,$combo2,$combo3] ;<== Add an array of controls

GUISetState(@SW_SHOW)



While 1
        $msg = GUIGetMsg()

        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
        
        if $msg = $combo1 Then
            _createComboList(GUICtrlRead($combo1),$aCombos[2]);<== I need to pass combo2 controlID 
        EndIf
        
        if $msg = $combo2 Then
            _createComboList(GUICtrlRead($combo2),$aCombos[3]);<== I need to pass combo3 controlID 
        EndIf
WEnd
GUIDelete()


Func _createComboList($c,$id)
    
    Local $tempVal = ""
    
    
    for $i = 1 To $array[0]
        MsgBox(0,"",$array[$i] & " = " & $c)
        if $array[$i] = $c Then
            ContinueLoop
        Else
            $tempVal &= $array[$i] & "|"
        EndIf
        
    Next
    
    $strip = StringTrimRight($tempVal,1)
    
    GUICtrlSetData($id,$strip) ;<==this is not going to work
    
EndFunc
Link to comment
Share on other sites

Like This!!!...???

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

Global $Data = "one|two|three|four"
Global $array = StringSplit($Data, "|")

$gui = GUICreate("Test")

$combo1 = GUICtrlCreateCombo("", 10, 20)
GUICtrlSetData($combo1, $Data)
$combo2 = GUICtrlCreateCombo("", 10, 40)
$combo3 = GUICtrlCreateCombo("", 10, 60)

GUISetState(@SW_SHOW)



While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop

    If $msg = $combo1 Then
        _createComboList(GUICtrlRead($combo1), $combo2);<== I need to pass combo2 controlID
    EndIf

    If $msg = $combo2 Then
        _createComboList(GUICtrlRead($combo2), $combo3);<== I need to pass combo3 controlID
    EndIf
WEnd
GUIDelete()


Func _createComboList($c, $id)
    Local $tempVal = "", $tempNum = ""
    For $i = 1 To UBound($array) - 1
        If $array[$i] = $c Then
            $tempNum = $i
        Else
            $tempVal &= $array[$i] & "|"
        EndIf

    Next
    _ArrayDelete($array, $tempNum)
    $strip = StringTrimRight($tempVal, 1)

    GUICtrlSetData($id, $strip)

EndFunc   ;==>_createComboList

8)

NEWHeader1.png

Link to comment
Share on other sites

Like This!!!...???

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

Global $Data = "one|two|three|four"
Global $array = StringSplit($Data, "|")

$gui = GUICreate("Test")

$combo1 = GUICtrlCreateCombo("", 10, 20)
GUICtrlSetData($combo1, $Data)
$combo2 = GUICtrlCreateCombo("", 10, 40)
$combo3 = GUICtrlCreateCombo("", 10, 60)

GUISetState(@SW_SHOW)



While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop

    If $msg = $combo1 Then
        _createComboList(GUICtrlRead($combo1), $combo2);<== I need to pass combo2 controlID
    EndIf

    If $msg = $combo2 Then
        _createComboList(GUICtrlRead($combo2), $combo3);<== I need to pass combo3 controlID
    EndIf
WEnd
GUIDelete()


Func _createComboList($c, $id)
    Local $tempVal = "", $tempNum = ""
    For $i = 1 To UBound($array) - 1
        If $array[$i] = $c Then
            $tempNum = $i
        Else
            $tempVal &= $array[$i] & "|"
        EndIf

    Next
    _ArrayDelete($array, $tempNum)
    $strip = StringTrimRight($tempVal, 1)

    GUICtrlSetData($id, $strip)

EndFunc   ;==>_createComboList

8)

Yep, that works as well, but it seems you can pass a controlID because you didn't change it and it worked. I thought when the control was passed it would be evaluated as some number. Your post actually dealt with the next problem I was going to have to deal with though. The way I wrote it combo3 would not show what was chosen in combo2, but the value from combo1 would be back.

hmm, you answered my question about using a controlID as a function argument, but using ArrayDelete is not going to work for this as well. You cannot go back and change your answers because the values have been deleted from the array. Anyway, you answered my question and I'll figure this out. Thanks,

Link to comment
Share on other sites

Maybe...

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

Global $array, $Data = "one|two|three|four"


$gui = GUICreate("Test")

$combo1 = GUICtrlCreateCombo("", 10, 20)
GUICtrlSetData($combo1, $Data)
$combo2 = GUICtrlCreateCombo("", 10, 40)
$combo3 = GUICtrlCreateCombo("", 10, 60)

$button = GUICtrlCreateButton("Reset", 150, 100, 60, 25) 

GUISetState(@SW_SHOW)


_Reset_Array()


While 1
    $msg = GUIGetMsg()
    
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        
        Case $combo1
            _createComboList(GUICtrlRead($combo1), $combo2)
            
        Case $combo2
             _createComboList(GUICtrlRead($combo2), $combo3)
             
        Case $button
            _Reset_Array()
            
    EndSwitch
            
WEnd
GUIDelete()


Func _createComboList($c, $id)
    Local $tempVal = "", $tempNum = ""
    For $i = 1 To UBound($array) - 1
        If $array[$i] = $c Then
            $tempNum = $i
        Else
            $tempVal &= $array[$i] & "|"
        EndIf

    Next
    _ArrayDelete($array, $tempNum)
    $strip = StringTrimRight($tempVal, 1)

    GUICtrlSetData($id, $strip)

EndFunc   ;==>_createComboList

Func _Reset_Array()
    $array = StringSplit($Data, "|")
    GUICtrlSetData( $combo2, "")
    GUICtrlSetData( $combo3, "")
EndFunc

8)

NEWHeader1.png

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