Jump to content

Combo Boxes based on previous selections


Recommended Posts

Good afternoon,

After reviewing some of my old posts I’ve realised something... I keep running into brick walls when it comes to AutoIT!...lol

Anyway down to business:

I’ve been developing an AutoIT Script which will prompt a user for the location of a computer workstation and when submitted will then add this information to the Computer Description property of the workstation (located within the properties of ‘My Computer’.) The script also tags the information to the workstation object within Active Directory.

All of the above works fine, however the prompt is a free text field and of course some people in the Universe can’t be bothered entering the correct information even if this will help them in the future... in short I'm pulling my hair out, hense I need your help to prevent rapid hair loss.

The information the user is prompted for is:

DEPARTMENT, FLOOR, BUILDING, SITE and ROOM NUMBER

To make the collection of the data easier I’d like to implement 3 Combo Boxes in the following order for:

SITE

BUILDING

FLOOR

So far so good I’m up to this point, it’s the next bit where I’m stuck.

I’ve created a file called ‘sites.txt’ which will populate each of the combo boxes. I would like it so when a SITE is selected it will only show a list of BUILDING‘s on that particular SITE and will then present a list of FLOOR’s for that BUILDING.

Example of sites.txt:

Site 1,Building 1,Ground Floor

Site 1,Building 1,1st Floor

Site 1,Building 1,2nd Floor

Site 1,Building 2,1st Floor

Site 1,Building 2,2nd Floor

Site 2,Building 1,Ground Floor

Site 2,Building 1,1st Floor

etc

Hope that made sense...

Any help will be much appreciated thanks in advance

Words of Wisdom and Favourite Quotes:

'Nothing is impossible, despite what other people say and think, prove them wrong and show them what you can do!'

'Understanding is a three edged sword, your side, their side and the truth!'

'The truth that humanity has never been able to grasp, is that death may be the only absolute freedom there is!'

'I've run out of places to put the brush... what do you suggest?'

Link to comment
Share on other sites

This is the kind of thing that cries out for XML.

For example, this script:

#Include <_XMLDOMWrapper.au3>

Global $sXML = @ScriptDir & "\SitesList.xml"

_XMLCreateFile($sXML, "Sites")
_XMLFileOpen($sXML)

; Create Site 1
_XMLCreateRootChild("Site")
_XMLCreateChildNode("/Sites/Site[1]", "Name", "Site 1")
_XMLCreateChildNode("/Sites/Site[1]", "Building")
_XMLCreateChildNode("/Sites/Site[1]/Building[1]", "Name", "Building 1")
_XMLCreateChildNode("/Sites/Site[1]/Building[1]", "Floor", "Ground Floor")
_XMLCreateChildNode("/Sites/Site[1]/Building[1]", "Floor", "1st Floor")
_XMLCreateChildNode("/Sites/Site[1]/Building[1]", "Floor", "2nd Floor")
_XMLCreateChildNode("/Sites/Site[1]", "Building", "Building 2")
_XMLCreateChildNode("/Sites/Site[1]/Building[2]", "Name", "Building 1")
_XMLCreateChildNode("/Sites/Site[1]/Building[2]", "Floor", "1st Floor")
_XMLCreateChildNode("/Sites/Site[1]/Building[2]", "Floor", "2nd Floor")

; Create Site 2
_XMLCreateRootChild("Site")
_XMLCreateChildNode("/Sites/Site[2]", "Name", "Site 2")
_XMLCreateChildNode("/Sites/Site[2]", "Building")
_XMLCreateChildNode("/Sites/Site[2]/Building[1]", "Name", "Building 1")
_XMLCreateChildNode("/Sites/Site[2]/Building[1]", "Floor", "Ground Floor")
_XMLCreateChildNode("/Sites/Site[2]/Building[1]", "Floor", "1st Floor")

Produces this XML file:

<?xml version="1.0"?>
<Sites>
    <Site>
        <Name>Site 1</Name>
        <Building>
            <Name>Building 1</Name>
            <Floor>Ground Floor</Floor>
            <Floor>1st Floor</Floor>
            <Floor>2nd Floor</Floor>
        </Building>
            <Building>Building 2<Name>Building 1</Name>
            <Floor>1st Floor</Floor>
            <Floor>2nd Floor</Floor>
        </Building>
    </Site>
    <Site>
        <Name>Site 2</Name>
        <Building>
            <Name>Building 1</Name>
            <Floor>Ground Floor</Floor>
            <Floor>1st Floor</Floor>
        </Building>
    </Site>
</Sites>

The hierarchical nature of data in an XML file makes it better than an INI file or simple flat text.

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Good afternoon,

Thank you for your reply. However I don't have a great deal of experience utilising XML with a combo box in AutoIT. I've searched the forum and couldn't find an example which would apply to the situation.

I know that I need to add the data to an array but I'm unsure how to interrogate the data for whats required...

Here is the code I have so far...

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#Include <GuiComboBox.au3>
#include <Array.au3>

Opt('GUIOnEventMode' , 1)

Global $Application = "Computer Location"
Local $File_Locations = FileOpen(@ScriptDir & "\sites.txt", 0)

; Check if file opened for reading OK
If $File_Locations = -1 Then
    MsgBox(48, $Application, "Unable to open 'sites.txt' file.")
    Exit
EndIf

; Read in lines of text until the EOF is reached
While 1
    $get_Locations = FileReadLine($File_Locations)
    If @error = -1 Then ExitLoop
    $Locations_Array = StringSplit($get_Locations, ",")

        ; <-- STUCK HERE -->
WEnd

; GUI
GuiCreate($Application, 210, 180, -1,-1, BitOR($WS_CAPTION, $WS_POPUP, $WS_BORDER, $WS_CLIPSIBLINGS), $WS_EX_WINDOWEDGE)

$Combo_Site = GUICtrlCreateCombo("", 5, 25, 200, 25, $CBS_DROPDOWN)
;~ GUICtrlSetData($Combo_Site, $Sites)
_GUICtrlComboBox_SetEditText($Combo_Site, "<SITE>")

$Combo_Building = GUICtrlCreateCombo("", 5, 50, 200, 25)
_GUICtrlComboBox_SetEditText($Combo_Building, "<BUILDING>")

$Combo_Floor = GUICtrlCreateCombo("", 5, 75, 200, 25)
_GUICtrlComboBox_SetEditText($Combo_Floor, "<FLOOR>")

$Input_Department = GuiCtrlCreateInput("<DEPARTMENT>", 5, 100, 200, 20)

$Input_Room = GuiCtrlCreateInput("<ROOM NUMBER>", 5, 125, 200, 20)

$Button_Submit = GUICtrlCreateButton("Submit", 130, 150, 75, 25, 0)
GUICtrlSetOnEvent($Button_Submit,"_CheckData")

GuiSetState()

; GUI MESSAGE LOOP
While 1  ; Main script loop
    Sleep (250)
WEnd


Func _CheckData()
    Local $Department = Guictrlread($Input_Department)
    Local $Floor = Guictrlread($Combo_Floor)
    Local $Building = Guictrlread($Combo_Building)
    Local $Site = Guictrlread($Combo_Site)
    Local $RoomNumber = Guictrlread($Input_Room)

    $Confirm_Data = MsgBox (4, $Application, "Please review the following information:" & @CRLF & @CRLF &  "Department: " & $Department & @CRLF & "Floor: " & $Floor & @CRLF & "Building: " & $Building & @CRLF & "Site: " & $Site & @CRLF & "Room Number:" & $RoomNumber)
    If $Confirm_Data = 7 Then
        Return
    Else
        ; <-- INSERT SCRIPT FUNCTION TO TAG DATA TO WORKSTATION OBJECT IN ACTIVE DIRECTORY -->
        MsgBox(0, $Application & " DEBUG", "Data Submitted: " & $Department & ", " & $Floor & ", " & $Building & ", " & $Site & ", " & $RoomNumber)
    EndIf
    Exit
EndFunc

Exit

Words of Wisdom and Favourite Quotes:

'Nothing is impossible, despite what other people say and think, prove them wrong and show them what you can do!'

'Understanding is a three edged sword, your side, their side and the truth!'

'The truth that humanity has never been able to grasp, is that death may be the only absolute freedom there is!'

'I've run out of places to put the brush... what do you suggest?'

Link to comment
Share on other sites

Hello again, I've found some Source Code which an old colleague used to create a similiar program with Visual Studio 6.0. I believe the following will resolve my problem. however I will need help converting it...:

#### START OF SAMPLE ####

Private Sub PopulateLocation()

ReDim Location1(0)

Open App.Path + "\sites.txt" For Input As #1

strArray = Split(Input(LOF(1), 1), vbCrLf)

Close #1

' Let's split the string by end of line chars

For k = LBound(strArray) To UBound(strArray)

locations = Split(strArray(k), ",")

If isInArray(Location1, locations(0)) = False Then

Location1(UBound(Location1)) = locations(0)

ReDim Preserve Location1(UBound(Location1) + 1)

End If

Next k

ReDim Preserve Location1(UBound(Location1) - 1)

For k = LBound(Location1) To UBound(Location1)

Form1.LocationCombo1.AddItem (Location1(k))

Next k

Dim Location3 As String

End Sub

-----------------------------------------------------------------------------------------------------------------

Private Sub LocationCombo1_Click()

narrowDownBuildings

End Sub

-----------------------------------------------------------------------------------------------------------------

Private Sub LocationCombo2_Click()

narrowDownFloors

End Sub

-----------------------------------------------------------------------------------------------------------------

Private Sub narrowDownBuildings()

ReDim Location2(0)

Form1.LocationCombo2.Clear

Form1.LocationCombo3.Clear

For k = LBound(strArray) To UBound(strArray)

locations = Split(strArray(k), ",")

If Form1.LocationCombo1.Text = locations(0) Then

If isInArray(Location2, locations(1)) = False Then

Location2(UBound(Location2)) = locations(1)

ReDim Preserve Location2(UBound(Location2) + 1)

End If

End If

Next k

ReDim Preserve Location2(UBound(Location2) - 1)

For k = LBound(Location2) To UBound(Location2)

Form1.LocationCombo2.AddItem (Location2(k))

Next k

End Sub

-----------------------------------------------------------------------------------------------------------------

Private Sub narrowDownFloors()

ReDim Location3(0)

Form1.LocationCombo3.Clear

For k = LBound(strArray) To UBound(strArray)

locations = Split(strArray(k), ",")

If Form1.LocationCombo1.Text = locations(0) And Form1.LocationCombo2.Text = locations(1) Then

If isInArray(Location3, locations(2)) = False Then

Location3(UBound(Location3)) = locations(2)

ReDim Preserve Location3(UBound(Location3) + 1)

End If

End If

Next k

ReDim Preserve Location3(UBound(Location3) - 1)

For k = LBound(Location3) To UBound(Location3)

Form1.LocationCombo3.AddItem (Location3(k))

Next k

End Sub

#### END OF SAMPLE ####

Edited by PlayZoneUK

Words of Wisdom and Favourite Quotes:

'Nothing is impossible, despite what other people say and think, prove them wrong and show them what you can do!'

'Understanding is a three edged sword, your side, their side and the truth!'

'The truth that humanity has never been able to grasp, is that death may be the only absolute freedom there is!'

'I've run out of places to put the brush... what do you suggest?'

Link to comment
Share on other sites

An example using sqlite

#include <GUIConstantsEx.au3>
#include <sqlite.au3>
#include <sqlite.dll.au3>

Opt('GUIOnEventMode' , 1)

Local $hQuery,$aRow
_SQLite_Startup()
ConsoleWrite("_SQLite_LibVersion=" &_SQLite_LibVersion() & @CRLF)
_SQLite_Open()
_SQLite_Exec(-1,"CREATE TABLE Floors (FloorID INTEGER NOT NULL PRIMARY KEY, FloorName TEXT);" & _
                "Insert into Floors (FloorName) values ('GroundFloor');" & _
                "Insert into Floors (FloorName) values ('1st Floor');" & _
                "Insert into Floors (FloorName) values ('2nd Floor');")

_SQLite_Exec(-1,"CREATE TABLE Buildings (BuildingID INTEGER NOT NULL PRIMARY KEY, BuildingName TEXT);" & _
                "Insert into Buildings (BuildingName) values ('Building 1');" & _
                "Insert into Buildings (BuildingName) values ('Building 2');")

_SQLite_Exec(-1,"CREATE TABLE Site (SiteName TEXT, BuildingID INTEGER, FloorID INTEGER);" & _
                "Insert into Site (SiteName,BuildingID,FloorID) values ('Site 1','1','1');" & _
                "Insert into Site (SiteName,BuildingID,FloorID) values ('Site 1','1','2');" & _
                "Insert into Site (SiteName,BuildingID,FloorID) values ('Site 1','1','3');" & _
                "Insert into Site (SiteName,BuildingID,FloorID) values ('Site 1','2','2');" & _
                "Insert into Site (SiteName,BuildingID,FloorID) values ('Site 1','2','3');" & _
                "Insert into Site (SiteName,BuildingID,FloorID) values ('Site 2','1','1');" & _
                "Insert into Site (SiteName,BuildingID,FloorID) values ('Site 2','1','2');")


GUICreate("Test")
$hSiteCombo = GUICtrlCreateCombo("",5,5)
GUICtrlSetOnEvent(-1, "_SiteCombo")
$hBuildingCombo = GUICtrlCreateCombo("",5,30)
GUICtrlSetOnEvent(-1, "_BuildingCombo")
GUICtrlSetState($hBuildingCombo,$GUI_DISABLE)
$hFloorCombo = GUICtrlCreateCombo("",5,55)
GUICtrlSetState($hFloorCombo,$GUI_DISABLE)
Local $hQuery
_SQlite_Query (-1, "SELECT DISTINCT SiteName FROM Site ;", $hQuery)
While _SQLite_FetchData ($hQuery, $aRow, False, False) = $SQLITE_OK ; Read Out the next Row
    GUICtrlSetData($hSiteCombo,$aRow[0])
WEnd

GUISetOnEvent($GUI_EVENT_CLOSE, "_Close")
GUISetState()


While 1
    Sleep (250)
WEnd

Func _SiteCombo()

    $sSiteSelection = guictrlread($hSiteCombo)
    GUICtrlSetData($hBuildingCombo,"")
    Local $hQuery
    _SQlite_Query (-1, "Select Distinct BuildingName From Buildings,Site WHERE SiteName = '" & $sSiteSelection & "' AND Site.BuildingID = Buildings.BuildingID", $hQuery)
    While _SQLite_FetchData ($hQuery, $aRow, False, False) = $SQLITE_OK
        GUICtrlSetData($hBuildingCombo,$aRow[0])
    WEnd
    GUICtrlSetState($hBuildingCombo,$GUI_ENABLE)
    GUICtrlSetData($hFloorCombo,"")
    GUICtrlSetState($hFloorCombo,$GUI_DISABLE)
EndFunc

Func _BuildingCombo()
    $sSiteSelection = guictrlread($hSiteCombo)
    $sBuildingSelection = guictrlread($hBuildingCombo)
    GUICtrlSetData($hFloorCombo,"")
    Local $hQuery
    _SQlite_Query (-1, "Select FloorName From Floors,Site,Buildings WHERE SiteName = '" & $sSiteSelection & "' AND BuildingName = '" & $sBuildingSelection & "' AND Site.FloorID = Floors.FloorID AND Site.BuildingID = Buildings.BuildingID", $hQuery)
    While _SQLite_FetchData ($hQuery, $aRow, False, False) = $SQLITE_OK
        GUICtrlSetData($hFloorCombo,$aRow[0])
    WEnd
    GUICtrlSetState($hBuildingCombo,$GUI_ENABLE)
    GUICtrlSetState($hFloorCombo,$GUI_ENABLE)
EndFunc


Func _Close()
    _SQLite_Close()
_SQLite_Shutdown()
    Exit
EndFunc
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

Thanks for the example Yoriz, parts of it have pointed me in the right direction (i.e. The disabling and enabling of the Combo Boxes which I've been working on this afternoon). I've changed my variable naming convention to match yours. Here is what I have so far utilising a text file method:

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#Include <GuiComboBox.au3>
#include <Array.au3>

Opt('GUIOnEventMode' , 1)

Global $Application = "Computer Location"
Global $File_Locations = FileOpen(@ScriptDir & "\sites.txt", 0)

; Check if file opened for reading OK
If $File_Locations = -1 Then
    MsgBox(48, $Application, "Unable to open 'sites.txt' file.")
    Exit
EndIf

; GUI
GuiCreate($Application, 210, 180, -1,-1, BitOR($WS_CAPTION, $WS_POPUP, $WS_BORDER, $WS_CLIPSIBLINGS), $WS_EX_WINDOWEDGE)

$hSiteCombo = GUICtrlCreateCombo("",5,25)
GUICtrlSetOnEvent(-1, "_SiteCombo")
$hBuildingCombo = GUICtrlCreateCombo("",5,50)
GUICtrlSetOnEvent(-1, "_BuildingCombo")
GUICtrlSetState($hBuildingCombo,$GUI_DISABLE)
$hFloorCombo = GUICtrlCreateCombo("",5,75)
GUICtrlSetState($hFloorCombo,$GUI_DISABLE)
$hDepartmentInput = GuiCtrlCreateInput("<DEPARTMENT>", 5, 100)
GUICtrlSetState($hDepartmentInput, $GUI_DISABLE)
$hRoomNumberInput = GuiCtrlCreateInput("<ROOM NUMBER>", 5, 125)
GUICtrlSetState($hRoomNumberInput, $GUI_DISABLE)

$Button_Cancel = GUICtrlCreateButton("Cancel", 50, 150, 75, 25, 0)
GUICtrlSetOnEvent($Button_Cancel,"_Quit")

$Button_Submit = GUICtrlCreateButton("Submit", 130, 150, 75, 25, 0)
GUICtrlSetOnEvent($Button_Submit,"_CheckData")
GUICtrlSetState($Button_Submit, $GUI_DISABLE)

While 1
    $get_Locations = FileReadLine($File_Locations)
    If @error = -1 Then ExitLoop
    $Array = StringSplit($get_Locations, ",")
    GUICtrlSetData($hSiteCombo, $Array[1])
WEnd

_GUICtrlComboBox_SetEditText($hSiteCombo, "<SITE>")
_GUICtrlComboBox_SetEditText($hBuildingCombo, "<BUILDING>")
_GUICtrlComboBox_SetEditText($hFloorCombo, "<FLOOR>")

GuiSetState()

; GUI MESSAGE LOOP
While 1  ; Main script loop
    Sleep(250)
WEnd

Func _SiteCombo()
    $sSiteSelection = guictrlread($hSiteCombo)
    GUICtrlSetData($hBuildingCombo,"")
    While 1
        $get_Locations = FileReadLine($File_Locations)
        If @error = -1 Then ExitLoop
        Local $Array = StringSplit($get_Locations, ",")
        If $sSiteSelection = $Array[1] Then GUICtrlSetData($hBuildingCombo, $Array[2])
    WEnd

    GUICtrlSetState($hBuildingCombo,$GUI_ENABLE)
    GUICtrlSetData($hFloorCombo,"")
    GUICtrlSetState($hFloorCombo,$GUI_DISABLE)
    _GUICtrlComboBox_SetEditText($hBuildingCombo, "<BUILDING>")
    _GUICtrlComboBox_SetEditText($hFloorCombo, "<FLOOR>")
EndFunc

Func _BuildingCombo()
    $sSiteSelection = guictrlread($hSiteCombo)
    $sBuildingSelection = guictrlread($hBuildingCombo)
    GUICtrlSetData($hFloorCombo,"")
    While 1
        $get_Locations = FileReadLine($File_Locations)
        If @error = -1 Then ExitLoop
        Local $Array = StringSplit($get_Locations, ",")
        If $sBuildingSelection = $Array[2] Then GUICtrlSetData($hFloorCombo, $Array[3])
    WEnd

    GUICtrlSetState($hBuildingCombo,$GUI_ENABLE)
    GUICtrlSetState($hFloorCombo,$GUI_ENABLE)
    _GUICtrlComboBox_SetEditText($hFloorCombo, "<FLOOR>")
EndFunc

Func _CheckData()
    Local $Department = Guictrlread($hDepartmentInput)
    Local $Floor = Guictrlread($hFloorCombo)
    Local $Building = Guictrlread($hBuildingCombo)
    Local $Site = Guictrlread($hSiteCombo)
    Local $RoomNumber = Guictrlread($hRoomNumberInput)

    $Confirm_Data = MsgBox (4, $Application, "Please review the following information:" & @CRLF & @CRLF & "Department: " & $Department & @CRLF & "Floor: " & $Floor & @CRLF & "Building: " & $Building & @CRLF & "Site: " & $Site & @CRLF & "Room Number:" & $RoomNumber  & @CRLF & @CRLF & "Is the information correct?")
    If $Confirm_Data = 7 Then
        Return
    Else
        ; <-- INSERT SCRIPT FUNCTION TO TAG DATA TO WORKSTATION OBJECT IN ACTIVE DIRECTORY -->
        MsgBox(0, $Application & " DEBUG", "Data Submitted: " & $Department & ", " & $Floor & ", " & $Building & ", " & $Site & ", " & $RoomNumber)
    EndIf
    _Quit()
EndFunc

Func _Quit()
    GUIDelete()
    FileClose($File_Locations)
    Exit
EndFunc

The problem starts on the second combo box, it doesn't appear that any thing is retrieved from the Text file... any suggestions?

Edited by PlayZoneUK

Words of Wisdom and Favourite Quotes:

'Nothing is impossible, despite what other people say and think, prove them wrong and show them what you can do!'

'Understanding is a three edged sword, your side, their side and the truth!'

'The truth that humanity has never been able to grasp, is that death may be the only absolute freedom there is!'

'I've run out of places to put the brush... what do you suggest?'

Link to comment
Share on other sites

You would have to include the text file 'sites.txt' for testing of your script.

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

Sorry forgot, please find the requested file attached to this post

sites.txt

Words of Wisdom and Favourite Quotes:

'Nothing is impossible, despite what other people say and think, prove them wrong and show them what you can do!'

'Understanding is a three edged sword, your side, their side and the truth!'

'The truth that humanity has never been able to grasp, is that death may be the only absolute freedom there is!'

'I've run out of places to put the brush... what do you suggest?'

Link to comment
Share on other sites

You just need some nested loops.

So in the loop where you handle each line, note where the first field changes, indicating a new site. While the site remains constant, watch for changes in the second field (new building), and while the building remains constant, each entry is a new floor.

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Ive fixed it , the problem was the 'FileReadLine ', each time this is called without setting the optional line number to read, it just reads the next line. It has already read through the whole file when filing the site combo, to cure this i made it read from the start of the file again by adding the line number to read.

Something to think about though, you are reading the through the same file to create the same array over and over, maybe just read the file once to create the array and just use the same array for each combo, although it would then need to be a multi dimensional which you may not have played with yet.

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#Include <GuiComboBox.au3>
#include <Array.au3>

Opt('GUIOnEventMode' , 1)

Global $Application = "Computer Location"
Global $File_Locations = FileOpen(@ScriptDir & "\sites.txt", 0)

; Check if file opened for reading OK
If $File_Locations = -1 Then
    MsgBox(48, $Application, "Unable to open 'sites.txt' file.")
    Exit
EndIf

; GUI
GuiCreate($Application, 210, 180, -1,-1, BitOR($WS_CAPTION, $WS_POPUP, $WS_BORDER, $WS_CLIPSIBLINGS), $WS_EX_WINDOWEDGE)

$hSiteCombo = GUICtrlCreateCombo("",5,25)
GUICtrlSetOnEvent(-1, "_SiteCombo")
$hBuildingCombo = GUICtrlCreateCombo("",5,50)
GUICtrlSetOnEvent(-1, "_BuildingCombo")
GUICtrlSetState($hBuildingCombo,$GUI_DISABLE)
$hFloorCombo = GUICtrlCreateCombo("",5,75)
GUICtrlSetOnEvent(-1, "_FloorCombo")
GUICtrlSetState($hFloorCombo,$GUI_DISABLE)
$hDepartmentInput = GuiCtrlCreateInput("<DEPARTMENT>", 5, 100)
GUICtrlSetState($hDepartmentInput, $GUI_DISABLE)
$hRoomNumberInput = GuiCtrlCreateInput("<ROOM NUMBER>", 5, 125)
GUICtrlSetState($hRoomNumberInput, $GUI_DISABLE)

$Button_Cancel = GUICtrlCreateButton("Cancel", 50, 150, 75, 25, 0)
GUICtrlSetOnEvent($Button_Cancel,"_Quit")

$Button_Submit = GUICtrlCreateButton("Submit", 130, 150, 75, 25, 0)
GUICtrlSetOnEvent($Button_Submit,"_CheckData")
GUICtrlSetState($Button_Submit, $GUI_DISABLE)

While 1
    $get_Locations = FileReadLine($File_Locations)
    If @error = -1 Then ExitLoop
    $Array = StringSplit($get_Locations, ",")
    GUICtrlSetData($hSiteCombo, $Array[1])
WEnd

_GUICtrlComboBox_SetEditText($hSiteCombo, "<SITE>")
_GUICtrlComboBox_SetEditText($hBuildingCombo, "<BUILDING>")
_GUICtrlComboBox_SetEditText($hFloorCombo, "<FLOOR>")

GuiSetState()

; GUI MESSAGE LOOP
While 1  ; Main script loop
    Sleep(250)
WEnd

Func _SiteCombo()
    $sSiteSelection = guictrlread($hSiteCombo)
    GUICtrlSetData($hBuildingCombo,"")
    $iFileLine = 1
    While 1
        $get_Locations = FileReadLine($File_Locations,$iFileLine)
        If @error = -1 or $get_Locations = "" Then ExitLoop
        Local $Array = StringSplit($get_Locations, ",")
        If $sSiteSelection = $Array[1] Then GUICtrlSetData($hBuildingCombo, $Array[2])
        $iFileLine +=1
    WEnd

    GUICtrlSetState($hBuildingCombo,$GUI_ENABLE)
    GUICtrlSetData($hFloorCombo,"")
    GUICtrlSetState($hFloorCombo,$GUI_DISABLE)
    _GUICtrlComboBox_SetEditText($hBuildingCombo, "<BUILDING>")
    _GUICtrlComboBox_SetEditText($hFloorCombo, "<FLOOR>")
EndFunc

Func _BuildingCombo()
    $sSiteSelection = guictrlread($hSiteCombo)
    $sBuildingSelection = guictrlread($hBuildingCombo)
    GUICtrlSetData($hFloorCombo,"")
    $iFileLine = 1
    While 1
        $get_Locations = FileReadLine($File_Locations,$iFileLine)
        If @error = -1 or $get_Locations = "" Then ExitLoop
        Local $Array = StringSplit($get_Locations, ",")
        If $sBuildingSelection = $Array[2] Then GUICtrlSetData($hFloorCombo, $Array[3])
        $iFileLine +=1
    WEnd

    GUICtrlSetState($hBuildingCombo,$GUI_ENABLE)
    GUICtrlSetState($hFloorCombo,$GUI_ENABLE)
    _GUICtrlComboBox_SetEditText($hFloorCombo, "<FLOOR>")
EndFunc

Func _FloorCombo()
    $sSelection = guictrlread($hFloorCombo)
    If $sSelection <> "" Then
        GUICtrlSetState($hDepartmentInput, $GUI_ENABLE)
    EndIf
EndFunc


Func _CheckData()
    Local $Department = Guictrlread($hDepartmentInput)
    Local $Floor = Guictrlread($hFloorCombo)
    Local $Building = Guictrlread($hBuildingCombo)
    Local $Site = Guictrlread($hSiteCombo)
    Local $RoomNumber = Guictrlread($hRoomNumberInput)

    $Confirm_Data = MsgBox (4, $Application, "Please review the following information:" & @CRLF & @CRLF & "Department: " & $Department & @CRLF & "Floor: " & $Floor & @CRLF & "Building: " & $Building & @CRLF & "Site: " & $Site & @CRLF & "Room Number:" & $RoomNumber  & @CRLF & @CRLF & "Is the information correct?")
    If $Confirm_Data = 7 Then
        Return
    Else
        ; <-- INSERT SCRIPT FUNCTION TO TAG DATA TO WORKSTATION OBJECT IN ACTIVE DIRECTORY -->
        MsgBox(0, $Application & " DEBUG", "Data Submitted: " & $Department & ", " & $Floor & ", " & $Building & ", " & $Site & ", " & $RoomNumber)
    EndIf
    _Quit()
EndFunc

Func _Quit()
    GUIDelete()
    FileClose($File_Locations)
    Exit
EndFunc
Edited by Yoriz
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

  • 2 weeks later...

Cheers Yoriz... sorry I didn't reply to you sooner.

I thought it had something to do with that, but I wasn't thinking straight . I will take your advice and look at using an array

Thanks again

Words of Wisdom and Favourite Quotes:

'Nothing is impossible, despite what other people say and think, prove them wrong and show them what you can do!'

'Understanding is a three edged sword, your side, their side and the truth!'

'The truth that humanity has never been able to grasp, is that death may be the only absolute freedom there is!'

'I've run out of places to put the brush... what do you suggest?'

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