Jump to content

GuiCtrlCreateLabel not working right


Recommended Posts

Version 3.1.1.37 is not replacing the GuiCtrlCreateLabel values on the Gui when choosing a new selection. Instead, it is writing the new values on top of the old.

Any Ideas???

#include <GUIConstants.au3>
#include <File.au3>

$in_filename = "test_csv.csv"
Dim $lines,$Display, $NumCols
_FileReadToArray($in_filename, $lines)
$Columns = StringSplit($lines[1], ",")
$NumCols=$Columns[0]
Dim $array[ $lines[0] ][ $Columns[0] ]
For $i = 1 To $lines[0]
    $Columns = StringSplit($lines[$i], ",")
    If $Columns[0] = 1 Then Continueloop
    For $j = 1 To $Columns[0]
        $array[$i-1][$j-1] = $Columns[$j]
    Next
Next
$Rows=$Lines[0]-1
For $i = 1 To $lines[0]-1
;---------------------------------------------------------------------
;Display Entire CSV File converted to a multi-dimensional Array
;---------------------------------------------------------------------
  For $j = 1 To $NumCols
  $Display  = $Display&"array["&String($i-1)&"]["&String($j-1)&"]="&chr(9)&$array[$i-1][$j-1]&@CRLF
  Next
Next
;MsgBox(0,"Entire test.csv file", $Display)
;---------------------------------------------------------------------
;Get the contents of Column A for every row and Add a "|" at the end 
;of each item so that GuiCtrlCreateCombo works properly
;---------------------------------------------------------------------
Dim $ColumnA, $AllColumnA, $H_cmbA, $H_ComboBox, $H_Return
$M = 0
While $m <= $Rows -1
    $ColumnA=$Array[$m][0] & "|"
    $m = $m + 1
    $AllColumnA=$AllColumnA & $ColumnA
Wend
;---------------------------------------------------------------------
;Display the contents of Column A in a GuiCtrlCreateCombo
;  Display Column B contents in an GuiCtrlCreateLabel
;  Display Column C contents in a GuiCtrlCreateLabel 
;---------------------------------------------------------------------
GUICreate("ComboBox View",600,100,-1,40)
$h_cmbA = GUICtrlCreateCombo("", 10,10,90)
GUICtrlSetData(-1,$AllColumnA)
GUISetState (@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
    case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    case $msg = $h_cmbA
        GuiCtrlCreateLabel(_GUICtrlComboBoxIndex($h_cmbA),110,13,90,30)
        GuiCtrlCreateLabel($Array[$H_Return][2],210,13,30,30)
;       GuiCtrlCreateLabel($Array[$H_Return][3],340,13,130,30)
;       GuiCtrlCreateLabel($Array[$H_Return][4],480,13,230,30)
    endselect
Wend
;---------------------------------------------------------------------
;Function used with "Display the contents of Column A in a ComboBox"
;  Returns the row (aka Line Number) for the item selected
;  Returns the data contained in Columns B, C, and D
;---------------------------------------------------------------------
Func _GUICtrlComboBoxIndex($H_ComboBox)
    Dim $CB_GETCURSEL = 0x147
    $H_Return = GUICtrlSendMsg ( $H_ComboBox, $CB_GETCURSEL , 0, 0 )
    $H_ComboBox = $Array[$H_Return][1]
    Return $H_ComboBox
    Return $H_Return
EndFunc
Link to comment
Share on other sites

No, not confused at all...The ComboBox is working perfectly; however, the GuiCtrlCreateLabel is not erasing the previous value on the GUI when another choice is made. The new label value is written on top of the old; creating a mess.

I installed the release version of AutoIT3 and the label works fine.

I've looked through the Beta version helpfile; but so far, nothing has caught my eye as to why GuiCtrlCreateLabel doesn't erase the previous value on the GUI before placing a new one in its place.

Link to comment
Share on other sites

No, not confused at all...The ComboBox is working perfectly; however, the GuiCtrlCreateLabel is not erasing the previous value on the GUI when another choice is made.  The new label value is written on top of the old; creating a mess.

I installed the release version of AutoIT3 and the label works fine.

I've looked through the Beta version helpfile; but so far, nothing has caught my eye as to why GuiCtrlCreateLabel doesn't erase the previous value on the GUI before placing a new one in its place.

<{POST_SNAPBACK}>

If you want to update a label you need to to use GUICtrlSetData not to recreate a new label on the same position. Perhaps it was working different before but update must be done with GUICtrlSetData.

can you attach a sample of the .csv you are using so I can see the behaviour you experience.

Thanks :(

Link to comment
Share on other sites

Here is a WinZiped example of the Test_csv.csv file

<{POST_SNAPBACK}>

here is the script working with the GUICtrlSetData as I mentionned.
#include <GUIConstants.au3>
#include <File.au3>

$in_filename = "test_csv.csv"
Dim $lines,$Display, $NumCols
_FileReadToArray($in_filename, $lines)
$Columns = StringSplit($lines[1], ",")
$NumCols=$Columns[0]
Dim $array[ $lines[0] ][ $Columns[0] ]
For $i = 1 To $lines[0]
    $Columns = StringSplit($lines[$i], ",")
    If $Columns[0] = 1 Then Continueloop
    For $j = 1 To $Columns[0]
        $array[$i-1][$j-1] = $Columns[$j]
    Next
Next
$Rows=$Lines[0]-1
For $i = 1 To $lines[0]-1
;---------------------------------------------------------------------
;Display Entire CSV File converted to a multi-dimensional Array
;---------------------------------------------------------------------
  For $j = 1 To $NumCols
  $Display  = $Display&"array["&String($i-1)&"]["&String($j-1)&"]="&chr(9)&$array[$i-1][$j-1]&@CRLF
  Next
Next
;MsgBox(0,"Entire test.csv file", $Display)
;---------------------------------------------------------------------
;Get the contents of Column A for every row and Add a "|" at the end 
;of each item so that GuiCtrlCreateCombo works properly
;---------------------------------------------------------------------
Dim $ColumnA, $AllColumnA, $H_cmbA, $H_ComboBox, $H_Return
$M = 0
While $m <= $Rows -1
    $ColumnA=$Array[$m][0] & "|"
    $m = $m + 1
    $AllColumnA=$AllColumnA & $ColumnA
Wend
;---------------------------------------------------------------------
;Display the contents of Column A in a GuiCtrlCreateCombo
;  Display Column B contents in an GuiCtrlCreateLabel
;  Display Column C contents in a GuiCtrlCreateLabel 
;---------------------------------------------------------------------
GUICreate("ComboBox View",600,100,-1,40)
$h_cmbA = GUICtrlCreateCombo("", 10,10,90)
GUICtrlSetData(-1,$AllColumnA)
 $label1=      GuiCtrlCreateLabel("",110,13,90,30); >>>>>>>>>>
 $label2=      GuiCtrlCreateLabel("",210,13,30,30);>>>>>>>>>>>>>
GUISetState (@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
    case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    case $msg = $h_cmbA
        GuiCtrlSetData($label1,_GUICtrlComboBoxIndex($h_cmbA));>>>>>>>
        GuiCtrlSetData($label2, $Array[$H_Return][2]);>>>>>>>>>>>>>
;       GuiCtrlCreateLabel($Array[$H_Return][3],340,13,130,30)
;       GuiCtrlCreateLabel($Array[$H_Return][4],480,13,230,30)
    endselect
Wend
;---------------------------------------------------------------------
;Function used with "Display the contents of Column A in a ComboBox"
;  Returns the row (aka Line Number) for the item selected
;  Returns the data contained in Columns B, C, and D
;---------------------------------------------------------------------
Func _GUICtrlComboBoxIndex($H_ComboBox)
    Dim $CB_GETCURSEL = 0x147
    $H_Return = GUICtrlSendMsg ( $H_ComboBox, $CB_GETCURSEL , 0, 0 )
    $H_ComboBox = $Array[$H_Return][1]
    Return $H_ComboBox
    Return $H_Return; <<<<<<<<<<<< never executed
EndFunc

the modified line are marked with >>>>>>>>>>>

something strange I didn't analyse is the return maked <<<<<<<<< in the function.

You can return only one value if you want to return more you can return an array or update a parameter pass by ref or update a global variable :(

Link to comment
Share on other sites

The ability to return only one item is indeed a change from the released version. 

<{POST_SNAPBACK}>

No reread the doc the "return" statement return so the next "return" will never be executed. IT IS NOT A CHANGE FROM THE RELASE VERSION
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...