Jump to content

Drop Down Menu Not Loading Files


Recommended Posts

I am looking specifically at the area "Select a sample file:"

The drop down port does not work, but if I click it and use my arrow keys I can cycle through the list of files.

How do I get it to display the files?

Code:

#cs
Solution to that is to move the window to the same screen location every time the program is run or the loop recycles.
Or test to see if it's on the X/Y you want and if not, force it there.


Use this as example for input box field when testing submition: http://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_legend
#ce

#include <file.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <ComboConstants.au3>
#include <GuiComboBox.au3>


Global $a_csv
Global $listview
Global $checkboxName
Global $iCount
Global $runProg
Global $acheck
Global $mapColumn
Global $runProg
Global $selectInstrument


$s_Path = FileOpenDialog("Select CVS File", @ScriptDir, "comma seperated values (*.csv)")
If @error Then
    MsgBox(4096, "", "No File(s) chosen")
    Exit
Else

    _FileReadToArray($s_Path, $a_csv)
    buildGUI()



EndIf



Func copyToInput()
    ;$title = "(METTLER) - TGA-200A with gas box"
    ;$title = "HPOV"
                if GUICtrlRead($selectInstrument) = "dummy" Then
                    $textPos = 4
                    $title = "HPOV"
                ElseIf GUICtrlRead($selectInstrument) = "TGA-100" Then
                    $textPos = 35
                    $title = "(METTLER) - TGA-100A with gas box"
                ElseIf GUICtrlRead($selectInstrument) = "TGA-200" Then
                    $textPos = 44
                    $title = "(METTLER) - TGA-200A with gas box"
                ElseIf GUICtrlRead($selectInstrument) = "AUTOCAT-100" Then
                    $textPos = 75
                ElseIf GUICtrlRead($selectInstrument) = "AUTOCAT-200" Then
                    $textPos = 15
                EndIf


    $allRows =  _GUICtrlListView_GetItemCount($listview)
    For $rows = 0 to $allRows-1
        $material_name = _GUICtrlListView_GetItem($listview, $rows, 0)
        $letter = _GUICtrlListView_GetItem($listview, $rows, 3)
        ;where to input if statement so only checkbox that is checked runs????
        If GUICtrlRead($aCheck[1]) <> 1 and GUICtrlRead($aCheck[4]) <> 1 then continueloop
        If GUICtrlRead($aCheck[1]) = 1 Then
        controlsettext($title, "", $textPos, $material_name[3])
        endif
        #cs - 2nd input box
        If GUICtrlRead($aCheck[4]) = 1 Then
        controlsettext($title, "", 5, $letter[3])
        endif
        #ce

        controlclick($title, "", 6)

 Sleep(2000)
        ;there you can put some sleep(5000) = 5seconds, more or less, if u know exact applications processing time for this operation

        ;or ControlGetText("Myapplication title", "", CONTROL_WHICH_CHANGES_AFTER_BUTTONPRESS) and compare to older reads

        controlclick("Job", "", 2)

 Sleep(2000)
        ;there you can put some sleep(5000) = 5seconds, more or less, if u know exact applications processing time for this operation

        ;or ControlGetText("Myapplication title", "", CONTROL_WHICH_CHANGES_AFTER_BUTTONPRESS) and compare to older reads
if msgbox(1,"", "You Shall Not Pass!" & @CRLF & "Ok actually you can, just press something") = 2 then
    ExitLoop
endif

    Next
EndFunc

Func buildGUI()
    GUICreate("CSV Listview", 900, 450, -1, -1)
    $listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 400, 210)
    GUICtrlCreateLabel("Select a sample file:", 450, 40, 200)
    $selectFile = GUICtrlCreateCombo("", 450, 60, 180, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
    ;GUICtrlSetData($selectFile, @ScriptDir & '\*.csv')
    _GUICtrlComboBox_BeginUpdate($selectFile)
    _GUICtrlComboBox_AddDir($selectFile, @ScriptDir & "\*.csv")
    _GUICtrlComboBox_EndUpdate($selectFile)
    ;GUISetState(@SW_SHOW)


    GUICtrlCreateLabel("Select an instrument:", 700, 40, 200)
    $selectInstrument = GUICtrlCreateCombo("", 700, 60, 180, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
    GUICtrlSetData(-1, "dummy|TGA-100|TGA-200|AUTOCAT-100|AUTOCAT-200")
    $checkboxName = StringSplit($a_csv[1], ",")
    $iCount = $checkboxName[0]

    ;creating buttons
    Global $aCheck[$iCount + 1]
    Global $mapColumn[$iCount + 1]

    ;$nextSample = GUICtrlCreateButton("Map sample submition button ", 395, 320, 180, 30)
    $runProg = GUICtrlCreateButton("Run Program", 700, 400, 180, 30)
    GUICtrlSetState($runProg, $GUI_DISABLE)
    ;$btnStop = GUICtrlCreateButton("Stop", 700, 400, 180, 30)

     For $j = 1 To $iCount
        ; Store controIDs of the checkboxes
        $aCheck[$j] = GUICtrlCreateCheckbox($checkboxName[$j], 10, 190 + (50 * $j), 100, 30)
       ; $mapColumn[$j] = GUICtrlCreateButton("Map " & '"'  & $checkboxName[$j] & '"' & " to input box", 150, 190 + (50 * $j), 180, 30)
        GUICtrlSetState($aCheck[$j], $GUI_UNCHECKED)
       ; GUICtrlSetState($mapColumn[$j], $GUI_DISABLE)
            Next

    For $i = 2 To UBound($a_csv) - 1
        $s_temp = StringReplace($a_csv[$i], ",", "|")
        GUICtrlCreateListViewItem($s_temp, $listview)
    Next

    Global $aOut['']['']
    For $i = 2 to $a_csv[0]
        $aLine = stringsplit($a_csv[$i] , ",",3)
            If ubound($aLine) > ubound($aOut , 2) Then redim $aOut[$i][ubound($aLine)]
            _ArrayAdd($aOut , $a_csv[$i] , 0 , ",")
            ;consolewrite("line: "  & $aLine[2] & @LF)
    Next



    GUISetState()


        While 1
            $msg = GUIGetMsg()
            Switch $msg
                Case $GUI_EVENT_CLOSE
                    Exit

                Case $runProg
                    copyToInput()

                Case Else
                    For $i = 1 To $iCount
                        If $msg = $aCheck[$i] Then
                            If GUICtrlRead($msg) = 1 Then
                            ;   GUICtrlSetState($mapColumn[$i], $GUI_ENABLE)
                                GUICtrlSetState($runProg, $GUI_ENABLE)
;
;                           Local $text = ""
;                               For $k = 0 to $a_csv[0]-1
;                                 $text &= ControlListView ("CSV Listview", "", $listview, "GetText", $k, $i-1) & @crlf
;
                            ;   Next
                                ;Msgbox(0,$checkboxName[$i], $text) ; debug, can see the list of samples you selected
                            Else
                            ;GUICtrlSetState($mapColumn[$i], $GUI_DISABLE)
                            GUICtrlSetState($runProg, $GUI_DISABLE)
                            EndIf
                            ExitLoop
                        EndIf
                    Next
            EndSwitch
    WEnd

EndFunc

Thanks,

Tim

Link to comment
Share on other sites

Couple things that could help. :)

1. In copyToInput() using a switch/select statement would be more recommended. Like so:

Select
    Case GUICtrlRead($selectInstrument) = "dummy"
        $textPos = 4
        $title = "HPOV"
    Case GUICtrlRead($selectInstrument) = "TGA-100"
        $textPos = 35
        $title = "(METTLER) - TGA-100A with gas box"
    Case GUICtrlRead($selectInstrument) = "TGA-200" 
        $textPos = 44
        $title = "(METTLER) - TGA-200A with gas box"
    Case GUICtrlRead($selectInstrument) = "AUTOCAT-100"
        $textPos = 75
    Case GUICtrlRead($selectInstrument) = "AUTOCAT-200"
        $textPos = 15
EndSelect

2. The default style of GUICtrlCreateCombo is:

default (-1) : $CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL

So, using BitOR is not a necessity. 

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

 

Couple things that could help. :)

1. In copyToInput() using a switch/select statement would be more recommended. Like so:

Select
    Case GUICtrlRead($selectInstrument) = "dummy"
        $textPos = 4
        $title = "HPOV"
    Case GUICtrlRead($selectInstrument) = "TGA-100"
        $textPos = 35
        $title = "(METTLER) - TGA-100A with gas box"
    Case GUICtrlRead($selectInstrument) = "TGA-200" 
        $textPos = 44
        $title = "(METTLER) - TGA-200A with gas box"
    Case GUICtrlRead($selectInstrument) = "AUTOCAT-100"
        $textPos = 75
    Case GUICtrlRead($selectInstrument) = "AUTOCAT-200"
        $textPos = 15
EndSelect

2. The default style of GUICtrlCreateCombo is:

default (-1) : $CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL

So, using BitOR is not a necessity. 

 

Thanks for that switch statment.

But on the guicreatecombo, I am still unable to display the drop down list by clicking it, only able to cycle through the list with arrow keys and even though it only displays a single file at a time.

GUICtrlCreateLabel("Select a sample file:", 450, 40, 200)
    $selectFile = GUICtrlCreateCombo("", 450, 60, 180, 25)
    ;GUICtrlSetData($selectFile, @ScriptDir & '\*.csv')
    _GUICtrlComboBox_BeginUpdate($selectFile)
    _GUICtrlComboBox_AddDir($selectFile, @ScriptDir & "\*.csv")
    _GUICtrlComboBox_EndUpdate($selectFile)
    ;GUISetState(@SW_SHOW)
Link to comment
Share on other sites

How certain are you that _GUICtrlComboBox_AddDir() accepts wildcards?

Very confident, because this works just fine:

#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $idCombo

    ; Create GUI
    GUICreate("ComboBox Add Dir", 400, 296)
    $idCombo = GUICtrlCreateCombo("", 2, 2, 396, 296)
    GUISetState(@SW_SHOW)

    ; Add files
    _GUICtrlComboBox_BeginUpdate($idCombo)
    _GUICtrlComboBox_AddDir($idCombo, @ScriptDir & "\*.csv")
    _GUICtrlComboBox_EndUpdate($idCombo)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example
Link to comment
Share on other sites

 

Very confident, because this works just fine:

#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $idCombo

    ; Create GUI
    GUICreate("ComboBox Add Dir", 400, 296)
    $idCombo = GUICtrlCreateCombo("", 2, 2, 396, 296)
    GUISetState(@SW_SHOW)

    ; Add files
    _GUICtrlComboBox_BeginUpdate($idCombo)
    _GUICtrlComboBox_AddDir($idCombo, @ScriptDir & "\*.csv")
    _GUICtrlComboBox_EndUpdate($idCombo)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

MOTHER*(&*(&

It was because I did not set the box to allow enough characters through!

Being that it is now fixed.....

 

How do I create a button that once I select the file, will clear the current arrayFile and load the new file I selected?

Edited by timdecker
Link to comment
Share on other sites

How certain are you that _GUICtrlComboBox_AddDir() accepts wildcards?

 

Tested, works for me as well.

@TimDecker was about to point you to this post by Melba23 >link  :)

You'll need to make an event in your messageloop to catch the button click, like so:

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
           Exit
        Case $button
           ; do something
    EndSwitch
WEnd
Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

 

Tested, works for me as well.

@TimDecker was about to point you to this post by Melba23 >link  :)

You'll need to make an event in your messageloop to catch the button click, like so:

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
           Exit
        Case $button
           ; do something
    EndSwitch
WEnd

Well... I obviously don't know what I am doing because I tried this:

Case $loadNewFile
                    _FileReadToArray($selectFile,$a_csv)
                    buildGUI()

And it crashes when I click "Load File"...

Link to comment
Share on other sites

It could be you need the path to the file and not just the filename from your combobox.

@ScriptDir & "\" & $SelectFile
Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

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