Break On ; This is where we will save our data. If this file ; doesn't exist on startup, we will just build some ; random data on the fly [see: Load_Click()] $PROFILE = ".\PHONE.INI" ; ; MAIN FORM ; $Form = CreateObject("Kixtart.Form") $Form.ClientWidth = 600 $Form.ClientHeight = 400 $Form.FontName = Verdana $Form.FontSize = 10 $Form.Text = "PhoneBook" ;$Form.BackColor = SkyBlue ; <-- new feature - colornames ! $Form.PrintXY(10,15,"Find:") $txtFind = $Form.TextBox $txtFind.Bounds = 50,10,100,25 ; <--- new feature - moving the control in one move $Form.PrintXY($txtFind.Right+10,15,"In:") $cboFind = $Form.ComboBox $cboFind.Bounds = 190,10,115,200 $cboFind.Style = 1 $btnFind = $Form.Button $btnFind.Text = "Find..." $btnFind.Bounds = 320,10,75,25 $btnFind.OnClick = "btnFind_Click()" $btnFind.ToolTip = "Find matching items" ; ; Construct ListView object ... ; $List = $Form.ListView() $List.Left = 10 $List.Top = 50 $List.Width = 0.80 * $Form.ClientWidth $List.Bottom = $Form.ClientHeight - 20 $List.OnDoubleClick = "Edit_Click()" ; ; Set ListView Options... ; $List.Sorted = 1 ; Yes, sort the first column $List.MultiSelect = True ; Allow more than one selection $List.GridLines = True ; Show gridlines in report view $List.View = 3 ; Report view $List.FullRowSelect = True ; Allow user to select the entire row ; ; Add three columns to our listview. The format of the Add ; method of the Columns collection is: ; ; $obj = $List.Columns.Add(heading,width,alignment) ; $= $List.Columns.Add("Name") $= $List.Columns.Add("Address") $= $List.Columns.Add("Phone") ; ; Size the columns evenly within our view. If we have ; three columns, each will be 1/3 the total width... ; At the same time, we will load our Find Column ; ComboBox with the appropriate headings. ; For Each $Column In $List.Columns $Column.Width = $List.ClientWidth / $List.Columns.Count $cboFind.AddItem($Column.Text) Next ; ; Set the find string to be the first item in the ComboBox ; $cboFind.ListIndex = 0 ; ; Build our command buttons ... ; $Add = $Form.Button $Add.Text = "New" $Add.Top = 10 $Add.Left = $List.Right + 20 $Add.Size = 75,25 $Add.OnClick = "Add_Click()" $Add.ToolTip = "Add new item" $Edit = $Form.Button $Edit.Text = "Edit" $Edit.Top = $Add.Bottom + 10 $Edit.Left = $Add.Left $Edit.Size = 75,25 $Edit.OnClick = "Edit_Click()" $Edit.ToolTip = "Edit currently selected item" $Delete = $Form.Button $Delete.Text = "Delete" $Delete.Top = $Edit.Bottom + 10 $Delete.Left = $Add.Left $Delete.Size = 75,25 $Delete.OnClick = "Delete_Click()" $Delete.ToolTip = "Delete currently selected items" $Load = $Form.Button $Load.Text = "Load" $Load.Top = $Delete.Bottom + 10 $Load.Left = $Add.Left $Load.Size = 75,25 $Load.OnClick = "Load_Click()" $Load.ToolTip = "Load list from file" $Save = $Form.Button $Save.Text = "Save" $Save.Top = $Load.Bottom + 10 $Save.Left = $Add.Left $Save.Size = 75,25 $Save.OnClick = "Save_Click()" $Save.ToolTip = "Save list to file" $Report = $Form.Button $Report.Text = "Report" $Report.Top = $Save.Bottom + 10 $Report.Left = $Add.Left $Report.Size = 75,25 $Report.OnClick = "Report_Click()" $Report.ToolTip = "Report on selected items" $Exit = $Form.Button $Exit.Text = "Exit" $Exit.Top = $Report.Bottom + 10 $Exit.Left = $Add.Left $Exit.Size = 75,25 $Exit.OnClick = "Quit()" ; ; EDIT FORM - Used to add and edit our list items ... ; $frmEdit = CreateObject("Kixtart.Form") $frmEdit.ClientSize = 300,150 $frmEdit.FontName = $Form.FontName $frmEdit.FontSize = $Form.FontSize $lblName = $frmEdit.Label $lblname.Text = "Name:" $lblName.Location = 10,15 $lblName.Size = 75,15 $txtName = $frmEdit.TextBox $txtName.Location = $lblName.Right + 5,$lblName.Top - 3 $txtName.Size = 200,20 $lblAddress = $frmEdit.Label $lblAddress.Text = "Address:" $lblAddress.Location = 10,$txtName.Bottom+15 $lblAddress.Size = 75,15 $txtAddress = $frmEdit.TextBox $txtAddress.Location = $lblAddress.Right + 5,$lblAddress.Top - 3 $txtAddress.Size = 200,20 $lblPhone = $frmEdit.Label $lblPhone.Text = "Phone:" $lblPhone.Location = 10,$txtAddress.Bottom+15 $lblPhone.Size = 75,15 $txtPhone = $frmEdit.TextBox $txtPhone.Location = $lblPhone.Right + 5,$lblPhone.Top - 3 $txtPhone.Size = 200,20 $btnOk = $frmEdit.Button $btnOk.Text = "OK" $btnOk.Size = 75,25 $btnOk.Top = $lblPhone.Bottom + 20 $btnOk.Left = 125 $btnOk.OnClick = "$$frmEdit.Tag = 1" $btnCancel = $frmEdit.Button $btnCancel.Text = "Cancel" $btnCancel.Size = 75,25 $btnCancel.Top = $btnOk.Top $btnCancel.Left = $BtnOk.Right + 15 $btnCancel.OnClick = "$$frmEdit.Tag = 2" ; ; REPORT FORM - Used to display a report of all list items ; $frmReport = CreateObject("Kixtart.Form") $frmReport.Width = 0.66 * $Form.Width $frmReport.Height = $Form.Height $frmReport.FontName = Verdana $frmReport.Text = "Report" $frmReport.FontName = "Courier New" $frmReport.FontSize = 10 $txtReport = $frmReport.TextBox $txtReport.MultiLine = True $txtReport.Text = "" $txtReport.Location = 10,10 $txtReport.Width = $frmReport.ClientWidth - 20 $txtReport.Height = $frmReport.ClientHeight - 20 $txtReport.ScrollBars = 2 ;///////////////////////////////////////// ; Start the application ... ;///////////////////////////////////////// $Form.Center $Form.Show Load_Click() While $Form.Visible $= Execute($Form.DoEvents) Loop Exit 1 Function Add_Click() ; Clear and enable the form fields ... $txtName.Clear $txtAddress.Clear $txtPhone.Clear $txtName.Enabled = 1 $txtAddress.Enabled = 1 $txtPhone.Enabled = 1 ; Setup the form ... $frmEdit.Center $frmEdit.Text = "New" $frmEdit.Show $frmEdit.Tag = 0 ; Run the form ... While $frmEdit.Visible And $frmEdit.Tag = 0 $=Execute($frmEdit.DoEvents) Loop $frmEdit.Hide ; If OK button clicked, add new item ... If $frmEdit.Tag = 1 ; OK $Item = $List.Items.Add($txtName.Text) $Item.SubItems(1).Text = $txtAddress.Text $Item.SubItems(2).Text = $txtPhone.Text EndIf $List.SetFocus EndFunction Function Edit_Click() ; ; Load fields from FocusedItem in ListView ... ; $List.SetFocus If Not $List.FocusedItem.Selected $= $Form.MsgBox("Please select an item","Edit") Return EndIf If $List.SelectedItems.Count > 1 $= $Form.MsgBox("Please select one item","Edit") Return EndIf $txtName.Text = $List.FocusedItem.SubItems(0).Text $txtAddress.Text = $List.FocusedItem.SubItems(1).Text $txtPhone.Text = $List.FocusedItem.SubItems(2).Text $txtName.Enabled = 1 $txtAddress.Enabled = 1 $txtPhone.Enabled = 1 ; Setup form ... $frmEdit.Center $frmEdit.Text = "Edit" $frmEdit.Show $frmEdit.Tag = 0 ; Run form ... While $frmEdit.Visible And $frmEdit.Tag = 0 $=Execute($FrmEdit.DoEvents) Loop $frmEdit.Hide ; If OK click put modified data back into FocusedItem ... If $frmEdit.Tag = 1 ; OK $Item = $List.FocusedItem $Item.SubItems(0).Text = $txtName.Text $Item.SubItems(1).Text = $txtAddress.Text $Item.SubItems(2).Text = $txtPhone.Text EndIf EndFunction Function btnFind_Click() $Text = $txtFind.Text If Not $Text $= $Form.MsgBox("Please specify a string to find.","Find") $txtFind.SetFocus Return EndIf ; ; Clear any selected items ... ; $Form.MousePointer = 11 $Form.Enabled = 0 For Each $Item In $List.SelectedItems $Item.Selected = 0 Next $Index = $cboFind.ListIndex For Each $Item In $List.Items If InStr($Item.SubItems($Index).Text,$Text) $Item.Selected = 1 EndIf Next $Form.MousePointer = 0 $Form.Enabled = 1 $List.SetFocus EndFunction Function Delete_Click() ; How many selected items ? $Count = $List.SelectedItems.Count ; Check to see if any items selected ... If $Count = 0 $= $Form.MsgBox("Please select an item","Delete") Return Else ; If we have items, ask to remove them ... If $Form.MsgBox("Delete $Count item(s) ?","Delete",4) <> 6 Return Endif EndIf ; ; BeginUpdate - suspends drawing of window until EndUpdate called ; $Form.MousePointer = 11 $Form.Enabled = 0 $Form.BeginUpdate $List.SelectedItems.Clear For Each $Column In $List.Columns $Column.Width = -1 $Column.Width = -2 Next ; ; EndUpdate - Resume drawing of graphics ; $Form.EndUpdate $Form.MousePointer = 0 $Form.Enabled = 1 $List.SetFocus EndFunction Function Save_Click() ; If profile exists, delete it ... If Exist($PROFILE) Del $PROFILE EndIf ; For each item in the view, write out details ... For Each $Item In $List.Items $= WriteProfileString($PROFILE,$Item.Text,"Address",$Item.SubItems(1).Text+" ") $= WriteProfileString($PROFILE,$Item.Text,"Phone",$Item.SubItems(2).Text+" ") Next $List.SetFocus EndFunction Function Load_Click() ; Remove all items from list ... $Form.MousePointer = 11 $Form.Enabled = 0 $Form.BeginUpdate $List.Items.Clear ; ; If profile exists, load it... ; If Exist($PROFILE) For Each $Name In Split(ReadProfileString($PROFILE,"",""),CHR(10)) If $Name $Item = $List.Items.Add($Name) $Item.SubItems(1).Text = ReadProfileString($PROFILE,$Name,"Address") $Item.SubItems(2).Text = ReadProfileString($PROFILE,$Name,"Phone") EndIf Next Else ; ; Build a database of random data ... ; For $i = 0 to 1000 $Item = $List.Items.Add("John Doe #$i") $Item.SubItems(1).Text = ""+(RND(98)+1)+" Maple Drive" $Item.SubItems(2).Text = ""+(RND(899)+100)+"-"+(RND(899)+100)+"-"+(RND(8999)+1000) Next EndIf For Each $Column In $List.Columns $Column.Width = -1 $Column.Width = -2 Next $Form.EndUpdate $Form.MousePointer = 0 $Form.Enabled = 1 $List.SetFocus EndFunction Function Report_Click() $txtReport.Text = "" $String = ""+$List.SelectedItems.Count+" item(s) selected."+@CRLF+@CRLF $Form.MousePointer = 11 $Form.Enabled = 0 For Each $Item In $List.SelectedItems $String = $String + $Item.Text + @CRLF + @CRLF $String = $String + " Address: " + $Item.SubItems(1).Text + @CRLF $String = $String + " Phone: " + $Item.SubItems(2).Text + @CRLF + @CRLF Next $Form.MousePointer = 0 $Form.Enabled = 1 $txtReport.Text = $String $frmReport.Center $frmReport.Top = $Form.Top + 30 $frmReport.Show While $frmReport.Visible $=Execute($frmReport.DoEvents) Loop $frmReport.Hide $List.SetFocus EndFunction