Jump to content
amosrinat

FileOpenDialog doesn't work with combo

Recommended Posts

Posted (edited)

I have created a script at which there are three combo boxes in separate functions and a Button configured to open a FileOpenDialog.

This dialog doesn't work unless I disable the line AutoItSetOption('GUIOnEventMode', 1). 

Please help.

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



AutoItSetOption('GUIOnEventMode', 1)

$_1 = GUICreate("LanSweeper Update tool", 537, 356, 248, 137)
$Button2 = GUICtrlCreateButton("Exit", 390, 236, 75, 25, 0)
$CsvInput1 = GUICtrlCreateInput("", 145, 19, 225, 21)


$Button1 = GUICtrlCreateButton("Browse...", 390, 16, 75, 25, 0)

GUISetOnEvent($GUI_EVENT_CLOSE, 'quit')

$combo1 = GUICtrlCreateCombo("", 42, 146, 120, 25)
GUICtrlSetData(-1, 'Computer_Name|Business_Owner|Group')
GUICtrlSetOnEvent($combo1, 'setgrp')

$combo2 = GUICtrlCreateCombo('', 42, 186, 120, 25)
GUICtrlSetOnEvent($combo2, 'fSetgrp2')

$combo3 = GUICtrlCreateCombo('', 42, 226, 120, 25)

$Checkbox1 = GUICtrlCreateCheckbox("Check to enable specific selection in LanSweeper", 40, 72, 273, 17)
$Label1 = GUICtrlCreateLabel("Select to match SQL (combo) with input csv", 40, 118, 211, 17)

$Input1 = GUICtrlCreateInput("", 145, 19, 225, 21)
$Label2 = GUICtrlCreateLabel("sdf", 180, 150, 108, 25)
$Label3 = GUICtrlCreateLabel("sdfg", 180, 190, 108, 25)
$Label4 = GUICtrlCreateLabel("sdf", 180, 230, 108, 25)


GUISetState()

;~ While 1
;~     Sleep(50)

;~ WEnd


while 1

    $nMsg = GUIGetMsg()
    Local $line,$List,$col,$arrCsv,$sHdr1

    Select
        Case $nMsg = $GUI_EVENT_CLOSE Or $nMsg = $Button2
            Exit
        Case $nMsg = $Button1
            $csv=FileOpenDialog("Open", "C:\" ,"csv files (*.csv)")
            GUICtrlSetData($Input1,$csv)

;~             _FileReadToArray($csv,$arrCsv,Default,",");[R][C]
;~             _ArrayDisplay($arrCsv)
;~             $sHdr1 = $arrCsv[1][0]
;~             $sHdr2 = $arrCsv[1][1]
;~             $sHdr3 = $arrCsv[1][2]
;~             GUICtrlSetData($Label2,$sHdr1)
;~             GUICtrlSetData($Label3,$sHdr2)
;~             GUICtrlSetData($Label4,$sHdr3)
            ;;; Computer,  B.Owner,   Group

;~             MsgBox(0,"",$sHdr1 & " " & $sHdr2 &" " & $sHdr3)
    EndSelect
WEnd

Func setgrp()
    Global $c_msg = GUICtrlRead($combo1)
    Switch $c_msg
        Case 'Computer_Name'
            GUICtrlSetData($combo2, '')
            GUICtrlSetData($combo2, 'Business_Owner|Group')
        Case 'Business_Owner'
            GUICtrlSetData($combo2, '')
            GUICtrlSetData($combo2, 'Computer_Name|Group')
        Case 'Group'
            GUICtrlSetData($combo2, '')
            GUICtrlSetData($combo2, 'Computer_Name|Business_Owner')
    EndSwitch
EndFunc

Func fSetgrp2()
    $c_msg2 = GuictrlRead($combo2)
        Switch $c_msg2
            Case 'Computer_Name'
                GUICtrlSetData($combo3, '')
                $sMsg = StringReplace('Business_Owner|Group',$c_msg,"")
                GUICtrlSetData($combo3,$sMsg)
            Case 'Business_Owner'
                GUICtrlSetData($combo3, '')
                $sMsg = StringReplace('Computer_Name|Group',$c_msg,"")
                GUICtrlSetData($combo3,$sMsg)
            Case 'Group'
                GUICtrlSetData($combo3, '')
                $sMsg = StringReplace('Computer_Name|Business_Owner',$c_msg,"")
                GUICtrlSetData($combo3,$sMsg)
        EndSwitch
EndFunc

Func quit()
    Exit
EndFunc


 

Edited by Melba23
Added code tags

Share this post


Link to post
Share on other sites

amosrinat,

Welcome to the AutoIt forums.

You cannot mix OnEvent and MessageLoop in the same script. So you need to decide which you want to use as if you use OnEvent mode, GUIGetMsg will never return any events - once you disable OnEvent mode it starts working correctly, as you have discovered.

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

@amosrinat, as what Melba said, you can decide which is which. You can disable the OnEvent mode on [param] 0 "AutoItSetOption('GUIOnEventMode', 0)" or you may do a Func () code same as below to make you script working.

Func Button1()
      $csv=FileOpenDialog("Open", "C:\" ,"csv files (*.csv)")
      GUICtrlSetData($Input1,$csv)
EndFunc

 

 

KS15


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites

Thank you for your adivce,

I have changed the code (below) to include a fButton1 function and now nothing happens. the GUI shows for a second and disappears.

please advice.

Thanks,

Amos

------------------------ Code

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

AutoItSetOption('GUIOnEventMode', 1)

$_1 = GUICreate("LanSweeper Update tool", 537, 356, 248, 137)
$Button2 = GUICtrlCreateButton("Exit", 390, 236, 75, 25, 0)
$CsvInput1 = GUICtrlCreateInput("", 145, 19, 225, 21)

$Button1 = GUICtrlCreateButton("Browse...", 390, 16, 75, 25, 0)
GUICtrlSetOnEvent($Button1,'fButton1') ; *********** new line ************
GUISetOnEvent($GUI_EVENT_CLOSE, 'quit')

$combo1 = GUICtrlCreateCombo("", 42, 146, 120, 25)
GUICtrlSetData(-1, 'Computer_Name|Business_Owner|Group')
GUICtrlSetOnEvent($combo1, 'fsetgrp')

$combo2 = GUICtrlCreateCombo('', 42, 186, 120, 25)
GUICtrlSetOnEvent($combo2, 'fSetgrp2')

$combo3 = GUICtrlCreateCombo('', 42, 226, 120, 25)

$Checkbox1 = GUICtrlCreateCheckbox("Check to enable specific selection in LanSweeper", 40, 72, 273, 17)
$Label1 = GUICtrlCreateLabel("Select to match SQL (combo) with input csv", 40, 118, 211, 17)

$Input1 = GUICtrlCreateInput("", 145, 19, 225, 21)
$Label2 = GUICtrlCreateLabel("sdf", 180, 150, 108, 25)
$Label3 = GUICtrlCreateLabel("sdfg", 180, 190, 108, 25)
$Label4 = GUICtrlCreateLabel("sdf", 180, 230, 108, 25)

GUISetState()
Local $line,$List,$col,$arrCsv,$sHdr1
$nMsg = GUIGetMsg()

Func fButton1() ; ************ new function *********
        $csv=FileOpenDialog("Open", "C:\" ,"csv files (*.csv)")
        GUICtrlSetData($Input1,$csv)
EndFunc

Func fsetgrp()
    Global $c_msg = GUICtrlRead($combo1)
    Switch $c_msg
        Case 'Computer_Name'
            GUICtrlSetData($combo2, '')
            GUICtrlSetData($combo2, 'Business_Owner|Group')
        Case 'Business_Owner'
            GUICtrlSetData($combo2, '')
            GUICtrlSetData($combo2, 'Computer_Name|Group')
        Case 'Group'
            GUICtrlSetData($combo2, '')
            GUICtrlSetData($combo2, 'Computer_Name|Business_Owner')
    EndSwitch
EndFunc

Func fSetgrp2()
    $c_msg2 = GuictrlRead($combo2)
        Switch $c_msg2
            Case 'Computer_Name'
                GUICtrlSetData($combo3, '')
                $sMsg = StringReplace('Business_Owner|Group',$c_Msg,"")
                GUICtrlSetData($combo3,$sMsg)
            Case 'Business_Owner'
                    MsgBox(0,"",$c_msg2)
                GUICtrlSetData($combo3, '')
                $sMsg = StringReplace('Computer_Name|Group',$c_Msg,"")
                MsgBox(0,"",$sMsg)
                GUICtrlSetData($combo3,$sMsg)
            Case 'Group'
                GUICtrlSetData($combo3, '')
                $sMsg = StringReplace('Computer_Name|Business_Owner',$c_msg,"")
                GUICtrlSetData($combo3,$sMsg)
        EndSwitch
EndFunc

Func quit()
    Exit
EndFunc

----------------------------- End of code

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

×
×
  • Create New...