home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / VISUAL_B / CODIGO_1 / FOX_ADR / ADR_FORM.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1993-08-26  |  19.7 KB  |  688 lines

  1. VERSION 2.00
  2. Begin Form adr_form 
  3.    Caption         =   "Address Book"
  4.    ClientHeight    =   6240
  5.    ClientLeft      =   2145
  6.    ClientTop       =   2250
  7.    ClientWidth     =   8880
  8.    Height          =   6645
  9.    Icon            =   ADR_FORM.FRX:0000
  10.    Left            =   2085
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   6240
  13.    ScaleWidth      =   8880
  14.    Top             =   1905
  15.    Width           =   9000
  16.    Begin CommandButton last_but 
  17.       Caption         =   "Las&t"
  18.       Height          =   495
  19.       Left            =   2580
  20.       TabIndex        =   33
  21.       Top             =   5640
  22.       Width           =   675
  23.    End
  24.    Begin CommandButton first_but 
  25.       Caption         =   "F&irst"
  26.       Height          =   495
  27.       Left            =   240
  28.       TabIndex        =   32
  29.       Top             =   5640
  30.       Width           =   675
  31.    End
  32.    Begin CommandButton list_but 
  33.       Caption         =   "&List"
  34.       Height          =   495
  35.       Left            =   4140
  36.       TabIndex        =   28
  37.       Top             =   5640
  38.       Width           =   675
  39.    End
  40.    Begin CheckBox Action_needed 
  41.       Caption         =   "&Action needed"
  42.       Height          =   255
  43.       Left            =   1500
  44.       TabIndex        =   27
  45.       Top             =   780
  46.       Width           =   1635
  47.    End
  48.    Begin CheckBox action_check 
  49.       Caption         =   "S&how outstanding action only"
  50.       Height          =   375
  51.       Left            =   240
  52.       TabIndex        =   26
  53.       Top             =   5160
  54.       Width           =   2835
  55.    End
  56.    Begin OptionButton order_option 
  57.       Caption         =   "Post &code"
  58.       Height          =   375
  59.       Index           =   0
  60.       Left            =   180
  61.       TabIndex        =   24
  62.       Top             =   4620
  63.       Width           =   1215
  64.    End
  65.    Begin OptionButton order_option 
  66.       Caption         =   "S&urname"
  67.       Height          =   375
  68.       Index           =   1
  69.       Left            =   180
  70.       TabIndex        =   23
  71.       Top             =   4260
  72.       Width           =   1215
  73.    End
  74.    Begin CommandButton pack_but 
  75.       Caption         =   "Pac&k"
  76.       Height          =   495
  77.       Left            =   6480
  78.       TabIndex        =   21
  79.       Top             =   5640
  80.       Width           =   675
  81.    End
  82.    Begin CommandButton del_but 
  83.       Caption         =   "&Delete"
  84.       Height          =   495
  85.       Left            =   7260
  86.       TabIndex        =   20
  87.       Top             =   5640
  88.       Width           =   675
  89.    End
  90.    Begin CommandButton new_but 
  91.       Caption         =   "Ne&w"
  92.       Height          =   495
  93.       Left            =   4920
  94.       TabIndex        =   19
  95.       Top             =   5640
  96.       Width           =   675
  97.    End
  98.    Begin CommandButton save_but 
  99.       Caption         =   "&Save"
  100.       Height          =   495
  101.       Left            =   5700
  102.       TabIndex        =   18
  103.       Top             =   5640
  104.       Width           =   675
  105.    End
  106.    Begin CommandButton quit_but 
  107.       Caption         =   "&Quit"
  108.       Height          =   495
  109.       Left            =   8040
  110.       TabIndex        =   14
  111.       Top             =   5640
  112.       Width           =   675
  113.    End
  114.    Begin CommandButton prev_but 
  115.       Caption         =   "&Prev"
  116.       Height          =   495
  117.       Left            =   1800
  118.       TabIndex        =   13
  119.       Top             =   5640
  120.       Width           =   675
  121.    End
  122.    Begin TextBox notes_box 
  123.       FontBold        =   -1  'True
  124.       FontItalic      =   0   'False
  125.       FontName        =   "Arial"
  126.       FontSize        =   9.75
  127.       FontStrikethru  =   0   'False
  128.       FontUnderline   =   0   'False
  129.       Height          =   2715
  130.       Left            =   120
  131.       MultiLine       =   -1  'True
  132.       ScrollBars      =   2  'Vertical
  133.       TabIndex        =   10
  134.       Text            =   "Text1"
  135.       Top             =   1080
  136.       Width           =   3015
  137.    End
  138.    Begin TextBox adr5_box 
  139.       FontBold        =   -1  'True
  140.       FontItalic      =   0   'False
  141.       FontName        =   "Arial"
  142.       FontSize        =   12
  143.       FontStrikethru  =   0   'False
  144.       FontUnderline   =   0   'False
  145.       Height          =   420
  146.       Left            =   4740
  147.       TabIndex        =   7
  148.       Text            =   "Text1"
  149.       Top             =   3780
  150.       Width           =   3975
  151.    End
  152.    Begin TextBox adr4_box 
  153.       FontBold        =   -1  'True
  154.       FontItalic      =   0   'False
  155.       FontName        =   "Arial"
  156.       FontSize        =   12
  157.       FontStrikethru  =   0   'False
  158.       FontUnderline   =   0   'False
  159.       Height          =   420
  160.       Left            =   4740
  161.       TabIndex        =   6
  162.       Text            =   "Text1"
  163.       Top             =   3300
  164.       Width           =   3975
  165.    End
  166.    Begin TextBox fax_box 
  167.       FontBold        =   -1  'True
  168.       FontItalic      =   0   'False
  169.       FontName        =   "Arial"
  170.       FontSize        =   12
  171.       FontStrikethru  =   0   'False
  172.       FontUnderline   =   0   'False
  173.       Height          =   420
  174.       Left            =   4740
  175.       TabIndex        =   9
  176.       Text            =   "Text1"
  177.       Top             =   4740
  178.       Width           =   4035
  179.    End
  180.    Begin TextBox tel_box 
  181.       FontBold        =   -1  'True
  182.       FontItalic      =   0   'False
  183.       FontName        =   "Arial"
  184.       FontSize        =   12
  185.       FontStrikethru  =   0   'False
  186.       FontUnderline   =   0   'False
  187.       Height          =   420
  188.       Left            =   4740
  189.       TabIndex        =   8
  190.       Text            =   "Text5"
  191.       Top             =   4260
  192.       Width           =   4035
  193.    End
  194.    Begin TextBox adr3_box 
  195.       FontBold        =   -1  'True
  196.       FontItalic      =   0   'False
  197.       FontName        =   "Arial"
  198.       FontSize        =   12
  199.       FontStrikethru  =   0   'False
  200.       FontUnderline   =   0   'False
  201.       Height          =   420
  202.       Left            =   4740
  203.       TabIndex        =   5
  204.       Text            =   "Text4"
  205.       Top             =   2820
  206.       Width           =   3975
  207.    End
  208.    Begin TextBox adr2_box 
  209.       FontBold        =   -1  'True
  210.       FontItalic      =   0   'False
  211.       FontName        =   "Arial"
  212.       FontSize        =   12
  213.       FontStrikethru  =   0   'False
  214.       FontUnderline   =   0   'False
  215.       Height          =   420
  216.       Left            =   4740
  217.       TabIndex        =   4
  218.       Text            =   "Text3"
  219.       Top             =   2340
  220.       Width           =   3975
  221.    End
  222.    Begin TextBox adr1_box 
  223.       FontBold        =   -1  'True
  224.       FontItalic      =   0   'False
  225.       FontName        =   "Arial"
  226.       FontSize        =   12
  227.       FontStrikethru  =   0   'False
  228.       FontUnderline   =   0   'False
  229.       Height          =   420
  230.       Left            =   4740
  231.       TabIndex        =   3
  232.       Text            =   "Text2"
  233.       Top             =   1860
  234.       Width           =   3975
  235.    End
  236.    Begin TextBox surname_box 
  237.       FontBold        =   -1  'True
  238.       FontItalic      =   0   'False
  239.       FontName        =   "Arial"
  240.       FontSize        =   12
  241.       FontStrikethru  =   0   'False
  242.       FontUnderline   =   0   'False
  243.       Height          =   420
  244.       Left            =   4740
  245.       TabIndex        =   2
  246.       Text            =   "Text1"
  247.       Top             =   1380
  248.       Width           =   3975
  249.    End
  250.    Begin CommandButton find_but 
  251.       Caption         =   "&Find"
  252.       Height          =   495
  253.       Left            =   3360
  254.       TabIndex        =   12
  255.       Top             =   5640
  256.       Width           =   675
  257.    End
  258.    Begin CommandButton next_but 
  259.       Caption         =   "&Next"
  260.       Height          =   495
  261.       Left            =   1020
  262.       TabIndex        =   11
  263.       Top             =   5640
  264.       Width           =   675
  265.    End
  266.    Begin TextBox forename_box 
  267.       FontBold        =   -1  'True
  268.       FontItalic      =   0   'False
  269.       FontName        =   "Arial"
  270.       FontSize        =   12
  271.       FontStrikethru  =   0   'False
  272.       FontUnderline   =   0   'False
  273.       Height          =   420
  274.       Left            =   4740
  275.       TabIndex        =   1
  276.       Text            =   "Text1"
  277.       Top             =   900
  278.       Width           =   3975
  279.    End
  280.    Begin Label Label9 
  281.       Caption         =   "Address:"
  282.       FontBold        =   -1  'True
  283.       FontItalic      =   -1  'True
  284.       FontName        =   "Arial"
  285.       FontSize        =   12
  286.       FontStrikethru  =   0   'False
  287.       FontUnderline   =   0   'False
  288.       Height          =   375
  289.       Left            =   3300
  290.       TabIndex        =   31
  291.       Top             =   1920
  292.       Width           =   1335
  293.    End
  294.    Begin Label Label8 
  295.       Caption         =   "Forename:"
  296.       FontBold        =   -1  'True
  297.       FontItalic      =   -1  'True
  298.       FontName        =   "Arial"
  299.       FontSize        =   12
  300.       FontStrikethru  =   0   'False
  301.       FontUnderline   =   0   'False
  302.       Height          =   375
  303.       Left            =   3300
  304.       TabIndex        =   30
  305.       Top             =   960
  306.       Width           =   1275
  307.    End
  308.    Begin Label Label7 
  309.       Caption         =   "Surname:"
  310.       FontBold        =   -1  'True
  311.       FontItalic      =   -1  'True
  312.       FontName        =   "Arial"
  313.       FontSize        =   12
  314.       FontStrikethru  =   0   'False
  315.       FontUnderline   =   0   'False
  316.       Height          =   375
  317.       Left            =   3300
  318.       TabIndex        =   29
  319.       Top             =   1440
  320.       Width           =   1335
  321.    End
  322.    Begin Label Label6 
  323.       Caption         =   "Sort by:"
  324.       FontBold        =   -1  'True
  325.       FontItalic      =   -1  'True
  326.       FontName        =   "Arial"
  327.       FontSize        =   12
  328.       FontStrikethru  =   0   'False
  329.       FontUnderline   =   0   'False
  330.       Height          =   375
  331.       Left            =   120
  332.       TabIndex        =   25
  333.       Top             =   3960
  334.       Width           =   1275
  335.    End
  336.    Begin Label Label5 
  337.       Caption         =   "Postcode:"
  338.       FontBold        =   -1  'True
  339.       FontItalic      =   -1  'True
  340.       FontName        =   "Arial"
  341.       FontSize        =   12
  342.       FontStrikethru  =   0   'False
  343.       FontUnderline   =   0   'False
  344.       Height          =   375
  345.       Left            =   3300
  346.       TabIndex        =   22
  347.       Top             =   3780
  348.       Width           =   1395
  349.    End
  350.    Begin Label Label4 
  351.       Caption         =   "Notes:"
  352.       FontBold        =   -1  'True
  353.       FontItalic      =   -1  'True
  354.       FontName        =   "Arial"
  355.       FontSize        =   12
  356.       FontStrikethru  =   0   'False
  357.       FontUnderline   =   0   'False
  358.       Height          =   375
  359.       Left            =   120
  360.       TabIndex        =   17
  361.       Top             =   720
  362.       Width           =   1215
  363.    End
  364.    Begin Label Label3 
  365.       Caption         =   "Fax:"
  366.       FontBold        =   -1  'True
  367.       FontItalic      =   -1  'True
  368.       FontName        =   "Arial"
  369.       FontSize        =   12
  370.       FontStrikethru  =   0   'False
  371.       FontUnderline   =   0   'False
  372.       Height          =   255
  373.       Left            =   3300
  374.       TabIndex        =   16
  375.       Top             =   4800
  376.       Width           =   1335
  377.    End
  378.    Begin Label Label2 
  379.       Caption         =   "Telephone:"
  380.       FontBold        =   -1  'True
  381.       FontItalic      =   -1  'True
  382.       FontName        =   "Arial"
  383.       FontSize        =   12
  384.       FontStrikethru  =   0   'False
  385.       FontUnderline   =   0   'False
  386.       Height          =   255
  387.       Left            =   3300
  388.       TabIndex        =   15
  389.       Top             =   4320
  390.       Width           =   1335
  391.    End
  392.    Begin Label Label1 
  393.       Alignment       =   2  'Center
  394.       Caption         =   "Address Book"
  395.       FontBold        =   -1  'True
  396.       FontItalic      =   0   'False
  397.       FontName        =   "Arial"
  398.       FontSize        =   24
  399.       FontStrikethru  =   0   'False
  400.       FontUnderline   =   0   'False
  401.       Height          =   495
  402.       Left            =   0
  403.       TabIndex        =   0
  404.       Top             =   120
  405.       Width           =   8895
  406.    End
  407. Sub action_check_click ()
  408. Rem this sets filter to only addresses
  409. Rem with action outstanding
  410. Rem check for changed details before moving
  411. Rem to another record
  412. ' If you set a check box value in code, it triggers the click
  413. ' event. This is a good way to get infinite loops, and I don't
  414. ' like this effect! Therefore I've set a flag so that
  415. ' I can ignore unwanted click events.
  416. If ignore_click = 1 Then
  417. ignore_click = 0
  418. Exit Sub
  419. End If
  420. curr_rec = adr_ds!recnum
  421. If chk_change() = "Cancel" Then
  422. ' reset check box without triggering code
  423. ignore_click = 1
  424. If action_check.Value = 1 Then
  425. action_check.Value = 0
  426. action_check.Value = 1
  427. End If
  428. Exit Sub
  429. End If
  430. If action_check.Value Then
  431. Rem set filter
  432. filt_adr
  433.     If Not action_check.Value Then
  434.     ' it was changed back by filt_adr because no records exist
  435.     ' with the action field true
  436.     ' so restore current record
  437.     criteria = "recnum = " + Str(curr_rec)
  438.     adr_ds.FindFirst criteria
  439.     End If
  440. refresh_sql
  441. criteria = "recnum = " + Str(curr_rec)
  442. adr_ds.FindFirst criteria
  443. End If
  444. upd_fields
  445. End Sub
  446. Sub Action_needed_Click ()
  447. If newflag Then
  448. ' if a new record is current, we cannot
  449. ' update the dynaset yet
  450. Exit Sub
  451. End If
  452. adr_ds.Edit
  453.     If action_needed.Value Then
  454.     adr_ds("ACTION") = True
  455.     Else
  456.     adr_ds("ACTION") = False
  457.     End If
  458. adr_ds.Update
  459. If action_check.Value = 1 Then
  460. Rem if we are presenting only records which have the action flag set,
  461. Rem then we need to update the SQL
  462. filt_adr
  463. End If
  464. upd_fields
  465. End Sub
  466. Sub del_but_Click ()
  467. Dim decis As Integer
  468. decis = MsgBox("Really delete record?", 4)
  469. If decis = 6 Then
  470. adr_ds.Delete
  471.     adr_ds.MovePrevious
  472.     If adr_ds.BOF Then
  473.     adr_ds.MoveFirst
  474.     End If
  475.     upd_fields
  476. End If
  477. End Sub
  478. Sub edit_but_Click ()
  479. adr_ds.Edit
  480. End Sub
  481. Sub find_but_Click ()
  482. If chk_change() = "Cancel" Then
  483. Exit Sub
  484. End If
  485. Dim rec_to_find As String, curr_rec As String, quotetest As Integer
  486. curr_rec = adr_ds.Bookmark
  487. If curr_ind = "address5" Then
  488. rec_to_find = InputBox$("Enter a post code", "Find a record")
  489. criteria = "ucase$(address5) >= " + "'" + UCase$(rec_to_find) + "'"
  490. rec_to_find = InputBox$("Enter a surname", "Find a record")
  491. criteria = "ucase$(Surname) >= " + "'" + UCase$(rec_to_find) + "'"
  492. End If
  493. ' test for empty string
  494.     If rec_to_find = "" Then
  495.     Exit Sub
  496.     End If
  497. ' If user typed in a single quote, this causes a crash!
  498. ' Therefore, check first
  499.     quotetest = InStr(rec_to_find, "'")
  500.     If quotetest Then
  501.     MsgBox ("Can't search for value including single quote")
  502.     Exit Sub
  503.     End If
  504. adr_ds.FindFirst criteria
  505. If adr_ds.NoMatch Then
  506. MsgBox ("Not found")
  507. adr_ds.Bookmark = curr_rec
  508. End If
  509. upd_fields
  510. End Sub
  511. Sub first_but_Click ()
  512. If chk_change() = "Cancel" Then
  513. Exit Sub
  514. End If
  515. adr_ds.MoveFirst
  516. upd_fields
  517. End Sub
  518. Sub last_but_Click ()
  519. If chk_change() = "Cancel" Then
  520. Exit Sub
  521. End If
  522. adr_ds.MoveLast
  523. upd_fields
  524. End Sub
  525. Sub list_but_Click ()
  526. curr_rec = adr_ds!recnum
  527. If chk_change() = "Cancel" Then
  528. Exit Sub
  529. End If
  530. If first_list = 1 Then
  531. first_list = 0
  532. Rem refresh list if first time
  533. 'It would be nice to refresh list automatically each
  534. 'time, but it takes sooooo long it seems better not
  535. 'to do it...
  536. upd_list
  537. End If
  538. list_form.Show
  539. End Sub
  540. Sub new_but_Click ()
  541. adr_ds.AddNew
  542. newflag = -1
  543. Dim countsnap As snapshot
  544. Dim newnum As Long
  545. ' Now find unique number for recnum field
  546. sql_stmnt = "Select max ([recnum]) as maxrec from address"
  547. Set countsnap = adr_db.CreateSnapshot(sql_stmnt)
  548. countsnap.MoveFirst
  549. newnum = countsnap!maxrec
  550. newnum = newnum + 1
  551. ' assign new number to recnum
  552. adr_ds!recnum = newnum
  553. upd_fields
  554. End Sub
  555. Sub next_but_Click ()
  556. If chk_change() = "Cancel" Then
  557. Exit Sub
  558. End If
  559. adr_ds.MoveNext
  560. If Not adr_ds.EOF Then
  561. upd_fields
  562. MsgBox ("No more addresses")
  563. adr_ds.MoveLast
  564. upd_fields
  565. End If
  566. End Sub
  567. Sub notes_box_LostFocus ()
  568. If newflag Then
  569. ' can't update dynaset if new record
  570. Exit Sub
  571. End If
  572. adr_ds.Edit
  573. adr_ds("NOTES") = notes_box.Text
  574. adr_ds.Update
  575. End Sub
  576. Sub order_option_Click (Index As Integer)
  577. Dim decis As Integer
  578. curr_rec = adr_ds!recnum
  579. If chk_change() = "Cancel" Then
  580. Exit Sub
  581. End If
  582. Select Case Index
  583. Case 0
  584. curr_ind = "address5"
  585. ' address5 is the name of the postcode field
  586. Case 1
  587. curr_ind = "surname"
  588. End Select
  589. refresh_sql
  590. criteria = "recnum = " + Str(curr_rec)
  591. adr_ds.FindFirst criteria
  592. upd_fields
  593. End Sub
  594. Sub pack_but_Click ()
  595. If chk_change() = "Cancel" Then
  596. Exit Sub
  597. End If
  598. screen.MousePointer = 11
  599. Dim adr_tb As table
  600. Dim oldtd As tabledef
  601. Dim newtb As table
  602. Dim newtd As New tabledef
  603. Dim newix As New Index
  604. Dim fieldcount As Integer
  605. curr_rec = adr_ds!recnum
  606. Rem close the dynaset
  607. adr_ds.Close
  608. Set adr_tb = adr_db.OpenTable("ADDRESS")
  609. Rem open the address table
  610. Set oldtd = adr_db.TableDefs("ADDRESS")
  611. Rem define fields
  612. fieldcount = oldtd.Fields.Count - 1
  613. ReDim newfields(fieldcount) As New field
  614. Dim countvar As Integer
  615. For countvar = 0 To fieldcount
  616. newfields(countvar).Name = oldtd.Fields(countvar).Name
  617. newfields(countvar).Type = oldtd.Fields(countvar).Type
  618. newfields(countvar).Size = oldtd.Fields(countvar).Size
  619. Rem now build new tabledef
  620. newtd.Name = "NEWTABLE"
  621.                                        
  622. Rem add fields
  623. For countvar = 0 To fieldcount
  624. newtd.Fields.Append newfields(countvar)
  625. Rem append new table to database
  626. adr_db.TableDefs.Append newtd
  627. Rem open new table
  628. Set newtb = adr_db.OpenTable("NEWTABLE")
  629. Rem copy records from old to new
  630. Rem set order to
  631. adr_tb.Index = ""
  632. adr_tb.MoveFirst
  633. sql_stmnt = "insert into newtable select * from address"
  634. adr_db.Execute sql_stmnt
  635. Rem now duplicate indexes
  636. indexcount = oldtd.Indexes.Count - 1
  637. ReDim newindexes(indexcount) As New Index
  638. For countvar = 0 To indexcount
  639. newindexes(countvar).Fields = oldtd.Indexes(countvar).Fields
  640. newindexes(countvar).Name = oldtd.Indexes(countvar).Name
  641. newindexes(countvar).Unique = oldtd.Indexes(countvar).Unique
  642. newindexes(countvar).Primary = oldtd.Indexes(countvar).Primary
  643. Rem add indexes
  644. newtb.Close
  645. Rem must close table before indexing
  646. For countvar = 0 To indexcount
  647. newtd.Indexes.Append newindexes(countvar)
  648. Rem delete and rename
  649. adr_tb.Close
  650. adr_db.Close
  651. Kill "C:\ADR\ADDRESS.DBF"
  652. Kill "C:\ADR\ADDRESS.FPT"
  653. Kill "C:\ADR\ADDRESS.CDX"
  654. Name "C:\ADR\NEWTABLE.DBF" As "C:\ADR\ADDRESS.DBF"
  655. Name "C:\ADR\NEWTABLE.FPT" As "C:\ADR\ADDRESS.FPT"
  656. Name "C:\ADR\NEWTABLE.CDX" As "C:\ADR\ADDRESS.CDX"
  657. Rem reopen database and table
  658. Set adr_db = OpenDatabase("C:\ADR", False, False, "FoxPro 2.5;")
  659. ' Restore dynaset
  660. refresh_sql
  661. ' restore current record
  662. criteria = "recnum = " + Str(curr_rec)
  663. adr_ds.FindFirst criteria
  664. upd_fields
  665. screen.MousePointer = 0
  666. MsgBox ("Pack completed")
  667. End Sub
  668. Sub prev_but_Click ()
  669. If chk_change() = "Cancel" Then
  670. Exit Sub
  671. End If
  672. adr_ds.MovePrevious
  673. If Not adr_ds.BOF Then
  674. upd_fields
  675. MsgBox ("No previous addresses")
  676. adr_ds.MoveFirst
  677. upd_fields
  678. End If
  679. End Sub
  680. Sub quit_but_Click ()
  681. If chk_change() = "Cancel" Then
  682. Exit Sub
  683. End If
  684. End Sub
  685. Sub save_but_Click ()
  686. save_rec
  687. End Sub
  688.