Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DropComboBox and the 50 States

Status
Not open for further replies.

molemanryan

Technical User
Jun 9, 2008
1
CA
I am trying to create a drop down list with the DropComboBox function with Attachmate. What I am trying to do is list all 50 states along with their 2 digit state abbreviation. Like District of Columbia is DC Virginia is VA and so on. The user will select one of these states and the corresponding 2 letter abbreviation will be sent to the screen. This is what I have so far:

Begin Dialog UserDialog 180, 95, "Select a State"
ButtonGroup .ButtonGroup1
Text 9, 3, 69, 13, "States:", .Text1
DropComboBox 9, 17, 111, 41, "Alaska AK"+Chr$(9)+"Arizona AZ"+Chr$(9)+"Arkansas AR", .ComboBox1
OKButton 131, 8, 42, 13
CancelButton 131, 27, 42, 13
End Dialog
Dim mydialogbox As UserDialog
Dialog mydialogbox

if DropComboBox = "Alaska AK" then
sess0.screen.sendkeys("AK")
end if

Couple of questions...how do I verify or check what was chosen with this function? I am pretty sure it's not the DropComboBox function holding the value, it seems it would be in an array. I tried using it as:

dim choices as string
Begin Dialog UserDialog 180, 95, "Select a State"
choices() = "Alaska AK"+Chr$(9)+"Arizona AZ"+Chr$(9)+"Arkansas AR"
ButtonGroup .ButtonGroup1
Text 9, 3, 69, 13, "States:", .Text1
DropComboBox 9, 17, 111, 41, choices(), .comboBox1
OKButton 131, 8, 42, 13
CancelButton 131, 27, 42, 13
End Dialog
Dim mydialogbox As UserDialog
Dialog mydialogbox

if choices(1) = "Alaska AK" then
sess0.screen.sendkeys("AK")
end if

This didn't work as it is referencing the number element like choices(1) would be Alaska...but I can't for the life of me figure it out. Your help is greatly appreciated!

Thank you
Ryan

 
You can set up your list of choices like this:

Code:
ListOfChoices = "Alaska AK" _
    +chr(9) + "Arizona AZ" _
    +chr(9) + "Arkansas AR"

so your declaration will look like this:

Code:
DropComboBox  9, 17, 111, 41, ListOfChoices, .ComboBox1

Now, to call your dialog box:

Code:
Done = FALSE

While Done = FALSE
    Dim mydialogbox As UserDialog
    OKorCANCEL = Dialog(mydialogbox)

    Select Case OKorCANCEL
        Case -1
            '' user has pressed the OK button
            Done = TRUE
            '' which state did the user pick?
            StatePicked = mydialogbox.ComboBox1
            StateAbbreviation = Right$(StatePicked, 2)
            Sess0.Screen.Sendkeys(StateAbbreviation)
            

        Case 0
            '' user has pressed the CANCEL button
            Done = TRUE
            msgbox("No state selected!")
    End Select
Wend

For further info, check out the descriptions of "text$" and ".field" in the help for the DropComboBox(statement).

Hope this helps,

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top