Sign in to follow this  
Followers 0
HockeyFan

Array Help

3 posts in this topic

Hello & TGIF!

I'm in a pinch and need some more help with an array. I need to pull the two letter state identifier from the $StateList Array. Currently, when the Function _CityOKButtonclick() is called, a GUICtrlRead is done on the Combo Box which uses the $StateList array data, but I want to add a msgbox that pulls the two letter state identifier based on the array data that was selected in the ComboBox.

Any assistance with this would be greatly appreciated!! :graduated:

Thanks in advance.

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ComboConstants.au3>

HotKeySet("+!t", "_Quit") ;Shift-Alt-t
Opt("GuiOnEventMode", 1)

$CityState = "Albany, NY/alb:" & _
        "Albuquerque, NM/alb:" & _
        "Alexandria, VA/alx:" & _
        "Amherst, NY/amh:" & _
        "Anchorage, AK/anc:" & _
        "Atlanta, GA/atl:" & _
        "Austin, TX/aus:" & _
        "Bala Cynwyd, PA/bcy:" & _
        "Baltimore, MD/bal:" & _
        "Baton Rouge, LA/bat:" & _
        "Bentonville, AR/ben:" & _
        "Bethlehem, PA (HBO)/bet:" & _
        "Bingham Farms, MI/bgf:" & _
        "Birmingham, AL/bir:" & _
        "Boston, MA/bos:" & _
        "Bridgewater, NJ/bri:" & _
        "Charlotte, NC/chr:" & _
        "Chesapeake, VA/che:" & _
        "Chicago, IL/chi:" & _
        "Cincinnati, OH/cin:" & _
        "Columbia, SC/col:" & _
        "Columbus, OH/col:" & _
        "Corpus Christi, TX (VPN)/cor:" & _
        "Dallas, TX/dal:" & _
        "Decatur, IL/dec:" & _
        "Denver, CO/den:" & _
        "East Syracuse, NY/syr:" & _
        "Emeryville, CA/emv:" & _
        "Evansville,IN (VPN)/evn:" & _
        "Fairfax, VA/ffx:" & _
        "Fargo, ND/far:" & _
        "Fort Lauderdale, FL/ftl:" & _
        "Grand Rapids, MI/gra:" & _
        "Greenville, SC/gre:" & _
        "Harrisburg, PA/har:" & _
        "Honolulu, HI/hon:" & _
        "Houston, TX/hou:" & _
        "Huntsville, AL (VPN)/hun:" & _
        "Independence, OH/ind:" & _
        "Indianapolis, IN/ind:" & _
        "(Editorial Ofc.) Indianapolis, IN/edi:" & _
        "Jackson, MS/jck:" & _
        "Jacksonville, FL/jac:" & _
        "Knoxville, TN/knx:" & _
        "Las Vegas, NV/las:" & _
        "Lexington, KY (VPN)/lex:" & _
        "Little Rock, AR/ltr:" & _
        "Los Angeles, CA/los:" & _
        "Louisville, KY/lou:" & _
        "Lubbock, TX/lub:" & _
        "Maitland, FL/mtl:" & _
        "Melville, NY/mel:" & _
        "Memphis, TN/mem:" & _
        "Miami, FL/mia:" & _
        "Middletown, CT/mid:" & _
        "Midland, TX (VPN)/mid:" & _
  "Monona, WI (VPN)/man:" & _
        "Nashville, TN/nsh:" & _
        "New Orleans, LA/new:" & _
        "New York, NY/nyc:" & _
        "Oklahoma City, OK/okl:" & _
        "Omaha, NE/oma:" & _
        "Overland Park, KS/ovr:" & _
        "Pensacola, FL(VPN)/pen:" & _
        "Phoenix, AZ/phx:" & _
        "Pittsburgh, PA/pit:" & _
        "Portland, ME (HBO)/por:" & _
        "Portland, OR/por:" & _
        "Providence, RI/pro:" & _
        "Raleigh, NC/ral:" & _
        "Richland, WA (VPN)/ric:" & _
        "Richmond, VA/ric:" & _
        "Rochester, NY/roc:" & _
        "Sacramento, CA/sac:" & _
        "Salt Lake City, UT/slc:" & _
        "San Antonio, TX/san:" & _
        "San Diego, CA/sad:" & _
        "San Jose, CA/saj:" & _
        "Santa Ana, CA/ana:" & _
        "Savannah, GA/svh:" & _
        "Seattle, WA/sea:" & _
  "Seminary Road, VA (VPN)/sem:" & _
        "Spokane, WA/spo:" & _
        "Springfield, MO/spr:" & _
  "St. Louis Park, MN/slp:" & _
        "St. Louis, MO/stl:" & _
        "Tampa, FL/tam:" & _
        "Tucson, AZ/tuc:" & _
        "Tulsa, OK/tul:" & _
        "Urbandale, IA/urb:" & _
        "Utica, NY/uti:" & _
        "Washington, DC/was:" & _
        "Wawatosa, WI/waw:" & _
        "White Plains, NY (VPN)/whi:" & _
        "Wichita, KS/wic:" & _
        "Wilmington, DE/wil"

Global $StateList[53]
$StateList[0] = "|Select State|"
$StateList[1] = "|Alabama|AL"
$StateList[2] = "|Alaska|AK"
$StateList[3] = "|Arizona|AZ"
$StateList[4] = "|Arkansas|AR"
$StateList[5] = "|California|CA"
$StateList[6] = "|Colorado|CO"
$StateList[7] = "|Connecticut|CT"
$StateList[8] = "|Delaware|DE"
$StateList[9] = "|District of Columbia|DC"
$StateList[10] = "|Florida|FL"
$StateList[11] = "|Georgia|GA"
$StateList[12] = "|Hawaii|HI"
$StateList[13] = "|Idaho|ID"
$StateList[14] = "|Illinois|IL"
$StateList[15] = "|Indiana|IN"
$StateList[16] = "|Iowa|IA"
$StateList[17] = "|Kansas|KS"
$StateList[18] = "|Kentucky|KY"
$StateList[19] = "|Louisiana|LA"
$StateList[20] = "|Maine|ME"
$StateList[21] = "|Maryland|MD"
$StateList[22] = "|Massachusetts|MA"
$StateList[23] = "|Michigan|MI"
$StateList[24] = "|Minnesota|MN"
$StateList[25] = "|Mississippi|MS"
$StateList[26] = "|Missouri|MO"
$StateList[27] = "|Montana|MT"
$StateList[28] = "|Nebraska|NE"
$StateList[29] = "|Nevada|NV"
$StateList[30] = "|New Hampshire|NH"
$StateList[31] = "|New Jersey|NJ"
$StateList[32] = "|New Mexico|NM"
$StateList[33] = "|New York|NY"
$StateList[34] = "|North Carolina|NC"
$StateList[35] = "|North Dakota|ND"
$StateList[36] = "|Ohio|OH"
$StateList[37] = "|Oklahoma|OK"
$StateList[38] = "|Oregon|OR"
$StateList[39] = "|Pennsylvania|PA"
$StateList[40] = "|Rhode Island|RI"
$StateList[41] = "|South Carolina|SC"
$StateList[42] = "|South Dakota|SD"
$StateList[43] = "|Tennessee|TN"
$StateList[44] = "|Texas|TX"
$StateList[45] = "|Utah|UT"
$StateList[46] = "|Vermont|VT"
$StateList[47] = "|Virginia|VA"
$StateList[48] = "|Washington|WA"
$StateList[49] = "|West Virginia|WV"
$StateList[50] = "|Wisconsin|WI"
$StateList[51] = "|Wyoming|WY"
$StateList[52] = "|Select State|"

Local $sList

$CityArrayData = StringSplit($CityState, ":")
Global $Radios[$CityArrayData[0] + 1] = [$CityArrayData[0]] ; [0] = count
Global $CityID[$CityArrayData[0] + 1] = [$CityArrayData[0]] ; [0] = count

$CityNameGUI = GUICreate("", 775, 676, -1, -1, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
$CityNameLabel1 = GUICtrlCreateLabel("Please select the city where the computer is to be located:", 25, 8, 500, 25, $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 12, 800, 0, "Arial")
GUICtrlSetColor(-1, 0x0000ff) ;Blue

$CityNameGroup1 = GUICtrlCreateGroup("", 24, 32, 725, 468)

Global $iX = 50 ; Starting X-pos
Global $iY = 50 ; Starting Y-pos

For $aX = 1 To $Radios[0]
$Radios[$aX] = GUICtrlCreateRadio(StringTrimRight($CityArrayData[$aX], 4), $iX, $iY, 160, 17)
GUICtrlSetOnEvent(-1, "CityNameSelectOKButtonEnable")
$CityID[$aX] = $CityArrayData[$aX]
$iY += 16
If Mod($aX, 24) = 0 Then; Original # = 27
  ; Start new column (26 items per column)
  $iY = 50
  $iX += 175
EndIf
Next

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

$HomeBasedUserCheckBox = GUICtrlCreateCheckbox(" ", 130, 512)
GUICtrlSetOnEvent(-1, "_HBUCheckBoxAction")
GUICtrlCreateLabel('Check here if the system is to be configured for a "Home Based" User', 153, 515, 500, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Arial")
GUICtrlSetColor(-1, 0xff0000) ;Red

$HomeBasedUserStateLabel = GUICtrlCreateLabel('Please select the State in which the "Home Based User" resides:  ', 130, 550, 410, 22)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
;GUICtrlSetColor(-1, 0xff0000) ;Red
GUICtrlSetState($HomeBasedUserStateLabel, $GUI_DISABLE)

$CityDataLastUpdateLabel = GUICtrlCreateLabel('(*) Office data updated November 2010', 550, 480, 195, 15)
GUICtrlSetFont(-1, 8, 800, 0, "Arial")
;GUICtrlSetColor(-1, 0x0000cd) ;Blue
GUICtrlSetColor(-1, 0x32cd32) ;Lime Green
GUICtrlSetState($HomeBasedUserStateLabel, $GUI_DISABLE)

$HomeBasedUserComboBox = GUICtrlCreateCombo("", 550, 550, 125, 25, BitOR($GUI_SS_DEFAULT_COMBO,$CBS_DROPDOWNLIST))
GUICtrlSetOnEvent(-1, "_EnableCityStateOKButton")
_Combo_Fill()
GUICtrlSetState($HomeBasedUserComboBox, $GUI_DISABLE)


$CityNameButton = GUICtrlCreateButton("OK", 330, 590, 115, 35)
GUICtrlSetFont(-1, 12, 800, 0, "Arial")
GUICtrlSetOnEvent(-1, "_CityOKButtonclick")
GUICtrlSetState($CityNameButton, $GUI_DISABLE)

GUISetState()

While 1
Sleep(10)
WEnd

Func CityNameSelectOKButtonEnable()
ConsoleWrite("Debug: Clicked a radio: ID = " & @GUI_CtrlId & "; Text = " & ControlGetText(@GUI_WinHandle, "", @GUI_CtrlId) & @LF)
GUICtrlSetState($CityNameButton, $GUI_ENABLE)
EndFunc ;==>CityNameSelectOKButtonEnable

Func _Quit()
Exit
EndFunc ;==>_Quit

Func _CityOKButtonclick()
For $n = 1 To $Radios[0]
  If ControlCommand($CityNameGUI, "", $Radios[$n], "IsChecked") Then
   MsgBox(64, "OK", "ID: " & $Radios[$n] & "; Text: " & ControlGetText($CityNameGUI, "", $Radios[$n]))
   ExitLoop
  EndIf
Next
$HBUComboRead = GUICtrlRead($HomeBasedUserComboBox)
If ControlCommand($CityNameGUI, "", $HomeBasedUserComboBox, "IsEnabled") Then
  MsgBox(64, "State", "State: " & $HBUComboRead)
EndIf

GUICtrlSetState($CityNameButton, $GUI_DISABLE)
Call("_Quit")
EndFunc ;==>_CityOKButtonclick

;Func _HBUCheckBoxAction()
; GUICtrlSetState($CityNameButton, $GUI_DISABLE)
; If BitAND(GUICtrlRead($HomeBasedUserCheckBox), $GUI_CHECKED) = $GUI_CHECKED Then Call("_HBUMessage")
; For $x = 1 To UBound($CityArrayData) - 1
;  If BitAND(GUICtrlRead($Radios[$x]), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState(($Radios[$x]), $GUI_UNCHECKED)
;  If BitAND(GUICtrlRead($HomeBasedUserCheckBox), $GUI_CHECKED) = $GUI_CHECKED Then
;   GUICtrlSetState(($Radios[$x]), $GUI_DISABLE)
;   GUICtrlSetState($HomeBasedUserStateLabel, $GUI_ENABLE)
;   GUICtrlSetState($HomeBasedUserComboBox, $GUI_ENABLE)
;  Else
;   GUICtrlSetState($CityNameButton, $GUI_DISABLE)
;   If BitAND(GUICtrlRead($Radios[$x]), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState(($Radios[$x]), $GUI_UNCHECKED)
;   GUICtrlSetState(($Radios[$x]), $GUI_ENABLE)
;   GUICtrlSetState($HomeBasedUserStateLabel, $GUI_DISABLE)
;   _Combo_Fill()
;   GUICtrlSetState($HomeBasedUserComboBox, $GUI_DISABLE)
;   If BitAND(GUICtrlRead($HomeBasedUserComboBox), $GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetData($HomeBasedUserComboBox, $sList, "Select State")
;  EndIf
; Next
; ;GUIDelete($CityNameGUI)
;EndFunc   ;==>_HBUCheckBoxAction

Func _HBUCheckBoxAction()

    GUICtrlSetState($CityNameButton, $GUI_DISABLE)
    For $x = 1 To UBound($CityArrayData) - 1
        GUICtrlSetState($Radios[$x], $GUI_UNCHECKED)
    Next
    Switch GUICtrlRead($HomeBasedUserCheckBox)
        Case 1 ; Checked
            For $x = 1 To UBound($CityArrayData) - 1
                GUICtrlSetState($Radios[$x], $GUI_DISABLE)
            Next
            GUICtrlSetState($HomeBasedUserStateLabel, $GUI_ENABLE)
            GUICtrlSetState($HomeBasedUserComboBox, $GUI_ENABLE)
        Case Else ; Not checked
            For $x = 1 To UBound($CityArrayData) - 1
                GUICtrlSetState($Radios[$x], $GUI_ENABLE)
            Next
            GUICtrlSetState($HomeBasedUserStateLabel, $GUI_DISABLE)
            _Combo_Fill()
            GUICtrlSetState($HomeBasedUserComboBox, $GUI_DISABLE)
    EndSwitch

EndFunc   ;==>_HBUCheckBoxAction

Func _EnableCityStateOKButton()
If GUICtrlRead($HomeBasedUserComboBox) <> "Select State" Then GUICtrlSetState($CityNameButton, $GUI_ENABLE)
If GUICtrlRead($HomeBasedUserComboBox) = "Select State" Then GUICtrlSetState($CityNameButton, $GUI_DISABLE)
EndFunc   ;==>_EnableCityStateOKButton

Func _Combo_Fill()
    $sList = "|"
    For $i = 0 To UBound($StateList) - 1
        $aSplit = StringSplit($StateList[$i], "|")
        $sList &= $aSplit[2] & "|"
    Next
    GUICtrlSetData($HomeBasedUserComboBox, $sList, "Select State")
EndFunc

Share this post


Link to post
Share on other sites



HockeyFan,

Add #include <Array.au3> to the top of your script and then amend your function as follows: :graduated:

$HBUComboRead = GUICtrlRead($HomeBasedUserComboBox)
If ControlCommand($CityNameGUI, "", $HomeBasedUserComboBox, "IsEnabled") Then
    $iIndex = _ArraySearch( $StateList, $HBUComboRead, 0 , 0, 0, 1) ; Look for the state name in the array
    $sStateID = StringRight($StateList[$iIndex], 2) ; Extract the ID from the end of the array element
    MsgBox(64, "State", "State: " & $HBUComboRead & @CRLF & $sStateID)
EndIf

M23


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

HockeyFan,

Add #include <Array.au3> to the top of your script and then amend your function as follows: :graduated:

$HBUComboRead = GUICtrlRead($HomeBasedUserComboBox)
If ControlCommand($CityNameGUI, "", $HomeBasedUserComboBox, "IsEnabled") Then
    $iIndex = _ArraySearch( $StateList, $HBUComboRead, 0 , 0, 0, 1) ; Look for the state name in the array
    $sStateID = StringRight($StateList[$iIndex], 2) ; Extract the ID from the end of the array element
    MsgBox(64, "State", "State: " & $HBUComboRead & @CRLF & $sStateID)
EndIf

M23

M23,

Thank you so much!!! This should get me rolling again! Thank you!!!!

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