Jump to content

Combo list controlles chr lenght in inputbox


Recommended Posts

Hello I am a noob to autoit and programming and have just startet a small project.

I have run into a problem I hope someone can help me with.

I have a GUI with a Inputbox & an Dropdown list(Combo list)

And what I want it to do is, when a name in the dropdown list is chosen, the inputbox gets a max charater length.

The different names in the dropdown list give different max charater length to the input box.

Here is a little exsample of what i have tried:

#include <ButtonConstants.au3>

#include <ComboConstants.au3>

#include <EditConstants.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

$GUIRecovery = GUICreate("Test ", 241, 203, 352, 256)

$NextB = GUICtrlCreateButton("Next", 8, 168, 225, 33, BitOR($BS_DEFPUSHBUTTON,$WS_GROUP), $WS_EX_STATICEDGE)

$PDROP = GUICtrlCreateCombo("", 28, 32, 97, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))

GUICtrlSetData($PDROP, "Asus|Clevo|Dell|Fujitsu|HP|LG|Lenovo|MSI|Medion|Packard Bell|Samsung|Sony|Toshiba|Zepto|")

$OSDROP = GUICtrlCreateCombo("Win7", 128, 88, 97, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))

GUICtrlSetData($OSDROP, "Vista|XP")

$RLabel = GUICtrlCreateLabel(" Model Nr:", 128, 120, 99, 17, $SS_CENTER)

$PNAVN = GUICtrlCreateLabel("Vælg PC Proucent", 128, 9, 101, 17)

$OSL = GUICtrlCreateLabel("Vælg OS Version", 128, 64, 94, 17)

$PDROPSTATE = GUICtrlRead($PDROP,1)

$OSDROPSTATE = GUICtrlRead($OSDROP,1)

If $PDROPSTATE = "Acer" Then

$DskName = GUICtrlCreateInput("", 128, 136, 105, 21,-1)

GUICtrlSetLimit($DskName, 5,4)

EndIf

If $PDROPSTATE = "HP" Then

$DskName = GUICtrlCreateInput("", 128, 136, 105, 21,-1)

GUICtrlSetLimit($DskName, 10,4)

EndIf

GUISetState()

While 1

$Msg = GUIGetMsg()

If $Msg = $GUI_Event_close Then

Exit

EndIf

If $Msg = $NextB Then

Exit

EndIf

WEnd

Help.au3

Link to comment
Share on other sites

  • Moderators

islandspapand,

Welcome to the AutoIt forum. :huh2:

I have made a few changes to your script and it should now run as you wish:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

; Set a couple of Global variables
Global $sCurrDROP = ""
Global $DskName = 9999 ; This is a placeholder value

$GUIRecovery = GUICreate("Test ", 241, 203, 352, 256)

$NextB = GUICtrlCreateButton("Next", 8, 168, 225, 33, BitOR($BS_DEFPUSHBUTTON, $WS_GROUP), $WS_EX_STATICEDGE)

$PDROP = GUICtrlCreateCombo("", 28, 32, 97, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
GUICtrlSetData($PDROP, "Asus|Clevo|Dell|Fujitsu|HP|LG|Lenovo|MSI|Medion|Packard Bell|Samsung|Sony|Toshiba|Zepto|")

$OSDROP = GUICtrlCreateCombo("Win7", 128, 88, 97, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
GUICtrlSetData($OSDROP, "Vista|XP")

$PNAVN = GUICtrlCreateLabel("Vælg PC Proucent", 128, 9, 101, 17)
$OSL = GUICtrlCreateLabel("Vælg OS Version", 128, 64, 94, 17)

GUISetState()

While 1

    ; Better syntax for your GUIGetMsg loop !
    Switch GUIGetMsg()
        Case $GUI_Event_close
            Exit
        Case $NextB
            Exit
        Case $PDROP ; The combo edit was changed
            ; Check if combo has been altered and closed
            If GUICtrlRead($PDROP) <> $sCurrDROP Then

                ; Create the label and input the first time we use the combo
                If $DskName = 9999 Then
                    $RLabel = GUICtrlCreateLabel(" Model Nr:", 128, 120, 99, 17, $SS_CENTER)
                    $DskName = GUICtrlCreateInput("", 128, 136, 105, 21, -1)
                EndIf
                ; Check combo value
                Switch GUICtrlRead($PDROP)
                    Case "Asus"
                        ConsoleWrite("Asus" & @CRLF) ; just for info
                        ; Adjust input limit as required
                        GUICtrlSetLimit($DskName, 5, 4)
                    Case "HP"
                        ConsoleWrite("HP" & @CRLF) ; just for info
                        ; Adjust input limit as required
                        GUICtrlSetLimit($DskName, 10, 4)
                EndSwitch
                ; Reset the current combo value
                $sCurrDROP = GUICtrlRead($PDROP)

            EndIf

    EndSwitch
    
    $OSDROPSTATE = GUICtrlRead($OSDROP, 1)

WEnd

I think the comments are self-explanatory, but please ask if not. ;)

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

 

Link to comment
Share on other sites

M23

Thank you for the welcome and even more thanks for your help I really appreciate it.

It was exactly what I needed to move forward :huh2:

I'll soon be posting my full script and i would appreciate it if you would look it over for any noob mistakes or if any process could be done easier.

Again thanks for your help and your time.

islandspapand.

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