Sign in to follow this  
Followers 0
marcoauto

ControlID of combo created dinamically

12 posts in this topic

Hi,

I need to create some combo in a gui, but the number of them are choose by the user.

I have do this (and this work):

For $c = 1 To $NumberofColumns
    for $r = 1 to $NumberofRows
      $EditControl[$c][$r] = GUICtrlCreateCombo($Control[$c][$r], $spazio_colonne+($larghezza_bottone+$spazio_colonne)*($c-1), $r *$spazio_righe + 10, $larghezza_bottone, $altezza_bottone, $CBS_DROPDOWNLIST)
      GUICtrlSetData(-1, $elenco)
   Next
   GUISetState()

but when I read the value of the combo, this value is always 0

For $c = 1 To $NumberofColumns
     for $r = 1 to $NumberofRows
      ConsoleWrite(GUICtrlRead($EditControl[$c][$r]))
     Next
    Next

If I create the combos with variabiles without array (es. $EditControl_1, $EditControl_2, ....) all works, but I can't create them dinamicaly

Is there a solution?

Grazie

marco

Share this post


Link to post
Share on other sites



Try this:

For $c = 1 To $NumberofColumns
  for $r = 1 to $NumberofRows
      ConsoleWrite($EditControl[$c][$r] & @CRLF)
;      ConsoleWrite(GUICtrlRead($EditControl[$c][$r]) & @CRLF)
   Next
Next

Also check if content of your array is not changed somewhere in your program.

Small reproducing script will be good to get more help.

Share this post


Link to post
Share on other sites

marcoauto,

Have you checked to make sure that you have sensible values in your $EditControl array? :D

I have no problems at all with this exampel script based on your snippets:

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

Global $aCombos[4][4]

$hGUI = GUICreate("Test", 500, 500)

For $i = 1 To 3
    For $j = 1 To 3
        $aCombos[$i][$j] = GUICtrlCreateCombo("", 10 + ($i * 100), 10 + ($j * 50), 80, 20)
        GUICtrlSetData(-1, "1|2|3|4|5", "1")
    Next
Next

$hButton = GUICtrlCreateButton("Read", 10, 400, 80, 30)

GUISetState()

_ArrayDisplay($aCombos, "Combo ControlIDs")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            For $i = 1 To 3
                For $j = 1 To 3
                    ConsoleWrite(GUICtrlRead($aCombos[$i][$j]) & @CRLF)
                Next
                ConsoleWrite(@CRLF)
            Next
    EndSwitch

WEnd

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Try this:

For $c = 1 To $NumberofColumns
  for $r = 1 to $NumberofRows
      ConsoleWrite($EditControl[$c][$r] & @CRLF)
;     ConsoleWrite(GUICtrlRead($EditControl[$c][$r]) & @CRLF)
   Next
Next

Also check if content of your array is not changed somewhere in your program.

Small reproducing script will be good to get more help.

I think I'm wrong somewhere in my scripts :-(

If I do

ConsoleWrite($EditControl[$c][$r] & @CRLF)

the result is

46
47
48
49
50
51
52
53
54

Share this post


Link to post
Share on other sites

marcoauto,

No, those values look as though they are perfectly sensible ControlIDs for your combos. However, I suggest that you add a similar line to check what ControlIDs are returned when you create the combos on order to check that they are the same. :D

And please post the whole script - we can then see if you have anything else in there which might cause a problem. :oops:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

marcoauto,

No, those values look as though they are perfectly sensible ControlIDs for your combos. However, I suggest that you add a similar line to check what ControlIDs are returned when you create the combos on order to check that they are the same. :D

And please post the whole script - we can then see if you have anything else in there which might cause a problem. :oops:

M23

Ok. This is my whole script. Is not finished.

The program read a file and parse it to find the values to use in the combos.

Also read a .ini file where are stored the default values and when the program will finished, I'll store the new values.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <Array.au3>
#Include <String.au3>
#include <EditConstants.au3>
 
Global $hChild, $fChild = False
$altezza_bottone = 26
$distanza_sinistra = 10
$larghezza_bottone = 150
$spazio_colonne = 30
$spazio_righe = 36
Global $Control[20][20]
Global $ButtonControl[20][20]
Global $EditControl[20][20]
Global $NumberofColumns = 7
Global $NumberofRows = 6
 
 
Global $chars
Global $elenco = ""
 
Global $ProgramSettingsFile = @ScriptDir & "\ABC_settings.ini"
 $Control[1][1] = IniRead($ProgramSettingsFile, "PLAYOUT1", "nome", "Not_Found")
 $Control[1][2] = IniRead($ProgramSettingsFile, "PLAYOUT1", "IP", "Not_Found")
 $Control[1][3] = IniRead($ProgramSettingsFile, "PLAYOUT1", "evento1", "Not_Found")
 $Control[1][4] = IniRead($ProgramSettingsFile, "PLAYOUT1", "evento2", "Not_Found")
$Control[1][5] = IniRead($ProgramSettingsFile, "PLAYOUT1", "evento3", "Not_Found")
 $Control[1][6] = IniRead($ProgramSettingsFile, "PLAYOUT1", "evento4", "Not_Found")
 $Control[1][7] = IniRead($ProgramSettingsFile, "PLAYOUT1", "evento5", "Not_Found")
 $Control[1][8] = IniRead($ProgramSettingsFile, "PLAYOUT1", "evento6", "Not_Found")
;~ ConsoleWrite ($P1n & $P1Ip & $P1e1 & $P1e2 & $P1e3 & $P1e4 & $P1e5 & $P1e6)
 
$hGUI = GUICreate("Test", 1290, 300)
 
$hButton = GUICtrlCreateButton("Setup", 10, 10, 80, 30)
 
GUISetState()
 
$file = FileOpen("file.txt", 0)
 
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
$chars = FileRead($file)
FileClose($file)
$array = StringRegExp($chars, '(?)0000000(.*?)(?)001100', 4)
for $i = 0 to UBound($array) - 1
    $match = $array[$i]
$elenco &= ($match[1]) & "|"
Next
 
For $c = 1 To $NumberofColumns
for $r = 1 to $NumberofRows
    $ButtonControl[$c][$r] = GUICtrlCreateButton($Control[$c][$r],$spazio_colonne+($larghezza_bottone+$spazio_colonne)*($c-1), $r *$spazio_righe + 10, $larghezza_bottone, $altezza_bottone)
GUICtrlSetOnEvent(-1, 'btnsfunc')
Next
Next
GUISetState()
 
Func quit()
    Exit
EndFunc
 
While 1
 
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            If $fChild Then
                GUISetState(@SW_ENABLE, $hGUI)
                GUIDelete($hChild)
                $fChild = False
For $c = 1 To $NumberofColumns
for $r = 1 to $NumberofRows
     ConsoleWrite($EditControl[$c][$r] & @CRLF)
;~  ConsoleWrite(GUICtrlRead($EditControl[$c][$r]) & @CRLF)
Next
Next
            Else
                Exit
            EndIf
        Case $hButton
            GUISetState(@SW_DISABLE, $hGUI)
            $fChild = True
$hChild =GUICreate('Setup',1290,300, -1, -1, -1, -1, $hGUI)
GUISetOnEvent($GUI_EVENT_CLOSE, 'quit')
For $c = 1 To 7 ; numero colonne (playout)
for $r = 1 to 6 ; numero righe (eventi: crawl ecc ecc)
If $r <= 2 Then
$EditControl[$c][$r] = GUICtrlCreateEdit("", $spazio_colonne+($larghezza_bottone+$spazio_colonne)*($c-1), $r *$spazio_righe + 10, $larghezza_bottone, $altezza_bottone, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN))
GUICtrlSetFont(-1, 10)
GUICtrlSetLimit(-1, 15)
Else
$EditControl[$c][$r] = GUICtrlCreateCombo($Control[$c][$r], $spazio_colonne+($larghezza_bottone+$spazio_colonne)*($c-1), $r *$spazio_righe + 10, $larghezza_bottone, $altezza_bottone, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, $elenco)
EndIf
Next
Next
GUISetState()
    EndSwitch
 
WEnd
 
Func btnsfunc()
    MsgBox(0, '', GUICtrlRead(@GUI_CtrlId))
EndFunc

and the file ABC_settings.ini is:

[PLAYOUT1]

nome = NameCh

IP = 192.168.1.111

evento1=test1file

evento2=test2file

evento3=test3file

evento4=test4file

evento5=test5file

evento6=test6file

Thanks

marco

Edited by marcoauto

Share this post


Link to post
Share on other sites

marcoauto,

I hope there is more than that to your script - try again! :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

marcoauto, I hope there is more than that to your script - try again! :oops: M23

:-)

To parse the file I use a symbol that the forum can't write :D

I have uploaded the whole script above

Share this post


Link to post
Share on other sites

marcoauto,

Look at this section of your script:

GUIDelete($hChild)
$fChild = False
For $c = 1 To $NumberofColumns
    For $r = 1 To $NumberofRows
        ConsoleWrite($EditControl[$c][$r] & @CRLF)
        ;~  ConsoleWrite(GUICtrlRead($EditControl[$c][$r]) & @CRLF)
    Next
Next

Now ask yourself in which GUI the Edit controls you are trying to read were created. Then ask yourself where that GUI is now - and you will underatand why you find it difficult to read them. :D

Got it? :oops:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

marcoauto,

Look at this section of your script:

GUIDelete($hChild)
$fChild = False
For $c = 1 To $NumberofColumns
    For $r = 1 To $NumberofRows
        ConsoleWrite($EditControl[$c][$r] & @CRLF)
        ;~  ConsoleWrite(GUICtrlRead($EditControl[$c][$r]) & @CRLF)
    Next
Next

Now ask yourself in which GUI the Edit controls you are trying to read were created. Then ask yourself where that GUI is now - and you will underatand why you find it difficult to read them. :)

Got it? :D

M23

:oops::D

ok, now it works

thankyou very much

:rip:

marco

Share this post


Link to post
Share on other sites

A NOTE TO ALL OUR READERS

Here is a classic case where the problem had nothing to do with the code snippets in the first post. So please do NOT just post small snippets of the code that you think is going wrong expecting us to determine the cause of your problems - post the complete script. If this is extremely long then YOU need to simplify it so that the problem remains and it does not take us too long to find. :D

Remember too that you wrote the code and know what it is supposed to do - we do not. We are happy to look for problems but please try to comment any complex sections of the code (in English) so we can see what is supposed to be happening. And please think about using Tidy to get the code into a readable format - how some of you manage to read your scripts at all given the chaotic layout of the code beats me! :)

So, if you post mere snippets of code, or a complex uncommented 3000 line script, you are unlikely to get a great deal of help. Please make it easy for us to help you. :oops:

M23

P.S. marcoauto - this is not directed at you more more than anyone else - you just acted as the catalyst! :rip:


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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