Sign in to follow this  
Followers 0
surreal

DropDown List Variable

14 posts in this topic

alight, below is the simple sample code. what i need to do now is create some kind of variable i think. i have search for examples through the forum and was not able to find anything. thanks everyone for your help with this...

what i would like to happen is the following:

a tech enters the username

then chooses desktop or laptop within the dropdown list

if desktop is select then only hp and dell will be listed within make, and then all three for laptop

if laptop - dell - is selected i would like to only list the models for the machine that we have in inventory for the type and make.

then the tech will enter the asset info

code:

CODE
#include <GUIConstants.au3>

$Form2 = GUICreate("Asset Info", 304, 210, 213, 133)

$Group1 = GUICtrlCreateGroup("Group1", 16, 16, 265, 153)

$Label1 = GUICtrlCreateLabel("Username:", 32, 40, 55, 17)

$Input1 = GUICtrlCreateInput("", 88, 40, 177, 21)

$Label2 = GUICtrlCreateLabel("Hardware Type:", 32, 72, 80, 17)

$Combo1 = GUICtrlCreateCombo("", 120, 72, 145, 25)

GUICtrlSetData(-1,"Desktop|Latop", "")

$Label3 = GUICtrlCreateLabel("Make:", 32, 104, 34, 17)

$Combo2 = GUICtrlCreateCombo("", 72, 104, 65, 25)

GUICtrlSetData(-1,"HP|DELL|IBM", "")

$Label4 = GUICtrlCreateLabel("Model:", 144, 104, 36, 17)

$Combo3 = GUICtrlCreateCombo("", 184, 104, 81, 25)

GUICtrlSetData(-1,"GX280|GX280|GX520|GX745", "")

$Label5 = GUICtrlCreateLabel("Asset:", 32, 136, 33, 17)

$Input2 = GUICtrlCreateInput("", 72, 136, 193, 21)

GUICtrlCreateGroup("", -99, -99, 1, 1)

$Button1 = GUICtrlCreateButton("Submit", 104, 176, 75, 25, 0)

GUISetState(@SW_SHOW)

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

EndSwitch

WEnd

d@ve

Share this post


Link to post
Share on other sites



#include <GUIConstants.au3>

$Form2 = GUICreate("Asset Info", 304, 210, 213, 133)
$Group1 = GUICtrlCreateGroup("Group1", 16, 16, 265, 153)
$Label1 = GUICtrlCreateLabel("Username:", 32, 40, 55, 17)
$Input1 = GUICtrlCreateInput("", 88, 40, 177, 21)
$Label2 = GUICtrlCreateLabel("Hardware Type:", 32, 72, 80, 17)
$Combo1 = GUICtrlCreateCombo("", 120, 72, 145, 25)
GUICtrlSetData(-1,"Desktop|Latop", "")
$Label3 = GUICtrlCreateLabel("Make:", 32, 104, 34, 17)
$Combo2 = GUICtrlCreateCombo("", 72, 104, 65, 25)
GUICtrlSetData(-1,"", "")
$Label4 = GUICtrlCreateLabel("Model:", 144, 104, 36, 17)
$Combo3 = GUICtrlCreateCombo("", 184, 104, 81, 25)
GUICtrlSetData(-1,"GX280|GX280|GX520|GX745", "")
$Label5 = GUICtrlCreateLabel("Asset:", 32, 136, 33, 17)
$Input2 = GUICtrlCreateInput("", 72, 136, 193, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("Submit", 104, 176, 75, 25, 0)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()

    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            
        Case $Combo1
            If GUICtrlRead($Combo1) = "Desktop" Then
              GUICtrlSetData($Combo2, "HP|DELL")
            Else
              GUICtrlSetData($Combo2, "")
              GUICtrlSetData($Combo2, "HP|DELL|IBM")
            EndIf
    EndSwitch
WEnd

One way of doing it. This has been tested and works. You should be able to take it from there.

Share this post


Link to post
Share on other sites

thank you very much for the quick responses, i will give this a go, and let ya know. i want this to do a few other things, but once im done i will post the code for anyone to use...

Share this post


Link to post
Share on other sites

Hehe no problem :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

your part did work, lol. but when i tried to add the extra layers it does not, i have tried different syntax but so far no outcome. i just found out we dont have to worry about hp, so this should be alittle easier. thanks again for the help.

new code:

CODE
#include <GUIConstants.au3>

$Form2 = GUICreate("Asset Info", 304, 210, 213, 133)

$Group1 = GUICtrlCreateGroup("Group1", 16, 16, 265, 153)

$Label1 = GUICtrlCreateLabel("Username:", 32, 40, 55, 17)

$Input1 = GUICtrlCreateInput("", 88, 40, 177, 21)

$Label2 = GUICtrlCreateLabel("Hardware Type:", 32, 72, 80, 17)

$Combo1 = GUICtrlCreateCombo("", 120, 72, 145, 25)

GUICtrlSetData(-1,"Desktop|Laptop", "")

$Label3 = GUICtrlCreateLabel("Make:", 32, 104, 34, 17)

$Combo2 = GUICtrlCreateCombo("", 72, 104, 65, 25)

GUICtrlSetData(-1,"", "")

$Label4 = GUICtrlCreateLabel("Model:", 144, 104, 36, 17)

$Combo3 = GUICtrlCreateCombo("", 184, 104, 81, 25)

GUICtrlSetData(-1,"", "")

$Label5 = GUICtrlCreateLabel("Asset:", 32, 136, 33, 17)

$Input2 = GUICtrlCreateInput("", 72, 136, 193, 21)

GUICtrlCreateGroup("", -99, -99, 1, 1)

$Button1 = GUICtrlCreateButton("Submit", 104, 176, 75, 25, 0)

GUISetState(@SW_SHOW)

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Combo1

If GUICtrlRead($Combo1) = "Desktop" Then

GUICtrlSetData($Combo2, "DELL")

GUICtrlSetData($Combo3, "GX280|GX280|GX520|GX745")

Else

GUICtrlSetData($Combo1, "Laptop")

GUICtrlSetData($Combo2, "DELL|IBM")

EndIf

If GUICtrlRead($Combo1) = "Laptop" ($Combo2) = "IBM" Then

GUICtrlSetData($Combo3, "T42|T43")

EndIf

If GUICtrlRead($Combo1) = "Laptop" ($Combo2) = "DELL" Then

GUICtrlSetData($Combo3, "D600|D610|D620")

EndIf

EndSwitch

WEnd

Edited by surreal

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

your part did work, lol. but when i tried to add the extra layers it does not, i have tried different syntax but so far no outcome. i just found out we dont have to worry about hp, so this should be alittle easier. thanks again for the help.

new code:

CODE
#include <GUIConstants.au3>

$Form2 = GUICreate("Asset Info", 304, 210, 213, 133)

$Group1 = GUICtrlCreateGroup("Group1", 16, 16, 265, 153)

$Label1 = GUICtrlCreateLabel("Username:", 32, 40, 55, 17)

$Input1 = GUICtrlCreateInput("", 88, 40, 177, 21)

$Label2 = GUICtrlCreateLabel("Hardware Type:", 32, 72, 80, 17)

$Combo1 = GUICtrlCreateCombo("", 120, 72, 145, 25)

GUICtrlSetData(-1,"Desktop|Laptop", "")

$Label3 = GUICtrlCreateLabel("Make:", 32, 104, 34, 17)

$Combo2 = GUICtrlCreateCombo("", 72, 104, 65, 25)

GUICtrlSetData(-1,"", "")

$Label4 = GUICtrlCreateLabel("Model:", 144, 104, 36, 17)

$Combo3 = GUICtrlCreateCombo("", 184, 104, 81, 25)

GUICtrlSetData(-1,"", "")

$Label5 = GUICtrlCreateLabel("Asset:", 32, 136, 33, 17)

$Input2 = GUICtrlCreateInput("", 72, 136, 193, 21)

GUICtrlCreateGroup("", -99, -99, 1, 1)

$Button1 = GUICtrlCreateButton("Submit", 104, 176, 75, 25, 0)

GUISetState(@SW_SHOW)

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Combo1

If GUICtrlRead($Combo1) = "Desktop" Then

GUICtrlSetData($Combo2, "DELL")

GUICtrlSetData($Combo3, "GX280|GX280|GX520|GX745")

Else

GUICtrlSetData($Combo1, "Laptop")

GUICtrlSetData($Combo2, "DELL|IBM")

If GUICtrlRead($Combo1) = "Laptop" ($Combo2) = "IBM" Then

GUICtrlSetData($Combo3, "T42|T43")

If GUICtrlRead($Combo1) = "Laptop" ($Combo2) = "DELL" Then

GUICtrlSetData($Combo3, "D600|D610|D620")

EndIf

EndSwitch

WEnd

Change your code to reflect this:

#include <GUIConstants.au3>

$Form2 = GUICreate("Asset Info", 304, 210, 213, 133)
$Group1 = GUICtrlCreateGroup("Group1", 16, 16, 265, 153)
$Label1 = GUICtrlCreateLabel("Username:", 32, 40, 55, 17)
$Input1 = GUICtrlCreateInput("", 88, 40, 177, 21)
$Label2 = GUICtrlCreateLabel("Hardware Type:", 32, 72, 80, 17)
$Combo1 = GUICtrlCreateCombo("", 120, 72, 145, 25)
GUICtrlSetData(-1,"Desktop|Laptop", "")
$Label3 = GUICtrlCreateLabel("Make:", 32, 104, 34, 17)
$Combo2 = GUICtrlCreateCombo("", 72, 104, 65, 25)
GUICtrlSetData(-1,"", "")
$Label4 = GUICtrlCreateLabel("Model:", 144, 104, 36, 17)
$Combo3 = GUICtrlCreateCombo("", 184, 104, 81, 25)
GUICtrlSetData(-1,"", "")
$Label5 = GUICtrlCreateLabel("Asset:", 32, 136, 33, 17)
$Input2 = GUICtrlCreateInput("", 72, 136, 193, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("Submit", 104, 176, 75, 25, 0)
GUISetState(@SW_SHOW)

While 1
  $nMsg = GUIGetMsg()

  Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

    Case $Combo1
      If GUICtrlRead($Combo1) = "Desktop" Then
        GUICtrlSetData($Combo2, "DELL")
        GUICtrlSetData($Combo3, "GX280|GX280|GX520|GX745")
      Else
        GUICtrlSetData($Combo1, "Laptop")
        GUICtrlSetData($Combo2, "DELL|IBM")

        If GUICtrlRead($Combo1) = "Laptop" And GUICtrlRead($Combo2) = "IBM" Then
          GUICtrlSetData($Combo3, "T42|T43")
        ElseIf GUICtrlRead($Combo1) = "Laptop" And GUICtrlRead($Combo2) = "DELL" Then
          GUICtrlSetData($Combo3, "D600|D610|D620")
        EndIf
    EndSwitch
WEnd

P.S. Indenting is always a favorable thing to do, as well as changing the default names of the variables.

Edited by Tasmania

Share this post


Link to post
Share on other sites

thank you, from the looks of the new code that make sense, but it is not working for me. there are two issues...

1. i get an error when running the new code "43) : ==> "EndSwitch" statement with no matching "Switch" statement.: EndSwitch" if i remove the new code its fine.

2. i think i have had this problem sense the beginning. if i choose laptop them ibm, but then change my mind and go back and choose desktop everything in all fields are listed twice, sometimes even more. example would be DELL,DELL,IBM,DELL,IBM in the make dropdown.

thanks again everyone. you have been alot of help.

d@ve

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Cheers

1. There's and EndIf missing...

Case $Combo1
      If GUICtrlRead($Combo1) = "Desktop" Then
        GUICtrlSetData($Combo2, "DELL")
        GUICtrlSetData($Combo3, "GX280|GX280|GX520|GX745")
      Else
        GUICtrlSetData($Combo1, "Laptop")
        GUICtrlSetData($Combo2, "DELL|IBM")

        If GUICtrlRead($Combo1) = "Laptop" And GUICtrlRead($Combo2) = "IBM" Then
          GUICtrlSetData($Combo3, "T42|T43")
        ElseIf GUICtrlRead($Combo1) = "Laptop" And GUICtrlRead($Combo2) = "DELL" Then
          GUICtrlSetData($Combo3, "D600|D610|D620")
        EndIf
      EndIf ; <---missing
    EndSwitch

2. clear the combobox of all data before adding data to it again... eg: GUICtrlSetData($Combo2, "","")

Cheers

Edited by smashly

Share this post


Link to post
Share on other sites

that did the trick, thanks. sorry but i dont get the second part, where would i enter that code? or are you suggesting i make an extra button that clears the fields? i would rather not go that route if i dont have to. it seems that all the fields save the data, so it get pretty messy if you go back and change your selection.

d@ve

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

No . I'm suggesting to clear a combo box before adding data to it...eg:

Case $Combo1
      If GUICtrlRead($Combo1) = "Desktop" Then
        GUICtrlSetData($Combo2, "", "")  
        GUICtrlSetData($Combo2, "DELL")
        GUICtrlSetData($Combo3, "", "")
        GUICtrlSetData($Combo3, "GX280|GX280|GX520|GX745")oÝ÷ Ø:-+0ØZ'(º£¬­ê®·Â§¶¢fènb²
"h«Þu«Z±ëb+Dv+r¢æ¥²¢pj{m¢ë¶´ß H4N
Edited by smashly

Share this post


Link to post
Share on other sites

thanks for the quick response. that is all very good information, i for sure will use the $CBS_DROPDOWNLIST. im new to this forum, and i would just like to say thanks to you and everyone else that helped. this is a great forum with alot of great info, and great people. you have a great day, or evening...

d@ve

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

ok, maybe this is just me. but all the code and the stuff you all have helped with looks right. however it still does not work. im not sure if it ever did, i was to busy noticing other things, but if i choose laptop, then dell, there is nothing in combo3, hummmmm. below is the new code...

#include <GUIConstants.au3>

$Form2 = GUICreate("Asset Info", 304, 210, 213, 133)
$Group1 = GUICtrlCreateGroup("Information", 16, 16, 265, 153)
$Label1 = GUICtrlCreateLabel("Username:", 32, 40, 55, 17)
$Input1 = GUICtrlCreateInput("", 88, 40, 177, 21)
$Label2 = GUICtrlCreateLabel("Hardware Type:", 32, 72, 80, 17)
$Combo1 = GUICtrlCreateCombo("", 120, 72, 145, 25, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1,"Desktop|Laptop", "")
$Label3 = GUICtrlCreateLabel("Make:", 32, 104, 34, 17)
$Combo2 = GUICtrlCreateCombo("", 72, 104, 65, 25, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1,"", "")
$Label4 = GUICtrlCreateLabel("Model:", 144, 104, 36, 17)
$Combo3 = GUICtrlCreateCombo("", 184, 104, 81, 25, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1,"", "")
$Label5 = GUICtrlCreateLabel("Asset:", 32, 136, 33, 17)
$Input2 = GUICtrlCreateInput("", 72, 136, 193, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("Submit", 104, 176, 75, 25, 0)
GUISetState(@SW_SHOW)

While 1
  $nMsg = GUIGetMsg()

  Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

    Case $Combo1
      If GUICtrlRead($Combo1) = "Desktop" Then
        GUICtrlSetData($Combo2, "", "")  
        GUICtrlSetData($Combo2, "DELL")
        GUICtrlSetData($Combo3, "", "")  
        GUICtrlSetData($Combo3, "GX280|GX280|GX520|GX745")
      Else
        GUICtrlSetData($Combo1, "Laptop")
        GUICtrlSetData($Combo2, "", "") 
        GUICtrlSetData($Combo3, "", "")
        GUICtrlSetData($Combo2, "DELL|IBM")

      If GUICtrlRead($Combo1) = "Laptop" And GUICtrlRead($Combo2) = "IBM" Then
         GUICtrlSetData($Combo3, "T42|T43")
     ElseIf GUICtrlRead($Combo1) = "Laptop" And GUICtrlRead($Combo2) = "DELL" Then
         GUICtrlSetData($Combo3, "D600|D610|D620")
          EndIf    
 EndIf
    EndSwitch
WEnd
Edited by surreal

Share this post


Link to post
Share on other sites

any thoughts, thanks ahead of time for your help...

d@ve

Share this post


Link to post
Share on other sites

a co-working and i got this part working...

#include <GUIConstants.au3>

$Form1 = GUICreate("Asset Info", 304, 210, 213, 133)
$Group1 = GUICtrlCreateGroup("Information", 16, 16, 265, 153)
$Label1 = GUICtrlCreateLabel("Username:", 32, 40, 55, 17)
$Input1 = GUICtrlCreateInput("", 88, 40, 177, 21)
$Label2 = GUICtrlCreateLabel("Hardware Type:", 32, 72, 80, 17)
$Combo1 = GUICtrlCreateCombo("", 120, 72, 145, 25, $CBS_DROPDOWNLIST)
          GUICtrlSetData(-1,"Desktop|Laptop", "")
$Label3 = GUICtrlCreateLabel("Make:", 32, 104, 34, 17)
$Combo2 = GUICtrlCreateCombo("", 72, 104, 65, 25, $CBS_DROPDOWNLIST)
          GUICtrlSetData(-1,"", "")
$Label4 = GUICtrlCreateLabel("Model:", 144, 104, 36, 17)
$Combo3 = GUICtrlCreateCombo("", 184, 104, 81, 25, $CBS_DROPDOWNLIST)
          GUICtrlSetData(-1,"", "")
$Label5 = GUICtrlCreateLabel("Asset:", 32, 136, 33, 17)
$Input2 = GUICtrlCreateInput("", 72, 136, 193, 21)
          GUICtrlCreateGroup("", -99, -99, 1, 1)
$GO = GUICtrlCreateButton("Submit", 104, 176, 75, 25, 0)
      GUISetState()

While 1
  $nMsg = GUIGetMsg()

  Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit


Case $Combo1
        If GUICtrlRead($Combo1) = "Desktop" Then
           GUICtrlSetData($Combo2, "", "")
           GUICtrlSetData($Combo3, "", "")
           GUICtrlSetData($Combo2, "Dell","")
           
        ElseIF GUICtrlRead($Combo1) = "Laptop" Then
               GUICtrlSetData($Combo2, "", "")
               GUICtrlSetData($Combo3, "", "")
               GUICtrlSetData($Combo2, "Dell|IBM","") 
        EndIf

Case $Combo2

        If GUICtrlRead($Combo2) = "Dell" AND GUICtrlRead($Combo1) = "Desktop" Then
           GUICTrlSetData($Combo3, "GX280|GX280|GX520|GX745")

        ElseIF GUICtrlRead($Combo2) = "IBM" AND GUICtrlRead($Combo1) = "Laptop" Then
               GUICtrlSetData($Combo3, "", "")
               GUICtrlSetData($Combo3, "T42|T43")

        ElseIF GUICtrlRead($Combo2) = "Dell" AND GUICtrlRead($Combo1) = "Laptop" Then
               GUICtrlSetData($Combo3, "", "")
               GUICtrlSetData($Combo3, "D600|D610|D620")

        EndIf
    EndSwitch
WEnd

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