home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / fieldpak / fpdemo1.frm < prev    next >
Text File  |  1993-11-30  |  10KB  |  270 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Invoice Browser (FieldPack demo program 1)"
  6.    ClientHeight    =   2505
  7.    ClientLeft      =   2220
  8.    ClientTop       =   1995
  9.    ClientWidth     =   5655
  10.    Height          =   3195
  11.    Left            =   2160
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    ScaleHeight     =   2505
  15.    ScaleWidth      =   5655
  16.    Top             =   1365
  17.    Width           =   5775
  18.    Begin ListBox lstInvoices 
  19.       FontBold        =   -1  'True
  20.       FontItalic      =   0   'False
  21.       FontName        =   "Courier"
  22.       FontSize        =   9.75
  23.       FontStrikethru  =   0   'False
  24.       FontUnderline   =   0   'False
  25.       Height          =   1005
  26.       Left            =   810
  27.       Sorted          =   -1  'True
  28.       TabIndex        =   2
  29.       Top             =   1080
  30.       Width           =   4035
  31.    End
  32.    Begin TextBox txt_hidden_NumberOfInvoices 
  33.       BackColor       =   &H00808080&
  34.       DataField       =   "NumberOfInvoices"
  35.       DataSource      =   "Data1"
  36.       Height          =   285
  37.       Left            =   4440
  38.       TabIndex        =   0
  39.       Top             =   0
  40.       Visible         =   0   'False
  41.       Width           =   495
  42.    End
  43.    Begin Data Data1 
  44.       BackColor       =   &H0000FF00&
  45.       Caption         =   "Customer Name"
  46.       Connect         =   ""
  47.       DatabaseName    =   "c:\FPDEMO1.MDB"
  48.       Exclusive       =   0   'False
  49.       ForeColor       =   &H00000000&
  50.       Height          =   270
  51.       Left            =   1440
  52.       Options         =   0
  53.       ReadOnly        =   0   'False
  54.       RecordSource    =   "InvoicesByCustomer"
  55.       Top             =   240
  56.       Width           =   2565
  57.    End
  58.    Begin Label lblCountDisplay 
  59.       BackColor       =   &H00C0C0C0&
  60.       Caption         =   "3"
  61.       FontBold        =   -1  'True
  62.       FontItalic      =   0   'False
  63.       FontName        =   "MS Sans Serif"
  64.       FontSize        =   12
  65.       FontStrikethru  =   0   'False
  66.       FontUnderline   =   0   'False
  67.       ForeColor       =   &H000000FF&
  68.       Height          =   255
  69.       Left            =   2850
  70.       TabIndex        =   6
  71.       Top             =   2130
  72.       Width           =   195
  73.    End
  74.    Begin Label Label3 
  75.       BackColor       =   &H00C0C0C0&
  76.       Caption         =   "open invoices."
  77.       FontBold        =   -1  'True
  78.       FontItalic      =   -1  'True
  79.       FontName        =   "MS Sans Serif"
  80.       FontSize        =   8.25
  81.       FontStrikethru  =   0   'False
  82.       FontUnderline   =   0   'False
  83.       Height          =   255
  84.       Left            =   3090
  85.       TabIndex        =   5
  86.       Top             =   2160
  87.       Width           =   1695
  88.    End
  89.    Begin Label Label1 
  90.       BackColor       =   &H00C0C0C0&
  91.       Caption         =   "This customer has"
  92.       FontBold        =   -1  'True
  93.       FontItalic      =   -1  'True
  94.       FontName        =   "MS Sans Serif"
  95.       FontSize        =   8.25
  96.       FontStrikethru  =   0   'False
  97.       FontUnderline   =   0   'False
  98.       Height          =   255
  99.       Left            =   1080
  100.       TabIndex        =   4
  101.       Top             =   2160
  102.       Width           =   1695
  103.    End
  104.    Begin Label lblCustomerName 
  105.       BorderStyle     =   1  'Fixed Single
  106.       DataField       =   "CustomerName"
  107.       DataSource      =   "Data1"
  108.       FontBold        =   -1  'True
  109.       FontItalic      =   0   'False
  110.       FontName        =   "Courier"
  111.       FontSize        =   9.75
  112.       FontStrikethru  =   0   'False
  113.       FontUnderline   =   0   'False
  114.       Height          =   255
  115.       Left            =   2010
  116.       TabIndex        =   3
  117.       Top             =   480
  118.       Width           =   1425
  119.    End
  120.    Begin Label Label2 
  121.       BackColor       =   &H00C0C0C0&
  122.       Caption         =   "Invoice Date           Amount          Terms"
  123.       Height          =   255
  124.       Left            =   960
  125.       TabIndex        =   1
  126.       Top             =   840
  127.       Width           =   3615
  128.    End
  129.    Begin Menu mnuFile 
  130.       Caption         =   "&File"
  131.       Begin Menu mnuExit 
  132.          Caption         =   "E&xit"
  133.       End
  134.    End
  135.    Begin Menu mnuExplain 
  136.       Caption         =   "&Explain"
  137.    End
  138. End
  139. Option Explicit
  140.  
  141. 'Program FPDEMO1
  142. 'October 1993
  143. 'By: Sam Cohen
  144. 'Software Source
  145. '42808 Christy St., Ste. 222
  146. 'Fremont, CA  94538  USA
  147. 'Tel +1(510)623-7854   Fax +1(510)651-6039
  148.  
  149. 'Most of the commentary in this program is in the single
  150. 'subroutine "LoadListBox."   (The only other code at all
  151. 'is in Form_Load, lblCustomerName_Change, mnuExplain, and
  152. 'mnuExit.)
  153.  
  154. Sub Form_Load ()
  155.  
  156.     Dim rc As Integer
  157.     MsgBox "This program expects to find the file FPDEMO1.MDB in the root directory of your C: drive.  Please wait while the VB3 MS-Access engine opens this file.", 64, "FieldPack Demo Program 1 -- Software Source"
  158.     rc = FP_Password("Sorry, you'll have to register to get a proper password.")
  159.  
  160. End Sub
  161.  
  162. Sub lblCustomerName_Change ()
  163.  
  164.     'A change to this data-linked control means that
  165.     'we need to reload the list box, since the user has
  166.     'selected a new record.  Each record represents a
  167.     'different customer.  There are three fields in each
  168.     'record:  customer name (which is automatically dis-
  169.     'played in the caption of this data-linked label
  170.     'control); the number of "packed" invoices; and a
  171.     'SuperString (physically stored as a Memo field in
  172.     'the Access database file) containing the packed
  173.     'invoices.  We use a SuperString function to unpack
  174.     'the invoice information and display it in the list
  175.     'box, one invoice per line.
  176.  
  177.     LoadListBox
  178.  
  179. End Sub
  180.  
  181. Sub LoadListBox ()
  182.  
  183.     Dim SS_Format As String
  184.     Dim NumberOfInvoices As Integer
  185.     Dim InvoiceCount As String
  186.     Dim SuperString As String
  187.     Dim Invoice As String
  188.     Dim InvoiceDate As String
  189.     Dim Amount As String
  190.     Dim Terms As String
  191.     Dim ListBoxLine As String
  192.     Dim LoopCounter As Integer
  193.     Dim rc As Integer
  194.  
  195.     lstInvoices.Clear       'Just to be neat, let's first clear out the list box.
  196.     
  197.     SuperString = Data1.Recordset.Fields("Invoices").Value   'Reads the SuperString out of the Access database.
  198.  
  199.     InvoiceCount = US_StripOut((txt_hidden_NumberOfInvoices.Text), " ")   'Note data-linked text box.
  200.     
  201.     SS_Format = "A" + InvoiceCount + "$"
  202.         'The above line of code builds the "Format Description String" we need to supply with
  203.         'any call to a SuperString function (such as the SS_FetchItem call you see below).
  204.         'In this demo, we use a simple SuperString format consisting of only one "piece,"
  205.         'an array of variable length strings.  The number of array elements varies from
  206.         'instance to instance (i.e., from record to record).  Each array element (variable-
  207.         'length string) contains information about a single invoice.  So, if customer XYZ
  208.         'has 6 invoices outstanding, the SuperString for that record contains a 6-element
  209.         'array of variable-length strings, and that SuperString is described with the
  210.         'format string "A6$".
  211.  
  212.  
  213.     lblCountDisplay.Caption = InvoiceCount   'Big red digits.
  214.     
  215.     NumberOfInvoices = Val(InvoiceCount)
  216.  
  217.     For LoopCounter = 1 To NumberOfInvoices
  218.  
  219.         rc = SS_FetchItem(SuperString, SS_Format, LoopCounter, "$", Invoice)
  220.             'The above function call extracts an "item" (in this case, a string containing
  221.             'information about a single invoice) from a SuperString.
  222.  
  223.         If rc <> 0 Then MsgBox "SS error " + Str$(rc)
  224.  
  225.         'Now, we're going to switch gears and demonstrate use of our Delimited Substring (DS_)
  226.         'capabilities (in a very minor way); the DS_GetField calls pick out variable-length
  227.         'substrings ("fields") delimited, in this case, by the "|" character:
  228.  
  229.         InvoiceDate = DS_GetField(Invoice, "|", 1)
  230.         Amount = DS_GetField(Invoice, "|", 2)
  231.         Terms = DS_GetField(Invoice, "|", 3)
  232.  
  233.         'Finally, just for completeness, the next line demonstrates use of some of our Utility
  234.         'String (US_) functions.  (We actually used one of these functions a few lines earlier,
  235.         'to remove blank characters from a string.)
  236.  
  237.         ListBoxLine = US_LJustify(InvoiceDate, 11, " ") + " " + US_RJustify(Amount, 7, "$") + " " + US_RJustify(Terms, 8, " ")
  238.         
  239.         lstInvoices.AddItem ListBoxLine
  240.  
  241.     Next LoopCounter
  242.  
  243. End Sub
  244.  
  245. Sub mnuExit_Click ()
  246.     
  247.     End
  248.  
  249. End Sub
  250.  
  251. Sub mnuExplain_Click ()
  252.  
  253.     Dim K As Integer
  254.     Dim Msg As String
  255.  
  256.     Msg = "This is a very simple demo of how you can use SuperStrings to store a VARIABLE NUMBER of subrecords in a database record.  "
  257.     Msg = Msg + "(SuperStrings are one of the three capabilities in FieldPack.)  "
  258.     Msg = Msg + "In this case, we use a file of customer records, each of which contains a different number of invoice subrecords.  "
  259.     Msg = Msg + Chr$(10) + Chr$(10)
  260.     Msg = Msg + "We use a single MS-Access table of customer records.  Each record has three fields:  "
  261.     Msg = Msg + "customer name, number of invoices (N), and a Memo field.  The Memo field is a SuperString, "
  262.     Msg = Msg + "into which we're packed N invoice 'subrecords.'"
  263.     Msg = Msg + Chr$(10) + Chr$(10)
  264.     Msg = Msg + "Remember, this program is just an illustration of one of the simplest applications of SuperStrings.  "
  265.     Msg = Msg + "By all means, look at the source code; there's only one subroutine ('LoadListBox')."
  266.     MsgBox Msg, 64, "FieldPack Demo Program 1 -- Software Source"
  267.  
  268. End Sub
  269.  
  270.