Sign in to follow this  
Followers 0
jazzyjeff

Combo Box not appearing

8 posts in this topic

I have a combo box with a list of products. When I choose a specific product, I want another Combox box to appear. I have this idea working in a script I have worked on before. When I use the same technique on this script, it just doesn't work.

Can someone please look at my code, and let me know what's wrong, because I can't figure it out. I thought it was fine.

The code I am interested in is in the Printer function:

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=D:\Icons\Icon.ico
#AutoIt3Wrapper_Run_Tidy=y
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/cs 1 /cn 1 /cf 1 /cv 1 /sf 1 /sv 1
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>

RegWrite("HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System", "EnableLUA", "REG_DWORD", "1")
RegWrite("HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultUserName", "REG_SZ", "Student")
RegWrite("HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "AutoAdminLogon", "REG_DWORD", "0")
RegDelete("HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword")
#region ### START Koda GUI section ### Form=
$FormMain = GUICreate("Student App Store", 426, 106, 192, 124, $WS_POPUPWINDOW)
$btnApps = GUICtrlCreateButton("Applications", 8, 8, 193, 89)
$btnPrinters = GUICtrlCreateButton("Printers", 224, 8, 193, 89)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            Shutdown(6)
        Case $btnApps
            _Apps()
        Case $btnPrinters
            _Printers()

    EndSwitch
WEnd

; Software Installs
Func _Apps()
    $Form1 = GUICreate("Student App Store", 500, 192, 201, 124, $WS_POPUPWINDOW)
    $listSoftware = GUICtrlCreateListView("", 8, 8, 400, 175)
    ; Add columns
    _GUICtrlListView_AddColumn($listSoftware, "Software", 120)
    ; Add items
    _GUICtrlListView_AddItem($listSoftware, "Adobe Flash")
    _GUICtrlListView_AddItem($listSoftware, "Adobe Reader")
    _GUICtrlListView_AddItem($listSoftware, "iTunes")
    _GUICtrlListView_AddItem($listSoftware, "Java")
    _GUICtrlListView_AddItem($listSoftware, "Skype")
    $btnInstall = GUICtrlCreateButton("&Install", 417, 112, 75, 25, $WS_GROUP)
    $btnExit = GUICtrlCreateButton("E&xit", 417, 160, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)

    While 2
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete($Form1)
                WinSetOnTop($FormMain, "", 1)
                ExitLoop
            Case $btnExit
                GUIDelete($Form1)
                WinSetOnTop($FormMain, "", 1)
                ExitLoop
            Case $btnInstall
                If _GUICtrlListView_GetItemSelected($listSoftware, 0) Then
                    _iAdobeFlash()
                ElseIf _GUICtrlListView_GetItemSelected($listSoftware, 1) Then
                    _iAdobeReader()
                EndIf

        EndSwitch
    WEnd
EndFunc   ;==>_Apps

Func _iAdobeFlash()

EndFunc   ;==>_iAdobeFlash

Func _iAdobeReader()

EndFunc   ;==>_iAdobeReader

; Printer Installs
Func _Printers()
    Local $comboPrinter, $btnInstallPrinter
    #region ### START Koda GUI section ### Form=
    $Form2 = GUICreate("Install Printer Drivers", 440, 35, -1, -1, $WS_POPUPWINDOW)
    $comboManufacturer = GUICtrlCreateCombo(" Select Manufacturer", 9, 8, 130, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $CBS_DROPDOWNLIST))
    GUICtrlSetData(-1, "Canon|Epson|HP|Lexmark")
    $btnSetManufacturer = GUICtrlCreateButton("Set", 150, 6, 35, 25)
    GUISetState(@SW_SHOW)
    #endregion ### END Koda GUI section ###
    WinSetOnTop("Install Printer Drivers", "", 1)

    While 3
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete($Form2)
                WinSetOnTop("Student App Store", "", 1)
                ExitLoop
            Case $btnSetManufacturer
                $rcomboManufacturer = GUICtrlRead($comboManufacturer)
                GUICtrlDelete($comboPrinter)
                If $rcomboManufacturer = "Canon" Then
                    $comboPrinter = GUICtrlCreateCombo(" Select Printer Model", 200, 8, 145, 25, BitOR($CBS_DROPDOWN, $CBS_SORT, $CBS_AUTOHSCROLL, $CBS_DROPDOWNLIST, $WS_VSCROLL))
                    GUICtrlSetData(-1, "Pixma MP280|Pixma MP250|Pixma MP270|Pixma MP495|Pixma MP490|Pixma MP560|Pixma MP640|Pixma MP990|Pixma MG8120|Pixma MG6120|Pixma MG5220|Pixma MG5120|Pixma iP100|Pixma iP4820|Pixma iP4700|Pixma iP3600|Pixma iP2702")
                ElseIf $rcomboManufacturer = "Epson" Then
                    $comboPrinter = GUICtrlCreateCombo(" Select Printer Model", 200, 8, 145, 25, BitOR($CBS_DROPDOWN, $CBS_SORT, $CBS_AUTOHSCROLL, $CBS_DROPDOWNLIST, $WS_VSCROLL))
                    GUICtrlSetData(-1, "725|835|320|325|520|630|635|840|NX510|NX305|NX215|NX420|NX625|Stylus C88+")
                ElseIf $rcomboManufacturer = "HP" Then
                    $comboPrinter = GUICtrlCreateCombo(" Select Printer Model", 200, 8, 145, 25, BitOR($CBS_DROPDOWN, $CBS_SORT, $CBS_AUTOHSCROLL, $CBS_DROPDOWNLIST, $WS_VSCROLL))
                    GUICtrlSetData(-1, "Photosmart D110a|Photosmart B210a|Photosmart C410a|Photosmart C310a|Photosmart C510a|Deskjet 1000|Deskjet 3050|Deskjet 3000")
                ElseIf $rcomboManufacturer = "Lexmark" Then
                    $comboPrinter = GUICtrlCreateCombo(" Select Printer Model", 200, 8, 145, 25, BitOR($CBS_DROPDOWN, $CBS_SORT, $CBS_AUTOHSCROLL, $CBS_DROPDOWNLIST, $WS_VSCROLL))
                    GUICtrlSetData(-1, "X2670|X5650ES|X5650|S305|S405|S505|PRO205|PRO705|S605|S815|S816|PRO905|PRO901|Z2420")
                EndIf
                $btnInstallPrinter = GUICtrlCreateButton("Install", 360, 6, 70, 25)
            Case $btnInstallPrinter
                $rComboPrinter = GUICtrlRead($comboPrinter)
                If $rComboPrinter = "Pixma MP560" Then
                    BlockInput(1)
                    Run("\\app2\apps$\6-12\One2World\Printers\Canon\MP560\mp560swin105ea24\DrvSetup\Setup.exe")
                    _WinWaitActivate("Welcome", "")
                    Send("{ALTDOWN}n{ALTUP}")
                    _WinWaitActivate("Select Your Place of Residence", "")
                    Send("{ALTDOWN}n{ALTUP}")
                    _WinWaitActivate("License Agreement", "")
                    Send("{ALTDOWN}y{ALTUP}")
                    BlockInput(0)
                    _WinWaitActivate("Installation Complete", "")
                    BlockInput(1)
                    Send("{ENTER}")
                    Shutdown(6)
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>_Printers

Func _WinWaitActivate($title, $text, $timeout = 0)
    WinWait($title, $text, $timeout)
    If Not WinActive($title, $text) Then WinActivate($title, $text)
    WinWaitActive($title, $text, $timeout)
EndFunc   ;==>_WinWaitActivate

Thanks for any help.

Jeff

Share this post


Link to post
Share on other sites



jazzyjeff,

Works for me - select a name in $comboManufacturer, press $btnSetManufacturer, then $comboPrinter and $btnInstallPrinter appear.

Or is that not what you meant? :unsure:

M23

P.S. You need some error-checking code to cover the case of no selection in $comboManufacturer - at the moment you only get $btnInstallPrinter and no $comboPrinter if no selection was made. :>


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

Thanks for the tip on the rro checking!

Well now I'm confused. I guess I am going to do what I should have done in the first place, and just compile the code and then see if it works on another machine. Maybe it's time for a reboot!

Thanks.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Maybe your script is losing track of what is the currently active GUI. Try the GUISwitch() function to set the GUI in which you want to create the new combo.

@Melba23

I hope you commented out the RegWrite/Deletes before testing...

Edited by wraithdu

Share this post


Link to post
Share on other sites

There is definitely something wrong with this code. The second loop seems to get stuck when I try and set a printer manufacturer in the combobox.

I tried the GUISwitch, but this didn't have any affect. I tried ExitLoop before the 2nd GUI opens, but this didn't work.

I'm a little stuck right now. I am running the latest AutoIT version.

Do you guys have any other ideas?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

jazzyjeff,

Try this cutdown version and see if it works for you: ;)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>

$FormMain = GUICreate("Student App Store", 426, 106, 192, 124, $WS_POPUPWINDOW)
$btnApps = GUICtrlCreateButton("Applications", 8, 8, 193, 89)
$btnPrinters = GUICtrlCreateButton("Printers", 224, 8, 193, 89)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $btnPrinters
            _Printers()
    EndSwitch
WEnd

; Printer Installs
Func _Printers()
    Local $comboPrinter, $btnInstallPrinter = 9999

    $Form2 = GUICreate("Install Printer Drivers", 440, 35, -1, -1, $WS_POPUPWINDOW)
    $comboManufacturer = GUICtrlCreateCombo(" Select Manufacturer", 9, 8, 130, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $CBS_DROPDOWNLIST))
    GUICtrlSetData(-1, "Canon|Epson|HP|Lexmark", "Canon")
    $btnSetManufacturer = GUICtrlCreateButton("Set", 150, 6, 35, 25)
    GUISetState(@SW_SHOW)
    WinSetOnTop("Install Printer Drivers", "", 1)

    While 3
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $btnSetManufacturer
                $rcomboManufacturer = GUICtrlRead($comboManufacturer)
                GUICtrlDelete($comboPrinter)
                If $rcomboManufacturer = "Canon" Then
                    $comboPrinter = GUICtrlCreateCombo(" Select Printer Model", 200, 8, 145, 25, BitOR($CBS_DROPDOWN, $CBS_SORT, $CBS_AUTOHSCROLL, $CBS_DROPDOWNLIST, $WS_VSCROLL))
                    GUICtrlSetData(-1, "Pixma MP280|Pixma MP250|Pixma MP270|Pixma MP495|Pixma MP490|Pixma MP560|Pixma MP640|Pixma MP990|Pixma MG8120|Pixma MG6120|Pixma MG5220|Pixma MG5120|Pixma iP100|Pixma iP4820|Pixma iP4700|Pixma iP3600|Pixma iP2702")
                ElseIf $rcomboManufacturer = "Epson" Then
                    $comboPrinter = GUICtrlCreateCombo(" Select Printer Model", 200, 8, 145, 25, BitOR($CBS_DROPDOWN, $CBS_SORT, $CBS_AUTOHSCROLL, $CBS_DROPDOWNLIST, $WS_VSCROLL))
                    GUICtrlSetData(-1, "725|835|320|325|520|630|635|840|NX510|NX305|NX215|NX420|NX625|Stylus C88+")
                ElseIf $rcomboManufacturer = "HP" Then
                    $comboPrinter = GUICtrlCreateCombo(" Select Printer Model", 200, 8, 145, 25, BitOR($CBS_DROPDOWN, $CBS_SORT, $CBS_AUTOHSCROLL, $CBS_DROPDOWNLIST, $WS_VSCROLL))
                    GUICtrlSetData(-1, "Photosmart D110a|Photosmart B210a|Photosmart C410a|Photosmart C310a|Photosmart C510a|Deskjet 1000|Deskjet 3050|Deskjet 3000")
                ElseIf $rcomboManufacturer = "Lexmark" Then
                    $comboPrinter = GUICtrlCreateCombo(" Select Printer Model", 200, 8, 145, 25, BitOR($CBS_DROPDOWN, $CBS_SORT, $CBS_AUTOHSCROLL, $CBS_DROPDOWNLIST, $WS_VSCROLL))
                    GUICtrlSetData(-1, "X2670|X5650ES|X5650|S305|S405|S505|PRO205|PRO705|S605|S815|S816|PRO905|PRO901|Z2420")
                EndIf
                $btnInstallPrinter = GUICtrlCreateButton("Install", 360, 6, 70, 25)
            Case $btnInstallPrinter
                $rComboPrinter = GUICtrlRead($comboPrinter)
                MsgBox(0, "Result", $rComboPrinter)
                GUIDelete($Form2)
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>_Printers

I did change a couple of things:

- Default combo option - so no need for errorchecking. :alien:

- Placeholder value for $btnInstallPrinter so it does not fire immediately (normal return from GUIGetMsg = 0)

Any luck? :huh2:

M23

wraithdu,

No worries - I always comment out Reg* stuff nowadays. I did not once and learnt my lesson the hard way! :ph34r:

Edited by Melba23

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

Ahhhh.... and I was just gonna feel all smart and stuff cause I figured it out too. You're right on about the placeholder value for $btnInstallPrinter. Although I would use GuiCtrlCreateDummy() so we get a safe control ID, then GuiCtrlDelete($btnInstallPrinter) before creating the actual button.

Your other tips are of course valid, but it's the undefined control ID that's causing the problems.

Share this post


Link to post
Share on other sites

You guys are awesome. Thanks very much for your help. Setting a Placeholder for the button variable did the trick.

Something new that I have learned now!

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