
    nomainwin

    WindowWidth = 550
    WindowHeight = 410

    Gosub [initNames]

    button #main.button1, "FULLTIME (7.2 Hours 5 Days)", [button1Click], UL, 118, 84, 234, 25
    button #main.button2, "PART-TIME (7.2 hours 4 Days)", [button2Click], UL, 118, 135, 234, 25
    button #main.button3, "PART-TIME (5 Hours 5 Days)", [button3Click], UL, 118, 189, 234, 25
    statictext #main.stxt91,Chr$(169) + "Sharmila Kuys  2007" ,300,300,296,20
    open "untitled" for window as #main
    print #main, "font ms_sans_serif 0 16"


[main.inputLoop]   'wait here for input event
    wait



[button1Click]   'Perform action for the button named 'button1'
    'Insert your own code here
   nomainwin

    WindowWidth = 550
    WindowHeight = 410

    combobox #main1.names, Names$(, [NameSelect], 110, 30, 140, 28

   open "untitled" for window as #main1
    print #main1, "font ms_sans_serif 0 16"

    ' Perform action for #main.names 'Name' combobox
' open a dialog window to allow adding, editing, deleting and moving List items
[NameSelect]
    Print #main1.names, "selectionindex? index" ' see which combobox item was selected
    ' the first index item in the combobox is '<Edit Names>'
    If index = 1 Then [EditAccessNameList]    ' open "Edit Names" dialog window
    Wait
    ' in another program possibly do something with the combobox item selected
    msg$ = "Name Combobox Selection Demo";Chr$(13);_
           "You selected '";Names$(index);"'";Chr$(13);Chr$(13);_
           "To see the main demo of this program,";Chr$(13);_
           "Please select <Edit Names> from the Name list." ';Chr$(13);
    Notice msg$
    Wait

' called if '<Edit Names>' is double clicked on in the #main.names 'Names' Combobox
[EditAccessNameList]
    ' store orginal NameQty for [EditBuildaNameList] routine and Cancel button;
    orgNameQty=NameQty                         ' to restore data file and array
    NameQty=NameQty+2          ' reset NameQty for [EditBuildaNameList] routine
    Gosub [EditBuildaNameList] ' store Names$( array in aNameList$ string
    NameQty=orgNameQty         ' restore original NameQty
    orgNameList$ = aNameList$  ' store original Names$( array for cancel button
    aNameList$ = ""            ' clear memory

    ' open a dialog_modal window to edit name list:
    WindowWidth = 375
    WindowHeight = 200
    UpperLeftX = 20
    UpperLeftY = 20

    For i = 1 to NameQty + 1   ' fix Names$( array to only show Names
        Names$(i) = Names$(i+1)
    Next i

    Statictext #d, "Name List:", 7, 10, 60, 15
    ' listbox for selecting names to edit/delete/move up/down
    Listbox #d.lst, Names$(, [EditChgName], 7, 28, 240, 122
    ' ok button to accept changes &/or close window
    Button #d, "&Ok", [EditOk], UL, 295, 15, 65, 25
    Button #d, "&Add", [EditAddName], UL, 295, 43, 65, 25
    Button #d, "&Edit", [EditChgName], UL, 295, 71, 65, 25
    Button #d, "&Delete", [EditDeleteName], UL, 295, 99, 65, 25
    Button #d, "?", [EditNamesHelp], UL, 258, 58, 25, 20
    Button #d, "/\", [EditMoveUp], UL, 258, 115, 25, 16
    Button #d, "\/", [EditMoveDown], UL, 258, 134, 25, 16
    ' cancel button to cancel changes & close window
    Button #d, "&Cancel", [EditCancel], UL, 295, 127, 65, 25
    Open "Edit Names" for Dialog_modal as #d
    Print #d, "trapclose [quitd]"
    Wait

' Perform action for 'Add' button in 'Edit Names' dialog window
' adds a listbox item to the Names$( array and updates data file
[EditAddName]
    Goto [EditAddNameWinOpen]
    Prompt "Add New Name to Name List"+Chr$(13)+"Add Name:"; aNewName$
    If aNewName$ = "" Then Wait

    ' ? check for duplicate names possibly in Names$( array - ?

    ' store Names$( array in aNameList$ string so array can be redimmed
    Gosub [EditBuildaNameList]  ' and then restored with new name added
    aNameList$ = aNameList$ + aNewName$  ' add new name to list string
    NameQty = NameQty + 1
    Redim Names$(NameQty + 2)
    For i = 1 to NameQty
        'aName$ = Word$(aNameList$, i, Chr$(13))  ' enable for debugging
        Names$(i) = Word$(aNameList$, i, Chr$(13))
    Next i
    aNameList$ = ""   ' free memory
    Print #d.lst, "reload"    ' update listbox with added name
    Print #d.lst, "selectindex ";NameQty
    Gosub [EditSaveNameList]  ' update data file with Names$( array
    Wait

[EditAddNameWinOpen]
    WindowWidth = 350
    WindowHeight = 240
    UpperLeftX = 20
    UpperLeftY = 20
    Statictext #e, "Employee Name:", 10,17,80,15
    Textbox #e.tbx, 10,37,240,25
    Button #e, "&Ok",[EditAddNameWinOk],UL 10,75,65,25
    Button #e, "&Cancel",[EditAddNameWinCancel],UL 80,75,65,25
    Button #e, "&Advanced...",[EditAddNameWinAdvanced],UL 150,75,98,25
    Open "Add New Name to Name List" for dialog_modal as #e
    Print #e, "trapclose [EditAddNameWinCancel]"
    Wait

[EditAddNameWinOpen2]
    WindowWidth = 270
    WindowHeight = 140
    UpperLeftX = 20
    UpperLeftY = 20
    Statictext #e, "Add Name:", 10,17,80,15
    Textbox #e.tbx, 10,37,240,25
    Button #e, "&Ok",[EditAddNameWinOk],UL 10,75,65,25
    Button #e, "&Cancel",[EditAddNameWinCancel],UL 80,75,65,25
    Button #e, "&Advanced...",[EditAddNameWinAdvanced],UL 150,75,98,25
    Open "Add New Name to Name List" for dialog_modal as #e
    Print #e, "trapclose [EditAddNameWinCancel]"
    Wait

[EditAddNameWinOk]
    Print #e.tbx, "!Contents? aNewName$"
    Close #e
    If aNewName$ = "" Then Wait
    ' ? check for duplicate names possibly in Names$( array - ?

    ' store Names$( array in aNameList$ string so array can be redimmed
    Gosub [EditBuildaNameList]  ' and then restored with new name added
    aNameList$ = aNameList$ + aNewName$  ' add new name to list string
    NameQty = NameQty + 1
    Redim Names$(NameQty + 2)
    For i = 1 to NameQty
        'aName$ = Word$(aNameList$, i, Chr$(13))  ' enable for debugging
        Names$(i) = Word$(aNameList$, i, Chr$(13))
    Next i
    aNameList$ = ""   ' free memory
    Print #d.lst, "reload"    ' update listbox with added name
    Print #d.lst, "selectindex ";NameQty
    Gosub [EditSaveNameList]  ' update data file with Names$( array
    Wait

[EditAddNameWinCancel]
    ' user cancelled so don't change name list, etc.
    Close #e
    Wait

[EditAddNameWinAdvanced]
    Notice "Sorry, not yet available."
    ' open another dialog_modal window to enable:
    ' get/change username/password; initialize files
    Wait


' called by a few routines to save changes in the Name data file;
' updates Names data file using NameQty and Names$( array items
[EditSaveNameList]
    ' update/rewrite data file adding new name
    Open "MyNamesFile.txt" for Output as #afile
    Print #afile, NameQty
    For i = 1 to NameQty
        'aName$ = Names$(i)  ' enable for debugging
        Print #afile, Names$(i)
    Next i
    Close #afile
    NameFileChangedFlag = 1   ' set flag as file changed for Cancel button
    Return

' store Names$( array in aNameList$ string
[EditBuildaNameList]
    aNameList$ = ""  ' initialize to null
    For i = 1 to NameQty
        aName$ = Names$(i)
        aNameList$ = aNameList$ + Names$(i) + Chr$(13)
    Next i
    Return

' Perform action for 'Edit' button in 'Edit Names' dialog window
' and is called after a listbox item is double clicked on
' edits selected listbox item in the Names$( array and updates data file
[EditChgName]
    Print #d.lst, "selection? aName$"
    Print #d.lst, "selectionindex? nameIndex"
    Prompt "Edit Name in Name List"+Chr$(13)+"Edit Name:"; aName$ 
    ' if edit was cancelled or no change was made then wait
    If aName$ = "" or aName$ = Names$(nameIndex) Then Wait
    ' update array and file
    Names$(nameIndex) = aName$
    #d.lst, "reload"  ' update name in listbox
    #d.lst, "selectindex ";nameIndex
    Gosub [EditSaveNameList]  ' update data file with Names$( array
    Wait

' Perform action for 'Delete' button in 'Edit Names' dialog window
' deletes selected listbox item from the Names$( array and updates data file
[EditDeleteName]
    Print #d.lst, "selection? aName$"
    If aName$ = "" Then Wait
    Confirm "Do you wish to delete '"+aName$+"' from the Name list?";ans$
    If ans$ = "no" Then Wait
    Print #d.lst, "selectionindex? nameIndex"

    ' store names in aNameList$
    Gosub [EditBuildaNameList]  ' store Names$( array in aNameList$ string
    NameQty = NameQty - 1
    Redim Names$(NameQty+2)
    a = 0
    For i = 1 to NameQty + 1  ' go through original number of names
        If i <> nameIndex Then
            a = a + 1
            'aName$ = Word$(aNameList$, i, Chr$(13))  ' enable for debugging
            Names$(a) = Word$(aNameList$, i, Chr$(13))
        End If
    Next i
    aNameList$ = ""   ' free memory
    #d.lst, "reload"  ' update names in listbox
    If nameIndex > NameQty Then nameIndex = NameQty
    #d.lst, "selectindex ";nameIndex
    Gosub [EditSaveNameList]       ' update data file with Names$( array
    Wait

' Perform action for '\/' button in 'Edit Names' dialog window
' moves Names$( array item down in the array and saves array in data file
[EditMoveDown]
    Print #d.lst, "selection? aName$"
    If aName$ = "" Then Wait
    Print #d.lst, "selectionindex? nameIndex"
    If nameIndex = NameQty Then Wait    ' it's already the last item
    Names$(nameIndex) = Names$(nameIndex+1)
    Names$(nameIndex+1) = aName$
    #d.lst, "reload"  ' update names in listbox
    #d.lst, "selectindex ";nameIndex+1  ' show item in it's new location
    Gosub [EditSaveNameList]       ' update data file with Names$( array
    Wait


' Perform action for '/\' button in 'Edit Names' dialog window
' moves Names$( array item up in the array and saves array in data file
[EditMoveUp]
    Print #d.lst, "selection? aName$"
    If aName$ = "" Then Wait
    Print #d.lst, "selectionindex? nameIndex"
    If nameIndex = 1 Then Wait     ' it's already the first item
    Names$(nameIndex) = Names$(nameIndex-1)
    Names$(nameIndex-1) = aName$
    #d.lst, "reload"  ' update names in listbox
    #d.lst, "selectindex ";nameIndex-1  ' show item in it's new location
    Gosub [EditSaveNameList]       ' update data file with Names$( array
    Wait

' Perform action for '?' button in 'Edit Names' dialog window
' shows a help Notice window for all buttons on 'Edit Names' dialog window
[EditNamesHelp]
    n$=Chr$(13)
    msg$ = "Edit Names Help";Chr$(13);_
           "Ok: Closes window, updating Name list with any changes.";_
        n$;"Add: Opens window to Add name to Name list.";_
        n$;"Edit: Opens window to Edit selected name in Name list.";_
        n$;" (Double clicking on name also opens Edit window.)";_
        n$;"Delete: Deletes selected name from Name list.";_
        n$;"Cancel: Closes window with no changes made to Name list.";_
        n$;"/\: Moves selected item up in the Name list.";_
        n$;"\/: Moves selected item down in the Name list."
    Notice msg$
    Wait

' Perform action for 'Ok' button in 'Edit Names' dialog window
' closes 'Edit Names' dialog window, restores Names$( array
' and clears selected combobox item for 'Name' combobox in main window
[EditOk]
    ' move items forward in array to readd <Edit Names> as first array item
    For i = NameQty to 1 Step -1
        Names$(i+1) = Names$(i)
    Next i
    Names$(1) = "<Edit Names>"
    #main.names, "reload"
    #main.names, "selectindex 0"  ' reset combobox to have nothing selected
    Close #d
    NameFileChangedFlag = 0  ' reset flag if needed
    Wait

' Perform action for 'Cancel' button in 'Edit Names' dialog window
' closes Edit Names dialog window without changing original Names$( array and file
[EditCancel]
    ' check flag:
    ' (if names in Name file were changed - restore original names in file)
    If NameFileChangedFlag = 1 Then Gosub [EditNamesRestoreNames]

    ' reset Names$( array for #main.names Combobox using original saved name list
    For i = 1 to NameQty+2
        aName$ = Word$(orgNameList$, i, Chr$(13))
        If aName$ = Chr$(13) Then aName$ = ""
        Names$(i) = aName$
    Next i

    #main2.names, "selectindex 0"  ' reset combobox to have nothing selected
    Close #d
    'Goto [quit]  ' debugging line; enable to close windows quickly
    NameFileChangedFlag = 0   ' reset flag if needed
    Wait

' called if user selects the cancel button after making changes to list items
[EditNamesRestoreNames]
    ' rebuild Names$( array from orgNameList$
    NameQty = orgNameQty
    Redim Names$(NameQty+2)

    ' build array for data file; so it can be returned as before
    For i = 2 to NameQty+1
        aName$ = Word$(orgNameList$, i, Chr$(13))
        If aName$ = Chr$(13) Then aName$ = ""
        Names$(i-1) = aName$
    Next i
    ' update data file with file's original data (NameQty & Names$( array)
    Gosub [EditSaveNameList]
    Return

' Initialize Names$( array for 'Name' Combobox in main window
[initNames]
    ' load Names from data file
    ' create file if needed to avoid error
    Open "MyNamesFile.txt" for Append as #afile
    Close #afile

    Open "MyNamesFile.txt" for Input as #afile
    If Eof(#afile) Then
        Close #afile
        Names$(1) = "<Edit Names>"
        Return
    End If
    Line Input #afile, NameQty
    Redim Names$(NameQty+2)
    Names$(1) = "<Edit Names>"
    i = 1
    While Eof(#afile)=0
        Line Input #afile, aName$
        If aName$="" Then Exit While
        i = i + 1
        Names$(i) = aName$
    Wend
    Close #afile
    Return

wait


[button2Click]   'Perform action for the button named 'button2'
    'Insert your own code here
     nomainwin

    WindowWidth = 550
    WindowHeight = 410

    combobox #main2.names, Names$(, [NameSelect], 110, 30, 140, 28

   open "untitled" for window as #main2
    print #main2, "font ms_sans_serif 0 16"

    ' Perform action for #main.names 'Name' combobox
' open a dialog window to allow adding, editing, deleting and moving List items
[NameSelect1]
    Print #main2.names, "selectionindex? index" ' see which combobox item was selected
    ' the first index item in the combobox is '<Edit Names>'
    If index = 1 Then [EditAccessNameList]    ' open "Edit Names" dialog window
    Wait
    ' in another program possibly do something with the combobox item selected
    msg$ = "Name Combobox Selection Demo";Chr$(13);_
           "You selected '";Names$(index);"'";Chr$(13);Chr$(13);_
           "To see the main demo of this program,";Chr$(13);_
           "Please select <Edit Names> from the Name list." ';Chr$(13);
    Notice msg$
    Wait

' called if '<Edit Names>' is double clicked on in the #main.names 'Names' Combobox
[EditAccessNameList1]
    ' store orginal NameQty for [EditBuildaNameList] routine and Cancel button;
    orgNameQty=NameQty                         ' to restore data file and array
    NameQty=NameQty+2          ' reset NameQty for [EditBuildaNameList] routine
    Gosub [EditBuildaNameList1] ' store Names$( array in aNameList$ string
    NameQty=orgNameQty         ' restore original NameQty
    orgNameList$ = aNameList$  ' store original Names$( array for cancel button
    aNameList$ = ""            ' clear memory

    ' open a dialog_modal window to edit name list:
    WindowWidth = 375
    WindowHeight = 200
    UpperLeftX = 20
    UpperLeftY = 20

    For i = 1 to NameQty + 1   ' fix Names$( array to only show Names
        Names$(i) = Names$(i+1)
    Next i

    Statictext #d, "Name List:", 7, 10, 60, 15
    ' listbox for selecting names to edit/delete/move up/down
    Listbox #d.lst, Names$(, [EditChgName], 7, 28, 240, 122
    ' ok button to accept changes &/or close window
    Button #d, "&Ok", [EditOk], UL, 295, 15, 65, 25
    Button #d, "&Add", [EditAddName], UL, 295, 43, 65, 25
    Button #d, "&Edit", [EditChgName], UL, 295, 71, 65, 25
    Button #d, "&Delete", [EditDeleteName], UL, 295, 99, 65, 25
    Button #d, "?", [EditNamesHelp], UL, 258, 58, 25, 20
    Button #d, "/\", [EditMoveUp], UL, 258, 115, 25, 16
    Button #d, "\/", [EditMoveDown], UL, 258, 134, 25, 16
    ' cancel button to cancel changes & close window
    Button #d, "&Cancel", [EditCancel], UL, 295, 127, 65, 25
    Open "Edit Names" for Dialog_modal as #d
    Print #d, "trapclose [quitd]"
    Wait

' Perform action for 'Add' button in 'Edit Names' dialog window
' adds a listbox item to the Names$( array and updates data file
[EditAddName1]
    Goto [EditAddNameWinOpen1]
    Prompt "Add New Name to Name List"+Chr$(13)+"Add Name:"; aNewName$
    If aNewName$ = "" Then Wait

    ' ? check for duplicate names possibly in Names$( array - ?

    ' store Names$( array in aNameList$ string so array can be redimmed
    Gosub [EditBuildaNameList1]  ' and then restored with new name added
    aNameList$ = aNameList$ + aNewName$  ' add new name to list string
    NameQty = NameQty + 1
    Redim Names$(NameQty + 2)
    For i = 1 to NameQty
        'aName$ = Word$(aNameList$, i, Chr$(13))  ' enable for debugging
        Names$(i) = Word$(aNameList$, i, Chr$(13))
    Next i
    aNameList$ = ""   ' free memory
    Print #d.lst, "reload"    ' update listbox with added name
    Print #d.lst, "selectindex ";NameQty
    Gosub [EditSaveNameList1]  ' update data file with Names$( array
    Wait

[EditAddNameWinOpen1]
    WindowWidth = 350
    WindowHeight = 240
    UpperLeftX = 20
    UpperLeftY = 20
    Statictext #e, "Employee Name:", 10,17,80,15
    Textbox #e.tbx, 10,37,240,25
    Button #e, "&Ok",[EditAddNameWinOk],UL 10,75,65,25
    Button #e, "&Cancel",[EditAddNameWinCancel],UL 80,75,65,25
    Button #e, "&Advanced...",[EditAddNameWinAdvanced],UL 150,75,98,25
    Open "Add New Name to Name List" for dialog_modal as #e
    Print #e, "trapclose [EditAddNameWinCancel]"
    Wait

[EditAddNameWinOpen21]
    WindowWidth = 270
    WindowHeight = 140
    UpperLeftX = 20
    UpperLeftY = 20
    Statictext #e, "Add Name:", 10,17,80,15
    Textbox #e.tbx, 10,37,240,25
    Button #e, "&Ok",[EditAddNameWinOk],UL 10,75,65,25
    Button #e, "&Cancel",[EditAddNameWinCancel],UL 80,75,65,25
    Button #e, "&Advanced...",[EditAddNameWinAdvanced],UL 150,75,98,25
    Open "Add New Name to Name List" for dialog_modal as #e
    Print #e, "trapclose [EditAddNameWinCancel]"
    Wait

[EditAddNameWinOk1]
    Print #e.tbx, "!Contents? aNewName$"
    Close #e
    If aNewName$ = "" Then Wait
    ' ? check for duplicate names possibly in Names$( array - ?

    ' store Names$( array in aNameList$ string so array can be redimmed
    Gosub [EditBuildaNameList1]  ' and then restored with new name added
    aNameList$ = aNameList$ + aNewName$  ' add new name to list string
    NameQty = NameQty + 1
    Redim Names$(NameQty + 2)
    For i = 1 to NameQty
        'aName$ = Word$(aNameList$, i, Chr$(13))  ' enable for debugging
        Names$(i) = Word$(aNameList$, i, Chr$(13))
    Next i
    aNameList$ = ""   ' free memory
    Print #d.lst, "reload"    ' update listbox with added name
    Print #d.lst, "selectindex ";NameQty
    Gosub [EditSaveNameList1]  ' update data file with Names$( array
    Wait

[EditAddNameWinCancel1]
    ' user cancelled so don't change name list, etc.
    Close #e
    Wait

[EditAddNameWinAdvanced1]
    Notice "Sorry, not yet available."
    ' open another dialog_modal window to enable:
    ' get/change username/password; initialize files
    Wait


' called by a few routines to save changes in the Name data file;
' updates Names data file using NameQty and Names$( array items
[EditSaveNameList1]
    ' update/rewrite data file adding new name
    Open "MyNamesFile.txt" for Output as #afile
    Print #afile, NameQty
    For i = 1 to NameQty
        'aName$ = Names$(i)  ' enable for debugging
        Print #afile, Names$(i)
    Next i
    Close #afile
    NameFileChangedFlag = 1   ' set flag as file changed for Cancel button
    Return

' store Names$( array in aNameList$ string
[EditBuildaNameList1]
    aNameList$ = ""  ' initialize to null
    For i = 1 to NameQty
        aName$ = Names$(i)
        aNameList$ = aNameList$ + Names$(i) + Chr$(13)
    Next i
    Return

' Perform action for 'Edit' button in 'Edit Names' dialog window
' and is called after a listbox item is double clicked on
' edits selected listbox item in the Names$( array and updates data file
[EditChgName1]
    Print #d.lst, "selection? aName$"
    Print #d.lst, "selectionindex? nameIndex"
    Prompt "Edit Name in Name List"+Chr$(13)+"Edit Name:"; aName$ 
    ' if edit was cancelled or no change was made then wait
    If aName$ = "" or aName$ = Names$(nameIndex) Then Wait
    ' update array and file
    Names$(nameIndex) = aName$
    #d.lst, "reload"  ' update name in listbox
    #d.lst, "selectindex ";nameIndex
    Gosub [EditSaveNameList1]  ' update data file with Names$( array
    Wait

' Perform action for 'Delete' button in 'Edit Names' dialog window
' deletes selected listbox item from the Names$( array and updates data file
[EditDeleteName1]
    Print #d.lst, "selection? aName$"
    If aName$ = "" Then Wait
    Confirm "Do you wish to delete '"+aName$+"' from the Name list?";ans$
    If ans$ = "no" Then Wait
    Print #d.lst, "selectionindex? nameIndex"

    ' store names in aNameList$
    Gosub [EditBuildaNameList1]  ' store Names$( array in aNameList$ string
    NameQty = NameQty - 1
    Redim Names$(NameQty+2)
    a = 0
    For i = 1 to NameQty + 1  ' go through original number of names
        If i <> nameIndex Then
            a = a + 1
            'aName$ = Word$(aNameList$, i, Chr$(13))  ' enable for debugging
            Names$(a) = Word$(aNameList$, i, Chr$(13))
        End If
    Next i
    aNameList$ = ""   ' free memory
    #d.lst, "reload"  ' update names in listbox
    If nameIndex > NameQty Then nameIndex = NameQty
    #d.lst, "selectindex ";nameIndex
    Gosub [EditSaveNameList1]       ' update data file with Names$( array
    Wait

' Perform action for '\/' button in 'Edit Names' dialog window
' moves Names$( array item down in the array and saves array in data file
[EditMoveDown1]
    Print #d.lst, "selection? aName$"
    If aName$ = "" Then Wait
    Print #d.lst, "selectionindex? nameIndex"
    If nameIndex = NameQty Then Wait    ' it's already the last item
    Names$(nameIndex) = Names$(nameIndex+1)
    Names$(nameIndex+1) = aName$
    #d.lst, "reload"  ' update names in listbox
    #d.lst, "selectindex ";nameIndex+1  ' show item in it's new location
    Gosub [EditSaveNameList1]       ' update data file with Names$( array
    Wait


' Perform action for '/\' button in 'Edit Names' dialog window
' moves Names$( array item up in the array and saves array in data file
[EditMoveUp1]
    Print #d.lst, "selection? aName$"
    If aName$ = "" Then Wait
    Print #d.lst, "selectionindex? nameIndex"
    If nameIndex = 1 Then Wait     ' it's already the first item
    Names$(nameIndex) = Names$(nameIndex-1)
    Names$(nameIndex-1) = aName$
    #d.lst, "reload"  ' update names in listbox
    #d.lst, "selectindex ";nameIndex-1  ' show item in it's new location
    Gosub [EditSaveNameList]       ' update data file with Names$( array
    Wait

' Perform action for '?' button in 'Edit Names' dialog window
' shows a help Notice window for all buttons on 'Edit Names' dialog window
[EditNamesHelp1]
    n$=Chr$(13)
    msg$ = "Edit Names Help";Chr$(13);_
           "Ok: Closes window, updating Name list with any changes.";_
        n$;"Add: Opens window to Add name to Name list.";_
        n$;"Edit: Opens window to Edit selected name in Name list.";_
        n$;" (Double clicking on name also opens Edit window.)";_
        n$;"Delete: Deletes selected name from Name list.";_
        n$;"Cancel: Closes window with no changes made to Name list.";_
        n$;"/\: Moves selected item up in the Name list.";_
        n$;"\/: Moves selected item down in the Name list."
    Notice msg$
    Wait

' Perform action for 'Ok' button in 'Edit Names' dialog window
' closes 'Edit Names' dialog window, restores Names$( array
' and clears selected combobox item for 'Name' combobox in main window
[EditOk1]
    ' move items forward in array to readd <Edit Names> as first array item
    For i = NameQty to 1 Step -1
        Names$(i+1) = Names$(i)
    Next i
    Names$(1) = "<Edit Names>"
    #main2.names, "reload"
    #main2.names, "selectindex 0"  ' reset combobox to have nothing selected
    Close #d
    NameFileChangedFlag = 0  ' reset flag if needed
    Wait

' Perform action for 'Cancel' button in 'Edit Names' dialog window
' closes Edit Names dialog window without changing original Names$( array and file
[EditCancel1]
    ' check flag:
    ' (if names in Name file were changed - restore original names in file)
    If NameFileChangedFlag = 1 Then Gosub [EditNamesRestoreNames]

    ' reset Names$( array for #main.names Combobox using original saved name list
    For i = 1 to NameQty+2
        aName$ = Word$(orgNameList$, i, Chr$(13))
        If aName$ = Chr$(13) Then aName$ = ""
        Names$(i) = aName$
    Next i

    #main2.names, "selectindex 0"  ' reset combobox to have nothing selected
    Close #d
    'Goto [quit]  ' debugging line; enable to close windows quickly
    NameFileChangedFlag = 0   ' reset flag if needed
    Wait

' called if user selects the cancel button after making changes to list items
[EditNamesRestoreNames1]
    ' rebuild Names$( array from orgNameList$
    NameQty = orgNameQty
    Redim Names$(NameQty+2)

    ' build array for data file; so it can be returned as before
    For i = 2 to NameQty+1
        aName$ = Word$(orgNameList$, i, Chr$(13))
        If aName$ = Chr$(13) Then aName$ = ""
        Names$(i-1) = aName$
    Next i
    ' update data file with file's original data (NameQty & Names$( array)
    Gosub [EditSaveNameList1]
    Return

' Initialize Names$( array for 'Name' Combobox in main window
[initNames1]
    ' load Names from data file
    ' create file if needed to avoid error
    Open "MyNamesFile.txt" for Append as #afile
    Close #afile

    Open "MyNamesFile.txt" for Input as #afile
    If Eof(#afile) Then
        Close #afile
        Names$(1) = "<Edit Names>"
        Return
    End If
    Line Input #afile, NameQty
    Redim Names$(NameQty+2)
    Names$(1) = "<Edit Names>"
    i = 1
    While Eof(#afile)=0
        Line Input #afile, aName$
        If aName$="" Then Exit While
        i = i + 1
        Names$(i) = aName$
    Wend
    Close #afile
    Return

wait


[button3Click]   'Perform action for the button named 'button3'
    'Insert your own code here
     nomainwin

    WindowWidth = 550
    WindowHeight = 410

    combobox #main3.names, Names$(, [NameSelect2], 110, 30, 140, 28

   open "untitled" for window as #main3
    print #main3, "font ms_sans_serif 0 16"

    ' Perform action for #main.names 'Name' combobox
' open a dialog window to allow adding, editing, deleting and moving List items
[NameSelect2]
    Print #main3.names, "selectionindex? index" ' see which combobox item was selected
    ' the first index item in the combobox is '<Edit Names>'
    If index = 1 Then [EditAccessNameList2]    ' open "Edit Names" dialog window
    Wait
    ' in another program possibly do something with the combobox item selected
    msg$ = "Name Combobox Selection Demo";Chr$(13);_
           "You selected '";Names$(index);"'";Chr$(13);Chr$(13);_
           "To see the main demo of this program,";Chr$(13);_
           "Please select <Edit Names> from the Name list." ';Chr$(13);
    Notice msg$
    Wait

' called if '<Edit Names>' is double clicked on in the #main.names 'Names' Combobox
[EditAccessNameList2]
    ' store orginal NameQty for [EditBuildaNameList] routine and Cancel button;
    orgNameQty=NameQty                         ' to restore data file and array
    NameQty=NameQty+2          ' reset NameQty for [EditBuildaNameList] routine
    Gosub [EditBuildaNameList2] ' store Names$( array in aNameList$ string
    NameQty=orgNameQty         ' restore original NameQty
    orgNameList$ = aNameList$  ' store original Names$( array for cancel button
    aNameList$ = ""            ' clear memory

    ' open a dialog_modal window to edit name list:
    WindowWidth = 375
    WindowHeight = 200
    UpperLeftX = 20
    UpperLeftY = 20

    For i = 1 to NameQty + 1   ' fix Names$( array to only show Names
        Names$(i) = Names$(i+1)
    Next i

    Statictext #d, "Name List:", 7, 10, 60, 15
    ' listbox for selecting names to edit/delete/move up/down
    Listbox #d.lst, Names$(, [EditChgName], 7, 28, 240, 122
    ' ok button to accept changes &/or close window
    Button #d, "&Ok", [EditOk], UL, 295, 15, 65, 25
    Button #d, "&Add", [EditAddName], UL, 295, 43, 65, 25
    Button #d, "&Edit", [EditChgName], UL, 295, 71, 65, 25
    Button #d, "&Delete", [EditDeleteName], UL, 295, 99, 65, 25
    Button #d, "?", [EditNamesHelp], UL, 258, 58, 25, 20
    Button #d, "/\", [EditMoveUp], UL, 258, 115, 25, 16
    Button #d, "\/", [EditMoveDown], UL, 258, 134, 25, 16
    ' cancel button to cancel changes & close window
    Button #d, "&Cancel", [EditCancel], UL, 295, 127, 65, 25
    Open "Edit Names" for Dialog_modal as #d
    Print #d, "trapclose [quitd]"
    Wait

' Perform action for 'Add' button in 'Edit Names' dialog window
' adds a listbox item to the Names$( array and updates data file
[EditAddName2]
    Goto [EditAddNameWinOpen2]
    Prompt "Add New Name to Name List"+Chr$(13)+"Add Name:"; aNewName$
    If aNewName$ = "" Then Wait

    ' ? check for duplicate names possibly in Names$( array - ?

    ' store Names$( array in aNameList$ string so array can be redimmed
    Gosub [EditBuildaNameList2]  ' and then restored with new name added
    aNameList$ = aNameList$ + aNewName$  ' add new name to list string
    NameQty = NameQty + 1
    Redim Names$(NameQty + 2)
    For i = 1 to NameQty
        'aName$ = Word$(aNameList$, i, Chr$(13))  ' enable for debugging
        Names$(i) = Word$(aNameList$, i, Chr$(13))
    Next i
    aNameList$ = ""   ' free memory
    Print #d.lst, "reload"    ' update listbox with added name
    Print #d.lst, "selectindex ";NameQty
    Gosub [EditSaveNameList2]  ' update data file with Names$( array
    Wait

[EditAddNameWinOpen23]
    WindowWidth = 350
    WindowHeight = 240
    UpperLeftX = 20
    UpperLeftY = 20
    Statictext #e, "Employee Name:", 10,17,80,15
    Textbox #e.tbx, 10,37,240,25
    Button #e, "&Ok",[EditAddNameWinOk],UL 10,75,65,25
    Button #e, "&Cancel",[EditAddNameWinCancel],UL 80,75,65,25
    Button #e, "&Advanced...",[EditAddNameWinAdvanced],UL 150,75,98,25
    Open "Add New Name to Name List" for dialog_modal as #e
    Print #e, "trapclose [EditAddNameWinCancel]"
    Wait

[EditAddNameWinOpen24]
    WindowWidth = 270
    WindowHeight = 140
    UpperLeftX = 20
    UpperLeftY = 20
    Statictext #e, "Add Name:", 10,17,80,15
    Textbox #e.tbx, 10,37,240,25
    Button #e, "&Ok",[EditAddNameWinOk],UL 10,75,65,25
    Button #e, "&Cancel",[EditAddNameWinCancel],UL 80,75,65,25
    Button #e, "&Advanced...",[EditAddNameWinAdvanced],UL 150,75,98,25
    Open "Add New Name to Name List" for dialog_modal as #e
    Print

[EditAddNameWinOk2]
    Print #e.tbx, "!Contents? aNewName$"
    Close #e
    If aNewName$ = "" Then Wait
    ' ? check for duplicate names possibly in Names$( array - ?

    ' store Names$( array in aNameList$ string so array can be redimmed
    Gosub [EditBuildaNameList2]  ' and then restored with new name added
    aNameList$ = aNameList$ + aNewName$  ' add new name to list string
    NameQty = NameQty + 1
    Redim Names$(NameQty + 2)
    For i = 1 to NameQty
        'aName$ = Word$(aNameList$, i, Chr$(13))  ' enable for debugging
        Names$(i) = Word$(aNameList$, i, Chr$(13))
    Next i
    aNameList$ = ""   ' free memory
    Print #d.lst, "reload"    ' update listbox with added name
    Print #d.lst, "selectindex ";NameQty
    Gosub [EditSaveNameList2]  ' update data file with Names$( array
    Wait

[EditAddNameWinCancel2]
    ' user cancelled so don't change name list, etc.
    Close #e
    Wait

[EditAddNameWinAdvanced2]
    Notice "Sorry, not yet available."
    ' open another dialog_modal window to enable:
    ' get/change username/password; initialize files
    Wait


' called by a few routines to save changes in the Name data file;
' updates Names data file using NameQty and Names$( array items
[EditSaveNameList2]
    ' update/rewrite data file adding new name
    Open "MyNamesFile.txt" for Output as #afile
    Print #afile, NameQty
    For i = 1 to NameQty
        'aName$ = Names$(i)  ' enable for debugging
        Print #afile, Names$(i)
    Next i
    Close #afile
    NameFileChangedFlag = 1   ' set flag as file changed for Cancel button
    Return

' store Names$( array in aNameList$ string
[EditBuildaNameList2]
    aNameList$ = ""  ' initialize to null
    For i = 1 to NameQty
        aName$ = Names$(i)
        aNameList$ = aNameList$ + Names$(i) + Chr$(13)
    Next i
    Return

' Perform action for 'Edit' button in 'Edit Names' dialog window
' and is called after a listbox item is double clicked on
' edits selected listbox item in the Names$( array and updates data file
[EditChgName2]
    Print #d.lst, "selection? aName$"
    Print #d.lst, "selectionindex? nameIndex"
    Prompt "Edit Name in Name List"+Chr$(13)+"Edit Name:"; aName$ 
    ' if edit was cancelled or no change was made then wait
    If aName$ = "" or aName$ = Names$(nameIndex) Then Wait
    ' update array and file
    Names$(nameIndex) = aName$
    #d.lst, "reload"  ' update name in listbox
    #d.lst, "selectindex ";nameIndex
    Gosub [EditSaveNameList2]  ' update data file with Names$( array
    Wait

' Perform action for 'Delete' button in 'Edit Names' dialog window
' deletes selected listbox item from the Names$( array and updates data file
[EditDeleteName2]
    Print #d.lst, "selection? aName$"
    If aName$ = "" Then Wait
    Confirm "Do you wish to delete '"+aName$+"' from the Name list?";ans$
    If ans$ = "no" Then Wait
    Print #d.lst, "selectionindex? nameIndex"

    ' store names in aNameList$
    Gosub [EditBuildaNameList2]  ' store Names$( array in aNameList$ string
    NameQty = NameQty - 1
    Redim Names$(NameQty+2)
    a = 0
    For i = 1 to NameQty + 1  ' go through original number of names
        If i <> nameIndex Then
            a = a + 1
            'aName$ = Word$(aNameList$, i, Chr$(13))  ' enable for debugging
            Names$(a) = Word$(aNameList$, i, Chr$(13))
        End If
    Next i
    aNameList$ = ""   ' free memory
    #d.lst, "reload"  ' update names in listbox
    If nameIndex > NameQty Then nameIndex = NameQty
    #d.lst, "selectindex ";nameIndex
    Gosub [EditSaveNameList2]       ' update data file with Names$( array
    Wait

' Perform action for '\/' button in 'Edit Names' dialog window
' moves Names$( array item down in the array and saves array in data file
[EditMoveDown2]
    Print #d.lst, "selection? aName$"
    If aName$ = "" Then Wait
    Print #d.lst, "selectionindex? nameIndex"
    If nameIndex = NameQty Then Wait    ' it's already the last item
    Names$(nameIndex) = Names$(nameIndex+1)
    Names$(nameIndex+1) = aName$
    #d.lst, "reload"  ' update names in listbox
    #d.lst, "selectindex ";nameIndex+1  ' show item in it's new location
    Gosub [EditSaveNameList2]       ' update data file with Names$( array
    Wait


' Perform action for '/\' button in 'Edit Names' dialog window
' moves Names$( array item up in the array and saves array in data file
[EditMoveUp2]
    Print #d.lst, "selection? aName$"
    If aName$ = "" Then Wait
    Print #d.lst, "selectionindex? nameIndex"
    If nameIndex = 1 Then Wait     ' it's already the first item
    Names$(nameIndex) = Names$(nameIndex-1)
    Names$(nameIndex-1) = aName$
    #d.lst, "reload"  ' update names in listbox
    #d.lst, "selectindex ";nameIndex-1  ' show item in it's new location
    Gosub [EditSaveNameList2]       ' update data file with Names$( array
    Wait

' Perform action for '?' button in 'Edit Names' dialog window
' shows a help Notice window for all buttons on 'Edit Names' dialog window
[EditNamesHelp2]
    n$=Chr$(13)
    msg$ = "Edit Names Help";Chr$(13);_
           "Ok: Closes window, updating Name list with any changes.";_
        n$;"Add: Opens window to Add name to Name list.";_
        n$;"Edit: Opens window to Edit selected name in Name list.";_
        n$;" (Double clicking on name also opens Edit window.)";_
        n$;"Delete: Deletes selected name from Name list.";_
        n$;"Cancel: Closes window with no changes made to Name list.";_
        n$;"/\: Moves selected item up in the Name list.";_
        n$;"\/: Moves selected item down in the Name list."
    Notice msg$
    Wait

' Perform action for 'Ok' button in 'Edit Names' dialog window
' closes 'Edit Names' dialog window, restores Names$( array
' and clears selected combobox item for 'Name' combobox in main window
[EditOk2]
    ' move items forward in array to readd <Edit Names> as first array item
    For i = NameQty to 1 Step -1
        Names$(i+1) = Names$(i)
    Next i
    Names$(1) = "<Edit Names>"
    #main3.names, "reload"
    #main3.names, "selectindex 0"  ' reset combobox to have nothing selected
    Close #d
    NameFileChangedFlag = 0  ' reset flag if needed
    Wait

' Perform action for 'Cancel' button in 'Edit Names' dialog window
' closes Edit Names dialog window without changing original Names$( array and file
[EditCancel2]
    ' check flag:
    ' (if names in Name file were changed - restore original names in file)
    If NameFileChangedFlag = 1 Then Gosub [EditNamesRestoreNames2]

    ' reset Names$( array for #main.names Combobox using original saved name list
    For i = 1 to NameQty+2
        aName$ = Word$(orgNameList$, i, Chr$(13))
        If aName$ = Chr$(13) Then aName$ = ""
        Names$(i) = aName$
    Next i

    #main3.names, "selectindex 0"  ' reset combobox to have nothing selected
    Close #d
    'Goto [quit]  ' debugging line; enable to close windows quickly
    NameFileChangedFlag = 0   ' reset flag if needed
    Wait

' called if user selects the cancel button after making changes to list items
[EditNamesRestoreNames2]
    ' rebuild Names$( array from orgNameList$
    NameQty = orgNameQty
    Redim Names$(NameQty+2)

    ' build array for data file; so it can be returned as before
    For i = 2 to NameQty+1
        aName$ = Word$(orgNameList$, i, Chr$(13))
        If aName$ = Chr$(13) Then aName$ = ""
        Names$(i-1) = aName$
    Next i
    ' update data file with file's original data (NameQty & Names$( array)
    Gosub [EditSaveNameList2]
    Return

' Initialize Names$( array for 'Name' Combobox in main window
[initNames2]
    ' load Names from data file
    ' create file if needed to avoid error
    Open "MyNamesFile.txt" for Append as #afile
    Close #afile

    Open "MyNamesFile.txt" for Input as #afile
    If Eof(#afile) Then
        Close #afile
        Names$(1) = "<Edit Names>"
        Return
    End If
    Line Input #afile, NameQty
    Redim Names$(NameQty+2)
    Names$(1) = "<Edit Names>"
    i = 1
    While Eof(#afile)=0
        Line Input #afile, aName$
        If aName$="" Then Exit While
        i = i + 1
        Names$(i) = aName$
    Wend
    Close #afile
    Return

wait

