home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / database / mf_db.zip / BCARDS.FRM < prev    next >
Text File  |  1993-05-21  |  38KB  |  1,157 lines

  1. VERSION 2.00
  2. Begin Form bcard 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Business Cards"
  5.    Height          =   5400
  6.    Left            =   870
  7.    LinkTopic       =   "Form3"
  8.    ScaleHeight     =   4740
  9.    ScaleWidth      =   5475
  10.    Top             =   1065
  11.    Width           =   5565
  12.    Begin Frame gBox 
  13.       BackColor       =   &H00C0C0C0&
  14.       Enabled         =   0   'False
  15.       Height          =   4695
  16.       Left            =   60
  17.       TabIndex        =   0
  18.       Top             =   0
  19.       Width           =   5355
  20.       Begin ComboBox Combo1 
  21.          FontBold        =   0   'False
  22.          FontItalic      =   0   'False
  23.          FontName        =   "MS Sans Serif"
  24.          FontSize        =   8.25
  25.          FontStrikethru  =   0   'False
  26.          FontUnderline   =   0   'False
  27.          Height          =   300
  28.          Left            =   3180
  29.          Style           =   2  'Dropdown List
  30.          TabIndex        =   10
  31.          Top             =   2940
  32.          Width           =   1995
  33.       End
  34.       Begin TextBox Text1 
  35.          Height          =   285
  36.          Index           =   0
  37.          Left            =   180
  38.          TabIndex        =   1
  39.          Top             =   780
  40.          Width           =   2115
  41.       End
  42.       Begin TextBox Text1 
  43.          Height          =   285
  44.          Index           =   1
  45.          Left            =   2340
  46.          TabIndex        =   2
  47.          Top             =   780
  48.          Width           =   2835
  49.       End
  50.       Begin TextBox Text1 
  51.          Height          =   285
  52.          Index           =   2
  53.          Left            =   180
  54.          TabIndex        =   4
  55.          Top             =   1860
  56.          Width           =   4995
  57.       End
  58.       Begin TextBox Text1 
  59.          Height          =   285
  60.          Index           =   3
  61.          Left            =   180
  62.          TabIndex        =   5
  63.          Top             =   2400
  64.          Width           =   2595
  65.       End
  66.       Begin TextBox Text1 
  67.          Height          =   285
  68.          Index           =   4
  69.          Left            =   2880
  70.          TabIndex        =   6
  71.          Top             =   2400
  72.          Width           =   435
  73.       End
  74.       Begin TextBox Text1 
  75.          Height          =   285
  76.          Index           =   5
  77.          Left            =   3660
  78.          TabIndex        =   7
  79.          Top             =   2400
  80.          Width           =   1515
  81.       End
  82.       Begin TextBox Text1 
  83.          Height          =   285
  84.          Index           =   6
  85.          Left            =   180
  86.          TabIndex        =   3
  87.          Top             =   1320
  88.          Width           =   4995
  89.       End
  90.       Begin CommandButton Command1 
  91.          Caption         =   "&Next Card"
  92.          FontBold        =   0   'False
  93.          FontItalic      =   0   'False
  94.          FontName        =   "MS Sans Serif"
  95.          FontSize        =   8.25
  96.          FontStrikethru  =   0   'False
  97.          FontUnderline   =   0   'False
  98.          Height          =   375
  99.          Index           =   0
  100.          Left            =   120
  101.          TabIndex        =   13
  102.          Top             =   4140
  103.          Width           =   1695
  104.       End
  105.       Begin CommandButton Command1 
  106.          Caption         =   "&Previous Card"
  107.          FontBold        =   0   'False
  108.          FontItalic      =   0   'False
  109.          FontName        =   "MS Sans Serif"
  110.          FontSize        =   8.25
  111.          FontStrikethru  =   0   'False
  112.          FontUnderline   =   0   'False
  113.          Height          =   375
  114.          Index           =   1
  115.          Left            =   120
  116.          TabIndex        =   12
  117.          Top             =   3780
  118.          Width           =   1695
  119.       End
  120.       Begin CommandButton Command2 
  121.          Caption         =   "&Find Card"
  122.          FontBold        =   0   'False
  123.          FontItalic      =   0   'False
  124.          FontName        =   "MS Sans Serif"
  125.          FontSize        =   8.25
  126.          FontStrikethru  =   0   'False
  127.          FontUnderline   =   0   'False
  128.          Height          =   375
  129.          Left            =   120
  130.          TabIndex        =   11
  131.          Top             =   3420
  132.          Width           =   3315
  133.       End
  134.       Begin CommandButton Command3 
  135.          Caption         =   "&New Card"
  136.          FontBold        =   0   'False
  137.          FontItalic      =   0   'False
  138.          FontName        =   "MS Sans Serif"
  139.          FontSize        =   8.25
  140.          FontStrikethru  =   0   'False
  141.          FontUnderline   =   0   'False
  142.          Height          =   375
  143.          Left            =   1800
  144.          TabIndex        =   14
  145.          Top             =   3780
  146.          Width           =   1635
  147.       End
  148.       Begin Frame Frame1 
  149.          BackColor       =   &H00C0C0C0&
  150.          Caption         =   "Order by"
  151.          FontBold        =   0   'False
  152.          FontItalic      =   0   'False
  153.          FontName        =   "MS Sans Serif"
  154.          FontSize        =   8.25
  155.          FontStrikethru  =   0   'False
  156.          FontUnderline   =   0   'False
  157.          Height          =   1155
  158.          Left            =   3660
  159.          TabIndex        =   19
  160.          Top             =   3360
  161.          Width           =   1515
  162.          Begin OptionButton Option1 
  163.             BackColor       =   &H00C0C0C0&
  164.             Caption         =   "Reference"
  165.             FontBold        =   0   'False
  166.             FontItalic      =   0   'False
  167.             FontName        =   "MS Sans Serif"
  168.             FontSize        =   8.25
  169.             FontStrikethru  =   0   'False
  170.             FontUnderline   =   0   'False
  171.             Height          =   255
  172.             Index           =   2
  173.             Left            =   180
  174.             TabIndex        =   18
  175.             Top             =   780
  176.             Width           =   1215
  177.          End
  178.          Begin OptionButton Option1 
  179.             BackColor       =   &H00C0C0C0&
  180.             Caption         =   "Person"
  181.             FontBold        =   0   'False
  182.             FontItalic      =   0   'False
  183.             FontName        =   "MS Sans Serif"
  184.             FontSize        =   8.25
  185.             FontStrikethru  =   0   'False
  186.             FontUnderline   =   0   'False
  187.             Height          =   255
  188.             Index           =   0
  189.             Left            =   180
  190.             TabIndex        =   16
  191.             Top             =   300
  192.             Value           =   -1  'True
  193.             Width           =   1095
  194.          End
  195.          Begin OptionButton Option1 
  196.             BackColor       =   &H00C0C0C0&
  197.             Caption         =   "Company"
  198.             FontBold        =   0   'False
  199.             FontItalic      =   0   'False
  200.             FontName        =   "MS Sans Serif"
  201.             FontSize        =   8.25
  202.             FontStrikethru  =   0   'False
  203.             FontUnderline   =   0   'False
  204.             Height          =   255
  205.             Index           =   1
  206.             Left            =   180
  207.             TabIndex        =   17
  208.             Top             =   540
  209.             Width           =   1155
  210.          End
  211.       End
  212.       Begin TextBox Text1 
  213.          Height          =   285
  214.          Index           =   7
  215.          Left            =   180
  216.          TabIndex        =   8
  217.          Top             =   2940
  218.          Width           =   1455
  219.       End
  220.       Begin TextBox Text1 
  221.          Height          =   285
  222.          Index           =   8
  223.          Left            =   1680
  224.          TabIndex        =   9
  225.          Top             =   2940
  226.          Width           =   1455
  227.       End
  228.       Begin CommandButton Command4 
  229.          Caption         =   "&Save Card"
  230.          FontBold        =   0   'False
  231.          FontItalic      =   0   'False
  232.          FontName        =   "MS Sans Serif"
  233.          FontSize        =   8.25
  234.          FontStrikethru  =   0   'False
  235.          FontUnderline   =   0   'False
  236.          Height          =   375
  237.          Left            =   1800
  238.          TabIndex        =   15
  239.          Top             =   4140
  240.          Width           =   1635
  241.       End
  242.       Begin Label Label1 
  243.          BackColor       =   &H00C0C0C0&
  244.          Caption         =   "Reference"
  245.          FontBold        =   0   'False
  246.          FontItalic      =   0   'False
  247.          FontName        =   "MS Sans Serif"
  248.          FontSize        =   8.25
  249.          FontStrikethru  =   0   'False
  250.          FontUnderline   =   0   'False
  251.          ForeColor       =   &H00FF0000&
  252.          Height          =   255
  253.          Index           =   9
  254.          Left            =   3180
  255.          TabIndex        =   30
  256.          Top             =   2700
  257.          Width           =   915
  258.       End
  259.       Begin Label Label1 
  260.          BackColor       =   &H00C0C0C0&
  261.          Caption         =   "First Name"
  262.          FontBold        =   0   'False
  263.          FontItalic      =   0   'False
  264.          FontName        =   "MS Sans Serif"
  265.          FontSize        =   8.25
  266.          FontStrikethru  =   0   'False
  267.          FontUnderline   =   0   'False
  268.          ForeColor       =   &H00FF0000&
  269.          Height          =   195
  270.          Index           =   0
  271.          Left            =   180
  272.          TabIndex        =   29
  273.          Top             =   540
  274.          Width           =   915
  275.       End
  276.       Begin Label Label1 
  277.          BackColor       =   &H00C0C0C0&
  278.          Caption         =   "Last Name"
  279.          FontBold        =   0   'False
  280.          FontItalic      =   0   'False
  281.          FontName        =   "MS Sans Serif"
  282.          FontSize        =   8.25
  283.          FontStrikethru  =   0   'False
  284.          FontUnderline   =   0   'False
  285.          ForeColor       =   &H00FF0000&
  286.          Height          =   195
  287.          Index           =   1
  288.          Left            =   2340
  289.          TabIndex        =   28
  290.          Top             =   540
  291.          Width           =   915
  292.       End
  293.       Begin Label Label1 
  294.          BackColor       =   &H00C0C0C0&
  295.          Caption         =   "Address"
  296.          FontBold        =   0   'False
  297.          FontItalic      =   0   'False
  298.          FontName        =   "MS Sans Serif"
  299.          FontSize        =   8.25
  300.          FontStrikethru  =   0   'False
  301.          FontUnderline   =   0   'False
  302.          ForeColor       =   &H00FF0000&
  303.          Height          =   255
  304.          Index           =   2
  305.          Left            =   180
  306.          TabIndex        =   27
  307.          Top             =   1620
  308.          Width           =   915
  309.       End
  310.       Begin Label Label1 
  311.          BackColor       =   &H00C0C0C0&
  312.          Caption         =   "City"
  313.          FontBold        =   0   'False
  314.          FontItalic      =   0   'False
  315.          FontName        =   "MS Sans Serif"
  316.          FontSize        =   8.25
  317.          FontStrikethru  =   0   'False
  318.          FontUnderline   =   0   'False
  319.          ForeColor       =   &H00FF0000&
  320.          Height          =   255
  321.          Index           =   3
  322.          Left            =   180
  323.          TabIndex        =   26
  324.          Top             =   2160
  325.          Width           =   915
  326.       End
  327.       Begin Label Label1 
  328.          BackColor       =   &H00C0C0C0&
  329.          Caption         =   "State"
  330.          FontBold        =   0   'False
  331.          FontItalic      =   0   'False
  332.          FontName        =   "MS Sans Serif"
  333.          FontSize        =   8.25
  334.          FontStrikethru  =   0   'False
  335.          FontUnderline   =   0   'False
  336.          ForeColor       =   &H00FF0000&
  337.          Height          =   255
  338.          Index           =   4
  339.          Left            =   2880
  340.          TabIndex        =   25
  341.          Top             =   2160
  342.          Width           =   495
  343.       End
  344.       Begin Label Label1 
  345.          BackColor       =   &H00C0C0C0&
  346.          Caption         =   "Zip Code"
  347.          FontBold        =   0   'False
  348.          FontItalic      =   0   'False
  349.          FontName        =   "MS Sans Serif"
  350.          FontSize        =   8.25
  351.          FontStrikethru  =   0   'False
  352.          FontUnderline   =   0   'False
  353.          ForeColor       =   &H00FF0000&
  354.          Height          =   255
  355.          Index           =   5
  356.          Left            =   3660
  357.          TabIndex        =   24
  358.          Top             =   2160
  359.          Width           =   915
  360.       End
  361.       Begin Label Label1 
  362.          BackColor       =   &H00C0C0C0&
  363.          Caption         =   "Company"
  364.          FontBold        =   0   'False
  365.          FontItalic      =   0   'False
  366.          FontName        =   "MS Sans Serif"
  367.          FontSize        =   8.25
  368.          FontStrikethru  =   0   'False
  369.          FontUnderline   =   0   'False
  370.          ForeColor       =   &H00FF0000&
  371.          Height          =   195
  372.          Index           =   6
  373.          Left            =   180
  374.          TabIndex        =   23
  375.          Top             =   1080
  376.          Width           =   915
  377.       End
  378.       Begin Label Label1 
  379.          BackColor       =   &H00C0C0C0&
  380.          Caption         =   "Voice"
  381.          FontBold        =   0   'False
  382.          FontItalic      =   0   'False
  383.          FontName        =   "MS Sans Serif"
  384.          FontSize        =   8.25
  385.          FontStrikethru  =   0   'False
  386.          FontUnderline   =   0   'False
  387.          ForeColor       =   &H00FF0000&
  388.          Height          =   255
  389.          Index           =   7
  390.          Left            =   180
  391.          TabIndex        =   22
  392.          Top             =   2700
  393.          Width           =   915
  394.       End
  395.       Begin Label Label1 
  396.          BackColor       =   &H00C0C0C0&
  397.          Caption         =   "Fax"
  398.          FontBold        =   0   'False
  399.          FontItalic      =   0   'False
  400.          FontName        =   "MS Sans Serif"
  401.          FontSize        =   8.25
  402.          FontStrikethru  =   0   'False
  403.          FontUnderline   =   0   'False
  404.          ForeColor       =   &H00FF0000&
  405.          Height          =   255
  406.          Index           =   8
  407.          Left            =   1680
  408.          TabIndex        =   21
  409.          Top             =   2700
  410.          Width           =   915
  411.       End
  412.       Begin Label CardNum 
  413.          BackColor       =   &H00C0C0C0&
  414.          Caption         =   "Card: 0/0"
  415.          FontBold        =   0   'False
  416.          FontItalic      =   0   'False
  417.          FontName        =   "MS Sans Serif"
  418.          FontSize        =   8.25
  419.          FontStrikethru  =   0   'False
  420.          FontUnderline   =   0   'False
  421.          Height          =   195
  422.          Left            =   180
  423.          TabIndex        =   20
  424.          Top             =   240
  425.          Width           =   3375
  426.       End
  427.    End
  428.    Begin Menu m_File 
  429.       Caption         =   "&File"
  430.       Begin Menu m_InitDB 
  431.          Caption         =   "&Create Card Databases"
  432.       End
  433.       Begin Menu m_Sep1 
  434.          Caption         =   "-"
  435.       End
  436.       Begin Menu m_Open 
  437.          Caption         =   "&Open Cards"
  438.       End
  439.       Begin Menu m_Close 
  440.          Caption         =   "&Close Cards"
  441.       End
  442.       Begin Menu m_Sep2 
  443.          Caption         =   "-"
  444.       End
  445.       Begin Menu m_Quit 
  446.          Caption         =   "&Quit"
  447.       End
  448.    End
  449.    Begin Menu mOther 
  450.       Caption         =   "&Other"
  451.       Begin Menu mDelete 
  452.          Caption         =   "&Delete"
  453.       End
  454.       Begin Menu mSepOther 
  455.          Caption         =   "-"
  456.       End
  457.       Begin Menu mEditRefTbl 
  458.          Caption         =   "&Edit Reference Table"
  459.       End
  460.       Begin Menu mSepOther2 
  461.          Caption         =   "-"
  462.       End
  463.       Begin Menu mSevere 
  464.          Caption         =   "&SP Demo"
  465.          Begin Menu mSevereLoad 
  466.             Caption         =   "Load list using SP API"
  467.          End
  468.          Begin Menu mNormalLoad 
  469.             Caption         =   "Load list using standard 'skips'"
  470.          End
  471.          Begin Menu SPSep 
  472.             Caption         =   "-"
  473.          End
  474.          Begin Menu mSPCount 
  475.             Caption         =   "Get COUNT- SP"
  476.          End
  477.       End
  478.    End
  479.    Begin Menu m_Test 
  480.       Caption         =   "&Test"
  481.       Begin Menu m_AddXRnd 
  482.          Caption         =   "&Add X - Random"
  483.       End
  484.       Begin Menu m_RplXRandom 
  485.          Caption         =   "&Replace X - Random"
  486.       End
  487.    End
  488.    Begin Menu mHelp 
  489.       Caption         =   "&Help"
  490.       Begin Menu mAbout 
  491.          Caption         =   "&About"
  492.       End
  493.    End
  494. End
  495. Option Explicit
  496.  
  497. ' Change this to a location better for you...
  498. Const CARDFILE = "C:\source\bcard"
  499.  
  500. Dim PersonDBHndl As Integer ' Handle to person db
  501. Dim PersonCurIndex As Integer ' Current index selected
  502. Dim personCurRec As Long      ' Record currently in use...
  503. Dim PersonTotRecs As Long   ' total # of recs in person db
  504.  
  505.  
  506.  
  507. Dim curFile As String   ' Curretly open DB file name
  508.  
  509. ' Take data from disply and store in tCard
  510. Function bcFillData% (c As tCard)
  511.     c.Person.fname = text1(0).Text
  512.     c.Person.lname = text1(1).Text
  513.     c.data.street = text1(2).Text
  514.     c.data.city = text1(3).Text
  515.     c.data.state = text1(4).Text
  516.     c.data.zip = text1(5).Text
  517.  
  518.     c.company.cName = text1(6).Text
  519.  
  520.     
  521.     c.ref.ref = Combo1.ListIndex
  522.     
  523.  
  524.  
  525.     c.data.voice = text1(7).Text
  526.     c.data.fax = text1(8).Text
  527.  
  528.  
  529.  
  530. End Function
  531.  
  532. ' take data from var and display it
  533. Function bcShowData% (c As tCard)
  534.     text1(0).Text = c.Person.fname
  535.     text1(1).Text = c.Person.lname
  536.     text1(2).Text = c.data.street
  537.     text1(3).Text = c.data.city
  538.     text1(4).Text = c.data.state
  539.     text1(5).Text = c.data.zip
  540.  
  541.     text1(6).Text = c.company.cName
  542.     ' since the 'random add' functions don't
  543.     ' set this value properly -- we have to check
  544.     ' for an error condition...
  545.     On Error Resume Next
  546.     Combo1.ListIndex = c.ref.ref
  547.     On Error GoTo 0
  548.  
  549.     text1(7).Text = c.data.voice
  550.     text1(8).Text = c.data.fax
  551.     'Command4.Enabled = False
  552.     'command3.Enabled = False
  553.  
  554.  
  555.  
  556. End Function
  557.  
  558. Sub Command1_Click (Index As Integer)
  559.     Dim PlusMinus As Integer
  560.     Dim NextRec As Long
  561.     Dim bcard As tCard
  562.  
  563.     ' Are They going FORWARD or BACKWARD
  564.     If Index = 0 Then
  565.         PlusMinus = 1   ' Next Record
  566.     ElseIf Index = 1 Then
  567.         PlusMinus = -1
  568.     Else
  569.         PlusMinus = 0   ' just force a re-display
  570.     End If
  571.     If personCurRec > 0 Then
  572.  
  573.         personCurRec = mfSkip(personCurRec, PlusMinus, TaskHndl, PersonDBHndl, PersonCurIndex)
  574.         If personCurRec = MFSEEK_BOF Then
  575.             Beep
  576.             ' They tried to skip past the begining of the file.  Since we already
  577.             ' overwrote the ptr to the previous record, we need to find out
  578.             ' what the first record was...
  579.             personCurRec = mfTop(TaskHndl, PersonDBHndl, PersonCurIndex)
  580.         ElseIf personCurRec = MFSEEK_EOF Then
  581.             Beep
  582.             ' They tried to skip past the END of the file.  Since we already
  583.             ' overwrote the ptr to the previous record, we need to find out
  584.             ' what the first record was...
  585.             personCurRec = mfBottom(TaskHndl, PersonDBHndl, PersonCurIndex)
  586.         End If
  587.         junk = mfRead(personCurRec, bcard, TaskHndl, PersonDBHndl, MFRW_ALL)
  588.     Else
  589.         ' We end up here if it's an empty database
  590.         personCurRec = 0
  591.     End If
  592.  
  593.     If junk < 0 Then
  594.         ' This shouldn't happen...
  595.         MsgBox "Bad Read"
  596.     End If
  597.     cardnum.Caption = curFile + " " + Format$(personCurRec) + " of " + Format$(PersonTotRecs) + " cards"
  598.     junk = bcShowData(bcard)
  599.  
  600. End Sub
  601.  
  602. ' Find a record
  603. Sub Command2_Click ()
  604.     Dim jump$, code%, jumpto&, s$, jumpint%
  605.  
  606.     ' Which Index do they have active? (Order by box)
  607.     If PersonCurIndex = 0 Then
  608.         s = "Seek String for Last/First name"
  609.     ElseIf PersonCurIndex = 1 Then
  610.         s = "Seek String for Company"
  611.     Else
  612.         s = "Seek String for Reference #"
  613.     End If
  614.     jump = InputBox$(s, "Record")
  615.  
  616.     ' NOTE: ALL seeks are SOFT.  If you need an
  617.     ' exact match, then assume if you fully specify
  618.     ' a key, it will be an exact...
  619.     If PersonCurIndex = 2 Then  ' search for a int...
  620.         ' INTS/LONGS/<Specialized> data types are passed with the
  621.         ' MFSEEKO structure.  Since STRINGS (mfseeks) don't pass well
  622.         ' using the as ANY keyword, there is a special mfseeks.  This
  623.         ' is only a problem in VB.  Any language that supports passing
  624.         ' ptrs to data will work fine with mf.
  625.         jumpint = Val(jump)
  626.         personCurRec = mfSeekO(jumpint, code, TaskHndl, PersonDBHndl, PersonCurIndex)
  627.     Else
  628.          ' SHOULD be padded to the length of the key
  629.          ' else, it will probably not seek correctly
  630.          ' (NOTE: Any padding you use for character keys
  631.          ' should be consistent so you won't have to have
  632.          ' alot of routines to do the seeking...
  633.          ' (NOTE: MF doesn't care if you OVERPAD something.  However, if you
  634.          ' UNDERPAD something -- you could get a GPF.  This is just the nature of
  635.          ' the C language )
  636.         jump = jump + Pad(128, " ")
  637.         personCurRec = mfSeekS(jump, code, TaskHndl, PersonDBHndl, PersonCurIndex)
  638.     End If
  639.  
  640.     If personCurRec = MFSEEK_EOF Then
  641.         MsgBox ("Search key was greater than any key in the database")
  642.     Else
  643.         If code = MFSEEK_EXACT_MATCH Then
  644.             MsgBox ("Exact Match")
  645.         Else ' code will equal 2...
  646.             MsgBox ("Closest Match")
  647.         End If
  648.     End If
  649.  
  650.  
  651.     ' will update display with current record
  652.     Command1_Click -1
  653.  
  654. End Sub
  655.  
  656. Sub Command3_Click ()
  657. ' Add a new record
  658.     Dim bcard As tCard
  659.  
  660.     junk = bcFillData(bcard)
  661.    
  662.     ' First, append a new record to the database.
  663.     ' NOTE: ON APPENDS:
  664.     ' PASS >>ONLY<< the DATA portion of the record.  Do NOT pass the
  665.     ' key along with the record.
  666.     personCurRec = mfAppendData(bcard.data, TaskHndl, PersonDBHndl)
  667.     ' Now, we have a reference to the new record.  We should proably
  668.     ' verify that it is a good # (not negative).
  669.     If personCurRec > 0 Then
  670.     
  671.         ' The MFRW_ALL flag tells it to update ALL index fields.  If we want
  672.         ' to enhance the SPEED and we know we have blank fields, then we
  673.         ' could have specified a specific index to update...
  674.         junki = mfWrite(personCurRec, bcard, TaskHndl, PersonDBHndl, MFRW_ALL)
  675.         If junki < 0 Then
  676.             MsgBox "Error on write:" + Format$(junki)
  677.         End If
  678.              
  679.         ' This will tell us how many records are now in the database
  680.         ' The size of a record, and the number of index's
  681.         Dim vRecSize%, vNumIndex%, vNumRecs&
  682.         junk = mfInfoDB(vRecSize, vNumIndex, vNumRecs, TaskHndl, PersonDBHndl)
  683.         PersonTotRecs = vNumRecs
  684.     
  685.     Else
  686.         If junkl < 0 Then
  687.             MsgBox "Error on add:" + Format$(junkl)
  688.         End If
  689.     End If
  690.  
  691.     cardnum.Caption = CARDFILE + " " + Format$(personCurRec) + "/" + Format$(PersonTotRecs)
  692.  
  693. End Sub
  694.  
  695. Sub Command4_Click ()
  696. ' Re-write current record...
  697.     Dim bcard As tCard
  698.     If personCurRec > 0 Then
  699.         ' General function to get TEXT fields into a structure
  700.         junk = bcFillData(bcard)
  701.         
  702.         junkl = mfWrite(personCurRec, bcard, TaskHndl, PersonDBHndl, MFRW_ALL)
  703.     
  704.         If junkl < 0 Then
  705.             MsgBox "Error on write:" + Format$(junkl)
  706.         End If
  707.     Else
  708.         MsgBox "Not a valid record to SAVE to"
  709.     End If
  710.  
  711.  
  712. End Sub
  713.  
  714. Sub Command5_Click ()
  715.     ' To see the 'size' (# of bytes in the key) of a particular index, just add a button (called command5) and
  716.     ' this will show you the 'size' of the active index...
  717.     MsgBox "Index Size:" + Format$(mfInfoIndex(TaskHndl, PersonDBHndl, PersonCurIndex))
  718.  
  719. End Sub
  720.  
  721. Sub Form_Load ()
  722.     mfBeginRun
  723.  
  724.     PersonDBHndl = -1
  725.  
  726. End Sub
  727.  
  728. Sub Form_Unload (Cancel As Integer)
  729.     ' Will auto-close any open db's
  730.     mfEndRun
  731.     
  732.  
  733. End Sub
  734.  
  735. ' Place some sample data in the Reference database
  736. Sub LoadSampleData (file$)
  737.     Dim ref As tReference
  738.  
  739.     refDBHndl = mfOpen(file, TaskHndl)
  740.     ref.ref = 1
  741.     ref.refsub = 0
  742.     ref.name = "Stores"
  743.     junk = mfWrite(mfAppendData(ref.name, TaskHndl, refDBHndl), ref, TaskHndl, refDBHndl, MFRW_ALL)
  744.  
  745.     ref.ref = 1
  746.     ref.refsub = 1
  747.     ref.name = "Pizza"
  748.     junk = mfWrite(mfAppendData(ref.name, TaskHndl, refDBHndl), ref, TaskHndl, refDBHndl, MFRW_ALL)
  749.  
  750.     ref.ref = 1
  751.     ref.refsub = 2
  752.     ref.name = "Computer"
  753.     junk = mfWrite(mfAppendData(ref.name, TaskHndl, refDBHndl), ref, TaskHndl, refDBHndl, MFRW_ALL)
  754.  
  755.     ref.ref = 1
  756.     ref.refsub = 3
  757.     ref.name = "Movies"
  758.     junk = mfWrite(mfAppendData(ref.name, TaskHndl, refDBHndl), ref, TaskHndl, refDBHndl, MFRW_ALL)
  759.     
  760.     ref.ref = 2
  761.     ref.refsub = 0
  762.     ref.name = "Personal"
  763.     junk = mfWrite(mfAppendData(ref.name, TaskHndl, refDBHndl), ref, TaskHndl, refDBHndl, MFRW_ALL)
  764.  
  765.     ref.ref = 2
  766.     ref.refsub = 1
  767.     ref.name = "Relatives"
  768.     junk = mfWrite(mfAppendData(ref.name, TaskHndl, refDBHndl), ref, TaskHndl, refDBHndl, MFRW_ALL)
  769.  
  770.     ref.ref = 2
  771.     ref.refsub = 2
  772.     ref.name = "Friends"
  773.     junk = mfWrite(mfAppendData(ref.name, TaskHndl, refDBHndl), ref, TaskHndl, refDBHndl, MFRW_ALL)
  774.      
  775.     junk = mfClose(refDBHndl, TaskHndl)
  776.  
  777. End Sub
  778.  
  779. Sub m_AddXRnd_Click ()
  780. ' Tests Adding X # of random cards to the database.
  781. ' This is mostly for data-verifaction/system stress test
  782. ' (Since we know the first thing you'll want to do is
  783. ' see if you can crash it, we left this in here...<g>)
  784. ' If you are going to compare the 'speed' of MF with
  785. ' this function, feel free.  We would like to offer
  786. ' the results, though, right now:
  787. '
  788. ' We tested: 3 index's (2 characer, 1 integer... of same
  789. '                       size)
  790. ' Clipper: (DOS)
  791. '       Recs/Second: 5 with LOCK, UNLOCK, FLUSHing
  792. ' (however, we were totally amazed that taking out the 'flush' brought around 150 records/second)
  793. ' unfortunately, the records weren't 'REAL' records and it wasn't a REAL network... oh well)
  794. '
  795. ' vxBase: Recs/Second: 15 with LOCK, UNLOCK, WRITE
  796. '
  797. ' mf:   Generally, 20-30...
  798.  
  799.     If PersonDBHndl = -1 Then
  800.         MsgBox "Open a database before trying this..."
  801.         Exit Sub
  802.     End If
  803.     Dim jump&, n&
  804.     Dim c As tCard
  805.  
  806.     jump = Val(InputBox$("# of records to add?", "Add"))
  807.  
  808.     c.data.street = "<Test Data>"
  809.     c.data.city = "<Test Data>"
  810.     c.data.state = "<>"
  811.     c.data.zip = "<Test>"
  812.     c.data.voice = "<Test>"
  813.     c.data.fax = "<Test>"
  814.     Randomize
  815.  
  816.     screen.MousePointer = 11    ' Hourglass
  817.  
  818.     For n = 1 To jump
  819.  
  820.         c.Person.fname = Format$(Rnd)
  821.         c.Person.lname = Format$(Rnd)
  822.         c.company.cName = Format$(Rnd)
  823.         c.ref.ref = Rnd * 32000
  824.  
  825.         PersonTotRecs = mfAppendData(c.data, TaskHndl, PersonDBHndl)
  826.         
  827.         ' NOTE: To see the 'effect' of INDEXING overhead (described in the
  828.         ' Docs), comment out this line...and step back...<grin>
  829.         junkl = mfWrite(PersonTotRecs, c, TaskHndl, PersonDBHndl, MFRW_ALL)
  830.  
  831.         If junkl < 0 Then
  832.             MsgBox "Error on add:" + Format$(junkl)
  833.         End If
  834.         If Int(n / 10) = n / 10 Then
  835.             cardnum.Caption = "Processed: " + Format$(n)
  836.             cardnum.Refresh
  837.         End If
  838.         ' This creates, in effect, background processing...
  839.         junk = DoEvents()
  840.  
  841.     Next n
  842.  
  843.     screen.MousePointer = 0    ' Default
  844.     'PersonCurRec = PersonTotRecs
  845.     cardnum.Caption = CARDFILE + " " + Format$(personCurRec) + "/" + Format$(PersonTotRecs)
  846.  
  847.  
  848. End Sub
  849.  
  850. ' Closing database...
  851. Sub m_Close_Click ()
  852.     m_Open.Enabled = True
  853.     m_Close.Enabled = False
  854.     gBox.Enabled = False
  855.  
  856.     junk = mfClose(TaskHndl, PersonDBHndl)
  857.     junk = mfClose(TaskHndl, refDBHndl)
  858.     PersonDBHndl = -1
  859.  
  860.  
  861. End Sub
  862.  
  863. ' This demostrates creating a database
  864. Sub m_InitDB_Click ()
  865.     Dim file$, recsize%
  866.     Dim Person As tPerson
  867.     Dim company As tCompany
  868.     Dim ref As tref
  869.     Dim bcard As tCard
  870.     
  871.     If PersonDBHndl <> -1 Then
  872.         MsgBox "Close all databases before doing this..."
  873.         Exit Sub
  874.     End If
  875.  
  876.  
  877.     file = InputBox$("Enter File Name (7 character max -- no extension)", "Create CardFile", CARDFILE)
  878.     If Len(file) > 0 Then
  879.         screen.MousePointer = PHOURGLASS
  880.     
  881.         ' CREATE CARD DATABASE
  882.  
  883.         ' Calculate the size of an individual records 'data'
  884.         recsize = Len(bcard) - Len(Person) - Len(company) - Len(ref)
  885.     
  886.         ' Fill arrays with index parameters
  887.         ' Note: we have 3 index's for this database
  888.         ReDim indSize(0 To 2) As tintArray
  889.         ReDim indType(0 To 2) As tintArray
  890.         indSize(0).i = Len(Person)  ' Key 0 (index 0...)
  891.         indSize(1).i = Len(company) ' Key 1
  892.         indSize(2).i = Len(ref)     ' Key 2
  893.     
  894.             ' This tells mf the TYPE of the index
  895.         indType(0).i = MFCOMP_CHARIC  ' CHAR key - case insensitive
  896.         indType(1).i = 1001           ' UDK (user-defined key) - Sorts in 'reverse' order...
  897.                                       ' (see mfUDK.c for example)
  898.         indType(2).i = MFCOMP_INT     ' An integer key...
  899.         
  900.         If mfCreateDB(file, recsize, 3, indSize(0), indType(0)) < 0 Then
  901.             MsgBox "Error creating card database"
  902.         End If
  903.  
  904.         '**************************************
  905.         ' CREATE REFERENCE DATABASE
  906.  
  907.         file = file + "r"
  908.         ' Calculate the size of an individual records 'data'
  909.         recsize = 25    ' size of the data portion of the record
  910.     
  911.         ' Fill arrays with index parameters
  912.         ' Note: we have 1 index for this database
  913.         ReDim indSize(0 To 0) As tintArray
  914.         ReDim indType(0 To 0) As tintArray
  915.         indSize(0).i = 4  ' length of 2 integer keys...
  916.     
  917.             ' This tells mf the TYPE of the index
  918.         indType(0).i = MFCOMP_INT  ' Integer key
  919.  
  920.         If mfCreateDB(file, recsize, 1, indSize(0), indType(0)) > -1 Then
  921.             ' Let's put some sample data into the REF database
  922.             LoadSampleData file
  923.             
  924.             MsgBox "Databases Created Successfully"
  925.         Else
  926.             MsgBox "Error creating reference database"
  927.         End If
  928.         screen.MousePointer = PNORMAL
  929.  
  930.     End If
  931.  
  932. End Sub
  933.  
  934. ' Demostrates opening a couple of databases
  935. Sub m_Open_Click ()
  936.     Dim vRecSize%, vNumIndex%, vNumRecs&
  937.     Dim file$
  938.     
  939.     file = InputBox$("Enter File Name", "Open CardFile", CARDFILE)
  940.     If Len(file) > 0 Then
  941.         ' Call the open routine with the TASKhndl we recieved
  942.         ' when the application started...
  943.         ' PersonDBHndl will be > -1 if it can open a file...
  944.         PersonDBHndl = mfOpen(file, TaskHndl)
  945.         refDBHndl = mfOpen(file + "r", TaskHndl)
  946.  
  947.         If PersonDBHndl > -1 Then
  948.             curFile = file
  949.  
  950.             junk = mfInfoDB(vRecSize, vNumIndex, vNumRecs, TaskHndl, PersonDBHndl)
  951.             PersonTotRecs = vNumRecs
  952.             m_Open.Enabled = False
  953.             m_Close.Enabled = True
  954.             gBox.Enabled = True
  955.             personCurRec = mfTop(TaskHndl, PersonDBHndl, PersonCurIndex)
  956.  
  957.             ' Load the 'references' combo box
  958.             load_refs Combo1
  959.  
  960.  
  961.  
  962.  
  963.             Command1_Click -1   ' Force disply of top record...
  964.  
  965.                
  966.         Else
  967.             MsgBox "Error on open: " + Str$(PersonDBHndl)
  968.         End If
  969.     End If
  970.  
  971. End Sub
  972.  
  973. Sub m_Quit_Click ()
  974.     Unload bCardREf
  975.     Unload bcard
  976.  
  977. End Sub
  978.  
  979. Sub m_RplXRandom_Click ()
  980. ' Tests changing the key for X # of random cards to the database.
  981. ' This is mostly for data-verifaction/system stress test
  982. ' NOTE: Don't use this code as a SAMPLE!  IT won't work in the real world.
  983.  
  984.     If PersonDBHndl = -1 Then
  985.         MsgBox "Open a database before trying this..."
  986.         Exit Sub
  987.     End If
  988.  
  989.  
  990.     Dim jump&, n&
  991.     Dim c As tCard
  992.  
  993.     jump = Val(InputBox$("# of records to replace?", "Add"))
  994.  
  995.     c.data.street = "<Test Data>"
  996.     c.data.city = "<Test Data>"
  997.     c.data.state = "<>"
  998.     c.data.zip = "<Test>"
  999.     c.data.voice = "<Test>"
  1000.     c.data.fax = "<Test>"
  1001.     Randomize
  1002.  
  1003.     screen.MousePointer = 11    ' Hourglass
  1004.  
  1005.     For n = 1 To jump
  1006.  
  1007.         c.Person.fname = Format$(Rnd)
  1008.         c.Person.lname = Format$(Rnd)
  1009.         c.company.cName = Format$(Rnd)
  1010.         c.ref.ref = Rnd * 32000
  1011.  
  1012.         junkl = mfWrite(n + personCurRec, c, TaskHndl, PersonDBHndl, MFRW_ALL)
  1013.  
  1014.         If junkl < 0 Then
  1015.             MsgBox "Error on replace:" + Format$(junkl)
  1016.         End If
  1017.         If Int(n / 10) = n / 10 Then
  1018.             cardnum.Caption = "Processed: " + Format$(n)
  1019.             cardnum.Refresh
  1020.         End If
  1021.  
  1022.  
  1023.     Next n
  1024.  
  1025.     screen.MousePointer = 0    ' Default
  1026.     'PersonCurRec = PersonTotRecs
  1027.     cardnum.Caption = CARDFILE + " " + Format$(personCurRec) + "/" + Format$(PersonTotRecs)
  1028.  
  1029. End Sub
  1030.  
  1031. Sub mAbout_Click ()
  1032.     MsgBox "Business Cards  -- This application is freeware.  All source code may be used for any purpose you see fit.  However, the mf.BAS file is copyright 1993 by Carl Brown"
  1033. End Sub
  1034.  
  1035. Sub mDelete_Click ()
  1036.     If PersonDBHndl = -1 Then
  1037.         MsgBox "Open a database before trying this..."
  1038.         Exit Sub
  1039.     End If
  1040.     If personCurRec < 1 Then
  1041.         MsgBox "Move to a record before selecting this option..."
  1042.         Exit Sub
  1043.     End If
  1044.  
  1045.     
  1046.     junki = mfDelete(personCurRec, TaskHndl, PersonDBHndl)
  1047. End Sub
  1048.  
  1049. Sub mEditRefTbl_Click ()
  1050.     bCardREf.Show
  1051. End Sub
  1052.  
  1053. ' This demonstrates the difference in speed between the
  1054. ' severe-performance functions in mf and the 'standard' performance
  1055. ' functions in mf (and other databases...)
  1056. ' NOTE:  This is JUST meant to give you a general idea...
  1057. Sub mNormalLoad_Click ()
  1058.     If PersonDBHndl = -1 Then
  1059.         MsgBox "Open a database before trying this..."
  1060.         Exit Sub
  1061.     End If
  1062.     Dim hits&, MAX_HITS&, startTime As Variant, n%, startRec&, rCode%
  1063.  
  1064.     MAX_HITS = 1000
  1065.     screen.MousePointer = PHOURGLASS
  1066.     startTime = Time
  1067.     startRec = mfSeekS("0", rCode, TaskHndl, PersonDBHndl, 0)
  1068.     
  1069.     For n = 0 To MAX_HITS
  1070.         ' First off, in order to get a 'partial-key', we would have to 'read' each record to see if it matched
  1071.         ' but, the point of this demo is to show the difference in 'skips' vs. readlists...
  1072.         ' So, these two are not equal.  The readlist is actually even FASTER than this
  1073.         ' because readlist returns the actual 'matching' list...
  1074.         startRec = mfSkip(startRec, 1, TaskHndl, PersonDBHndl, 0)
  1075.         ' make sure we don't hit EOF
  1076.         If startRec < 1 Then
  1077.             Exit For
  1078.         End If
  1079.  
  1080.     Next n
  1081.     
  1082.     MsgBox "Elapsed time: " + Format$(Time - startTime) + "    # of (potential) records read: " + Format$(n)
  1083.     screen.MousePointer = PNORMAL
  1084.  
  1085. End Sub
  1086.  
  1087. ' Demonstrates using a 'severe-performance' function
  1088. Sub mSevereLoad_Click ()
  1089.     
  1090.     If PersonDBHndl = -1 Then
  1091.         MsgBox "Open a database before trying this..."
  1092.         Exit Sub
  1093.     End If
  1094.     Dim hits&, MAX_HITS&, startTime As Variant, TopRecord&
  1095.  
  1096.     MAX_HITS = 1000
  1097.     ReDim hitList(0 To MAX_HITS) As tLongArray
  1098.     ' This example reads UP TO 1000 records (in sequential order) that start with
  1099.     ' the character "0".  The THIRD parm (a '1') tells the read API call to only
  1100.     ' process the FIRST character in the index field.
  1101.     ' Since we are seeking on a STRING index, we must use the readListS api call...
  1102.     ' NOTE:  The reason we use the "0" as the example is:  If you use the random
  1103.     ' ADD functions (under TEST) alot of "0.xxxxxxxx" names get created...
  1104.     screen.MousePointer = PHOURGLASS    ' This is SO fast, you may not need this...<grin>
  1105.     startTime = Time
  1106.     hits = mfReadListS(0, "0", 1, hitList(0), MAX_HITS, TaskHndl, PersonDBHndl, 0)
  1107.     screen.MousePointer = PNORMAL
  1108.     MsgBox "Elapsed time: " + Format$(Time - startTime) + "    " + "# of records read: " + Format$(hits)
  1109.     
  1110.     ' Demos a 'continuation set' read.  e.g. lets say there are too many hits to
  1111.     ' load in RAM.  You would have to continue the process using a second read...
  1112.     ' This is here just to show 'HOW' it would be done.  This wont actually work unless you
  1113.     ' have over 1000 hits to retrieve.  If you would like to see it work, make sure you put
  1114.     ' over 1000 records in your database (or cut back on the 'MAX_HITS' value...)
  1115.  
  1116.     'hits = mfReadListS(hitList(MAX_HITS), "0", 1, hitList(0), MAX_HITS, TaskHndl, personDBHndl, 0)
  1117.  
  1118.  
  1119.     ' Demos a 'list' of sequential records.  If you just want the first '1000' records, and
  1120.     ' don't care about a particular 'key', use this.
  1121.     'ReDim hitList(0 To MAX_HITS) As tLongArray
  1122.     'TopRecord = mfTop(TaskHndl, personDBHndl, 0)
  1123.     'hits = mfReadListNull(TopRecord, 0&, -1, hitList(0), MAX_HITS, TaskHndl, personDBHndl, 0)
  1124.  
  1125. End Sub
  1126.  
  1127. ' Demos using the readlist COUNT option
  1128. ' See the mSevereLoad for more comments
  1129. Sub mSPCount_Click ()
  1130.  
  1131.     If PersonDBHndl = -1 Then
  1132.         MsgBox "Open a database before trying this..."
  1133.         Exit Sub
  1134.     End If
  1135.     Dim hits&, startTime As Variant
  1136.  
  1137.     
  1138.     ReDim hitList(0 To 0) As tLongArray
  1139.     screen.MousePointer = PHOURGLASS    ' This is SO fast, you may not need this...<grin>
  1140.     startTime = Time
  1141.     hits = mfReadListS(0, "0", 1, hitList(0), MF_SP_COUNT, TaskHndl, PersonDBHndl, 0)
  1142.     screen.MousePointer = PNORMAL
  1143.     MsgBox "Elapsed time: " + Format$(Time - startTime) + "    " + "# of records matching filter: " + Format$(hits)
  1144.     
  1145.  
  1146. End Sub
  1147.  
  1148. Sub Option1_Click (Index As Integer)
  1149.     PersonCurIndex = Index
  1150. End Sub
  1151.  
  1152. Sub Text1_Change (Index As Integer)
  1153.     Command4.Enabled = True
  1154.     command3.Enabled = True
  1155. End Sub
  1156.  
  1157.