Jump to content

SOLVED Help getting $variable = "" in to a dropdown list using GUICtrlCreateCombo and GUICtrlSetData


Recommended Posts

Please could someone help!

I'm creating a GUI Script that allows a user to match a drop-down list of address fields to the corresponding field in a system I manage (see sample script below).

The problem is that some of the options in the drop-down list may be blank. When the script creates the drop-down lists in the GUI, if the variable is blank that option and the one above do not show. As soon as I declare some text in the variable the GUI shows the options correctly

#include <GUIconstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIcoordMode", 2)
;****************************************************************************************
;* The 5 lines below will not form part of final script                              *
;* $rAddress1, 2, 3, 4, $rPostCode will be populated by cells from an Excel spreadsheet *
;****************************************************************************************
Global $rAddress1 = "1 Some Street"
Global $rAddress2 = "" ; <----- If some text between the quotes here, the GUI Shows the drop-down options correctly.
Global $rAddress3 = "ATown"
Global $rAddress4 = "ACounty"
Global $rPostCode = "AA1 1AA"
Global $add1 = $rAddress1
Global $add2 = $rAddress2
Global $add3 = $rAddress3
Global $add4 = $rAddress4
Global $pc = $rPostCode
Global $array[5]
$array[0] = $add1
$array[1] = $add2
$array[2] = $add3
$array[3] = $add4
$array[4] = $pc
GUICreate("Address Selecter", 280, 230)
GUIStartGroup()
Global $widthCell = 125
; Address 1 option
GUICtrlCreateLabel("Marketplace Address 1", 10, 10, $widthCell)
Global $sAddress1 = GUICtrlCreateCombo("", 0, -1)
For $i=0 to ubound($array) -1
    GUICtrlSetData(-1, $array[$i])
NEXT
; Address 2 option
GUICtrlCreateLabel("Marketplace Address 2", -2 * $widthCell, 10)
Global $sAddress2 = GUICtrlCreateCombo("", 0, -1)
For $i=0 to ubound($array) -1
    GUICtrlSetData(-1, $array[$i])
NEXT
; City option
GUICtrlCreateLabel("Marketplace City", -2 * $widthCell, 10)
Global $sCity = GUICtrlCreateCombo("", 0, -1)
For $i=0 to ubound($array) -1
    GUICtrlSetData(-1, $array[$i])
NEXT
; County option
GUICtrlCreateLabel("Marketplace County", -2 * $widthCell, 10)
Global $sCounty = GUICtrlCreateCombo("", 0, -1)
For $i=0 to ubound($array) -1
    GUICtrlSetData(-1, $array[$i])
NEXT
; Post Code option
GUICtrlCreateLabel("Marketplace Post Code", -2 * $widthCell, 10)
Global $sPostCode = GUICtrlCreateCombo("", 0, -1)
For $i=0 to ubound($array) -1
    GUICtrlSetData(-1, $array[$i], $array[4])
NEXT
Global $button_1 = GUICtrlCreateButton ("Ok", -1, 20, 120, 35)
GUISetState()
While 1
$msg = GUIGetMsg()
Select
  Case $msg = $GUI_EVENT_CLOSE
  SplashTextOn("Exiting", "Exiting the script.  Please re-run", 190, 100, -1, -1, 4, "", -1, 1000)
  Sleep(1500)
  SplashOff()
  Exit
  Case $msg = $button_1
   ExitLoop
EndSelect
WEnd
msgbox(0, "Selected Address", "Address1: " & GUICtrlRead($sAddress1) & " | Address2: " & GUICtrlRead($sAddress2) & " | City: " & GUICtrlRead($sCity) & " | County: " & GUICtrlRead($sCounty) & " | Post Code: " & GUICtrlRead($sPostCode))
GUIDelete()

Many thanks in advance.

Edited by mdcastle
Link to comment
Share on other sites

Try

Global $rAddress2 = " " ; <----- If some text between the quotes here, the GUI Shows the drop-down options correctly.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

mdcastle,

What a complicated way to fill your combos! :)

Anyway, if you want a blank element in your combo list, you need to fill it all in one go like this: :)

#include <guiconstants.au3>
#include <comboconstants.au3>
#include <editconstants.au3>
#include <windowsconstants.au3>

Opt("GUIcoordMode", 2)
;****************************************************************************************
;* The 5 lines below will not form part of final script                           *
;* $rAddress1, 2, 3, 4, $rPostCode will be populated by cells from an Excel spreadsheet *
;****************************************************************************************
Global $rAddress1 = "1 Some Street"
Global $rAddress2 = "" ; <----- If some text between the quotes here, the GUI Shows the drop-down options correctly.
Global $rAddress3 = "ATown"
Global $rAddress4 = "ACounty"
Global $rPostCode = "AA1 1AA"
Global $add1 = $rAddress1
Global $add2 = $rAddress2
Global $add3 = $rAddress3
Global $add4 = $rAddress4
Global $pc = $rPostCode

Global $array[5]
$array[0] = $add1
$array[1] = $add2
$array[2] = $add3
$array[3] = $add4
$array[4] = $pc

; Create a single string to fill the combo <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Global $sFullList = ""
For $i = 0 To UBound($array) - 1
    $sFullList &= "|" & $array[$i]
Next

GUICreate("Address Selecter", 280, 230)
GUIStartGroup()
Global $widthCell = 125
; Address 1 option
GUICtrlCreateLabel("Marketplace Address 1", 10, 10, $widthCell)
Global $sAddress1 = GUICtrlCreateCombo("", 0, -1)
GUICtrlSetData(-1, $sFullList) ; And load it in a single operation ; <<<<<<<<<<<<<<<<<<<<<<<<<<
; Address 2 option
GUICtrlCreateLabel("Marketplace Address 2", -2 * $widthCell, 10)
Global $sAddress2 = GUICtrlCreateCombo("", 0, -1)
GUICtrlSetData(-1, $sFullList); City option
GUICtrlCreateLabel("Marketplace City", -2 * $widthCell, 10)
Global $sCity = GUICtrlCreateCombo("", 0, -1)
GUICtrlSetData(-1, $sFullList); County option
GUICtrlCreateLabel("Marketplace County", -2 * $widthCell, 10)
Global $sCounty = GUICtrlCreateCombo("", 0, -1)
GUICtrlSetData(-1, $sFullList); Post Code option
GUICtrlCreateLabel("Marketplace Post Code", -2 * $widthCell, 10)
Global $sPostCode = GUICtrlCreateCombo("", 0, -1)
GUICtrlSetData(-1, $sFullList)
Global $button_1 = GUICtrlCreateButton("Ok", -1, 20, 120, 35)
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            SplashTextOn("Exiting", "Exiting the script.  Please re-run", 190, 100, -1, -1, 4, "", -1, 1000)
            Sleep(1500)
            SplashOff()
            Exit
        Case $msg = $button_1
            ExitLoop
    EndSelect
WEnd
MsgBox(0, "Selected Address", "Address1: " & GUICtrlRead($sAddress1) & " | Address2: " & GUICtrlRead($sAddress2) & " | City: " & GUICtrlRead($sCity) & " | County: " & GUICtrlRead($sCounty) & " | Post Code: " & GUICtrlRead($sPostCode))
GUIDelete()

Now you get yoru blank line. ;)

M23</windowsconstants.au3></editconstants.au3></comboconstants.au3></guiconstants.au3>

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

 

Link to comment
Share on other sites

What a complicated way to fill your combos! :)

I'm not surprised that i found the most complicated way to do this! ;) I'm very much a beginner at all things scripting so please be gentle :) .

Many thanks for your help.

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