home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / fldpak / fpdemo2r.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1993-11-08  |  14.2 KB  |  425 lines

  1. VERSION 2.00
  2. Begin Form ReportFrm 
  3.    BorderStyle     =   3  'Fixed Double
  4.    Caption         =   "FieldPack demo program 2 -- Report Set-up"
  5.    ClientHeight    =   2625
  6.    ClientLeft      =   1215
  7.    ClientTop       =   1890
  8.    ClientWidth     =   7470
  9.    ControlBox      =   0   'False
  10.    FontBold        =   -1  'True
  11.    FontItalic      =   0   'False
  12.    FontName        =   "Symbol"
  13.    FontSize        =   9.75
  14.    FontStrikethru  =   0   'False
  15.    FontUnderline   =   0   'False
  16.    Height          =   3030
  17.    Left            =   1155
  18.    LinkMode        =   1  'Source
  19.    LinkTopic       =   "Form1"
  20.    MaxButton       =   0   'False
  21.    MinButton       =   0   'False
  22.    ScaleHeight     =   2625
  23.    ScaleWidth      =   7470
  24.    Top             =   1545
  25.    Width           =   7590
  26.    Begin CommandButton cmdPreview 
  27.       Caption         =   "Preview"
  28.       Height          =   315
  29.       Left            =   6420
  30.       TabIndex        =   16
  31.       Top             =   900
  32.       Width           =   855
  33.    End
  34.    Begin CommandButton cmdWider 
  35.       Caption         =   "+"
  36.       Height          =   315
  37.       Left            =   4860
  38.       TabIndex        =   11
  39.       Top             =   1920
  40.       Width           =   315
  41.    End
  42.    Begin CommandButton cmdNarrower 
  43.       Caption         =   "-"
  44.       Height          =   315
  45.       Left            =   5220
  46.       TabIndex        =   10
  47.       Top             =   1920
  48.       Width           =   315
  49.    End
  50.    Begin CommandButton cmdCancel 
  51.       Caption         =   "Cancel"
  52.       Height          =   315
  53.       Left            =   6420
  54.       TabIndex        =   5
  55.       Top             =   1920
  56.       Width           =   855
  57.    End
  58.    Begin CommandButton cmdPrint 
  59.       Caption         =   "Print"
  60.       Height          =   315
  61.       Left            =   6420
  62.       TabIndex        =   4
  63.       Top             =   1410
  64.       Width           =   855
  65.    End
  66.    Begin CommandButton cmdMoveDown 
  67.       Caption         =   "Dn"
  68.       Height          =   315
  69.       Left            =   5700
  70.       TabIndex        =   9
  71.       Top             =   1170
  72.       Width           =   375
  73.    End
  74.    Begin CommandButton cmdDeselectField 
  75.       Caption         =   "<--"
  76.       Height          =   315
  77.       Left            =   2460
  78.       TabIndex        =   3
  79.       Top             =   1200
  80.       Width           =   675
  81.    End
  82.    Begin CommandButton cmdSelectField 
  83.       Caption         =   "-->"
  84.       Height          =   315
  85.       Left            =   2460
  86.       TabIndex        =   2
  87.       Top             =   720
  88.       Width           =   675
  89.    End
  90.    Begin CommandButton cmdMoveUp 
  91.       Caption         =   "Up"
  92.       Height          =   315
  93.       Left            =   5700
  94.       TabIndex        =   8
  95.       Top             =   750
  96.       Width           =   375
  97.    End
  98.    Begin ListBox lstSelectedFields 
  99.       Height          =   1395
  100.       Left            =   3360
  101.       TabIndex        =   1
  102.       Top             =   420
  103.       Width           =   2175
  104.    End
  105.    Begin ListBox lstAvailableFields 
  106.       Height          =   1395
  107.       Left            =   120
  108.       TabIndex        =   0
  109.       Top             =   420
  110.       Width           =   2115
  111.    End
  112.    Begin Label lblTotalWidth 
  113.       Alignment       =   1  'Right Justify
  114.       Caption         =   "0"
  115.       Height          =   195
  116.       Left            =   4440
  117.       TabIndex        =   15
  118.       Top             =   2280
  119.       Width           =   375
  120.    End
  121.    Begin Label lblFieldWidth 
  122.       Alignment       =   1  'Right Justify
  123.       Caption         =   "0"
  124.       Height          =   195
  125.       Left            =   4440
  126.       TabIndex        =   14
  127.       Top             =   1980
  128.       Width           =   375
  129.    End
  130.    Begin Label Label4 
  131.       Alignment       =   1  'Right Justify
  132.       Caption         =   "Total width:"
  133.       Height          =   195
  134.       Left            =   3240
  135.       TabIndex        =   13
  136.       Top             =   2280
  137.       Width           =   1155
  138.    End
  139.    Begin Label Label3 
  140.       Alignment       =   1  'Right Justify
  141.       Caption         =   "Field width:"
  142.       Height          =   195
  143.       Left            =   3240
  144.       TabIndex        =   12
  145.       Top             =   1980
  146.       Width           =   1155
  147.    End
  148.    Begin Label Label2 
  149.       Alignment       =   2  'Center
  150.       Caption         =   "Selected for report:"
  151.       Height          =   195
  152.       Left            =   3360
  153.       TabIndex        =   7
  154.       Top             =   120
  155.       Width           =   2145
  156.    End
  157.    Begin Label Label1 
  158.       Alignment       =   2  'Center
  159.       Caption         =   "Fields available:"
  160.       Height          =   195
  161.       Left            =   150
  162.       TabIndex        =   6
  163.       Top             =   120
  164.       Width           =   2085
  165.    End
  166. Option Explicit
  167. Sub cmdCancel_Click ()
  168.     Unload ReportFrm
  169. End Sub
  170. Sub cmdDeselectField_Click ()
  171.     Dim i As Integer
  172.     Dim w As Integer
  173.     If lstSelectedFields.ListIndex <> -1 Then
  174.         lstAvailableFields.AddItem lstSelectedFields.Text
  175.         w% = Val(DS_GetField((lstSelectedFields.Text), FldDlm$, 3))
  176.         If lstAvailableFields.ListCount = 1 Then
  177.             lstAvailableFields.ListIndex = 0
  178.         End If
  179.         i% = lstSelectedFields.ListIndex
  180.         lstSelectedFields.RemoveItem lstSelectedFields.ListIndex
  181.         If lstSelectedFields.ListCount > 0 Then
  182.             If i% >= lstSelectedFields.ListCount Then
  183.                 i% = lstSelectedFields.ListCount - 1
  184.             End If
  185.             lstSelectedFields.ListIndex = i%
  186.             lblTotalWidth.Caption = Format$(Val(lblTotalWidth.Caption) - w% - 1)
  187.         Else
  188.             lblFieldWidth.Caption = "0"
  189.             lblTotalWidth.Caption = "0"
  190.         End If
  191.     End If
  192. End Sub
  193. Sub cmdMoveDown_Click ()
  194.     Dim i As Integer
  195.     Dim temp As String
  196.     If lstSelectedFields.ListIndex <> -1 Then
  197.         If lstSelectedFields.ListIndex < lstSelectedFields.ListCount - 1 Then
  198.             i% = lstSelectedFields.ListIndex
  199.             temp$ = lstSelectedFields.List(i%)
  200.             lstSelectedFields.RemoveItem i%
  201.             lstSelectedFields.AddItem temp$, i% + 1
  202.             lstSelectedFields.ListIndex = i% + 1
  203.         End If
  204.     End If
  205. End Sub
  206. Sub cmdMoveUp_Click ()
  207.     Dim i    As Integer
  208.     Dim temp As String
  209.     If lstSelectedFields.ListIndex <> -1 Then
  210.         If lstSelectedFields.ListIndex > 0 Then
  211.             i% = lstSelectedFields.ListIndex
  212.             temp$ = lstSelectedFields.List(i%)
  213.             lstSelectedFields.RemoveItem i%
  214.             lstSelectedFields.AddItem temp$, i% - 1
  215.             lstSelectedFields.ListIndex = i% - 1
  216.         End If
  217.     End If
  218. End Sub
  219. Sub cmdNarrower_Click ()
  220.     Dim w As Integer
  221.     If lstSelectedFields.ListCount > 0 Then
  222.         w% = Val(lblFieldWidth.Caption)
  223.         If w% > 0 Then
  224.             lblFieldWidth.Caption = Str$(w% - 1)
  225.             lblTotalWidth.Caption = Format$(Val(lblTotalWidth.Caption) - 1)
  226.             lstSelectedFields.List(lstSelectedFields.ListIndex) = DS_PutField((lstSelectedFields.List(lstSelectedFields.ListIndex)), FldDlm$, 3, (lblFieldWidth.Caption))
  227.         End If
  228.     End If
  229. End Sub
  230. Sub cmdPreview_Click ()
  231.     Dim i As Integer
  232.     Dim t As String
  233.     If lstSelectedFields.ListCount > 0 Then
  234.         pr_num_fields% = lstSelectedFields.ListCount
  235.         ReDim pr_fld_numbers(pr_num_fields% + 1)
  236.         ReDim pr_fld_widths(pr_num_fields% + 1)
  237.         For i% = 1 To pr_num_fields%
  238.             t$ = lstSelectedFields.List(i% - 1)
  239.             t$ = DS_ReplaceDlms(t$, String$(40, " "), "")   ' trim   ???
  240.             pr_fld_numbers(i%) = Val(DS_GetField(t$, FldDlm$, 2))
  241.             pr_fld_widths(i%) = Val(DS_GetField(t$, FldDlm$, 3))
  242.         Next i%
  243.     End If
  244.     preview_report
  245. End Sub
  246. Sub cmdPrint_Click ()
  247.     Dim i As Integer
  248.     Dim t As String
  249.     If lstSelectedFields.ListCount > 0 Then
  250.         pr_num_fields% = lstSelectedFields.ListCount
  251.         ReDim pr_fld_numbers(pr_num_fields% + 1)
  252.         ReDim pr_fld_widths(pr_num_fields% + 1)
  253.         For i% = 1 To pr_num_fields%
  254.             t$ = lstSelectedFields.List(i% - 1)
  255.             t$ = DS_ReplaceDlms(t$, String$(40, " "), "")   ' trim   ???
  256.             pr_fld_numbers(i%) = Val(DS_GetField(t$, FldDlm$, 2))
  257.             pr_fld_widths(i%) = Val(DS_GetField(t$, FldDlm$, 3))
  258.         Next i%
  259.     End If
  260.     i% = MsgBox("OK to send report to printer?", 4 + 32, "FieldPack Demo Program 2")
  261.     If i% = 6 Then
  262.         print_report
  263.     End If
  264. End Sub
  265. Sub cmdSelectField_Click ()
  266.     Dim i    As Integer
  267.     Dim temp As String
  268.     Dim tmp  As String
  269.     If lstAvailableFields.ListIndex <> -1 Then
  270.         lstSelectedFields.AddItem lstAvailableFields.Text
  271.         If lstSelectedFields.ListCount = 1 Then
  272.             lstSelectedFields.ListIndex = 0
  273.             temp$ = lstSelectedFields.List(lstSelectedFields.ListIndex)
  274.             tmp$ = DS_GetField(temp$, FldDlm$, 3)
  275.             lblTotalWidth.Caption = tmp$
  276.         Else
  277.             lstSelectedFields.ListIndex = lstSelectedFields.ListCount - 1
  278.             temp$ = lstSelectedFields.List(lstSelectedFields.ListIndex)
  279.             tmp$ = DS_GetField(temp$, FldDlm$, 3)
  280.             lblTotalWidth.Caption = Format$(Val(lblTotalWidth.Caption) + 1 + Val(tmp$))
  281.         End If
  282.         i% = lstAvailableFields.ListIndex
  283.         lstAvailableFields.RemoveItem lstAvailableFields.ListIndex
  284.         If lstAvailableFields.ListCount > 0 Then
  285.             If i% >= lstAvailableFields.ListCount Then
  286.                 i% = lstAvailableFields.ListCount - 1
  287.             End If
  288.             lstAvailableFields.ListIndex = i%
  289.         End If
  290.     End If
  291. End Sub
  292. Sub cmdWider_Click ()
  293.     Dim w As Integer
  294.     If lstSelectedFields.ListCount > 0 Then
  295.         w% = Val(lblFieldWidth.Caption)
  296.         lblFieldWidth.Caption = Str$(w% + 1)
  297.         lblTotalWidth.Caption = Format$(Val(lblTotalWidth.Caption) + 1)
  298.         lstSelectedFields.List(lstSelectedFields.ListIndex) = DS_PutField((lstSelectedFields.List(lstSelectedFields.ListIndex)), FldDlm$, 3, (lblFieldWidth.Caption))
  299.     End If
  300. End Sub
  301. Sub Form_Load ()
  302.     Dim i As Integer
  303.     Dim n As Integer
  304.     n% = DS_CountDlms(field_names$, FldDlm$) + 1
  305.     For i% = 1 To n%
  306.         lstAvailableFields.AddItem DS_GetField(field_names$, FldDlm$, i%) + String$(40, " ") + FldDlm$ + Format$(i%) + FldDlm$ + Format$(DS_GetField(field_widths, FldDlm$, i%))
  307.     Next i%
  308.     lstAvailableFields.ListIndex = 0
  309. End Sub
  310. Function format_hdg$ (opt%)
  311.     Dim rec As String
  312.     Dim buf As String
  313.     Dim fc  As String
  314.     Dim i   As Integer
  315.     buf$ = ""
  316.     If opt% = 0 Then
  317.         ' show field names
  318.         For i% = 1 To pr_num_fields
  319.             If i% > 1 Then
  320.                 buf$ = buf$ + " "
  321.             End If
  322.             buf$ = buf$ + US_CJustify(DS_GetField(field_names$, FldDlm$, pr_fld_numbers(i%)), pr_fld_widths(i%), " ")
  323.         Next i%
  324.     Else
  325.         ' underline
  326.         For i% = 1 To pr_num_fields
  327.             If i% > 1 Then
  328.                 buf$ = buf$ + " "
  329.             End If
  330.             buf$ = buf$ + String$(pr_fld_widths(i%), "-")
  331.         Next i%
  332.     End If
  333.     format_hdg = buf$
  334. End Function
  335. Function format_line$ (recno%)
  336.     Dim rec As String
  337.     Dim buf As String
  338.     Dim i   As Integer
  339.     rec$ = DS_GetField(DatabaseMemoryBuffer$, RecDlm$, recno%)
  340.     'Rearrange record in "normal" field order for simplicity of field extraction:
  341.     rec$ = DS_InsertField(DS_RemoveField(rec$, FldDlm$, 1), FldDlm$, FirstField, DS_GetField(rec$, FldDlm$, 1))
  342.     buf$ = ""
  343.     For i% = 1 To pr_num_fields
  344.         If i% > 1 Then
  345.             buf$ = buf$ + " "
  346.         End If
  347.         buf$ = buf$ + US_LJustify(DS_GetField(rec$, FldDlm$, pr_fld_numbers(i%)), pr_fld_widths(i%), " ")
  348.     Next i%
  349.     format_line = buf$
  350. End Function
  351. Sub lstAvailableFields_DblClick ()
  352.     cmdSelectField_Click
  353. End Sub
  354. Sub lstSelectedFields_Click ()
  355.     Dim i    As Integer
  356.     Dim iw   As Integer
  357.     Dim tw   As Integer
  358.     Dim temp As String
  359.     Dim tmp  As String
  360.     If lstSelectedFields.ListIndex <> -1 Then
  361.         i% = lstSelectedFields.ListIndex
  362.         temp$ = lstSelectedFields.List(i%)
  363.         tmp$ = DS_GetField(temp$, FldDlm$, 3)
  364.         lblFieldWidth.Caption = tmp$
  365.     End If
  366. End Sub
  367. Sub lstSelectedFields_DblClick ()
  368.     cmdDeselectField_Click
  369. End Sub
  370. Sub preview_report ()
  371.     Dim buf   As String
  372.     Dim i     As Integer
  373.     Dim crlf  As String
  374.     Dim pr_num_recs As Integer
  375.     If FlagNewRecordInProgress Then
  376.         pr_num_recs = NumberOfRecords - 1
  377.     Else
  378.         pr_num_recs = NumberOfRecords
  379.     End If
  380.     Load PreviewFrm
  381.     crlf$ = Chr$(13) + Chr$(10)
  382.     buf$ = crlf$
  383.     buf$ = buf$ + "Records sequenced by " + EditFrm.lblCurrentSortField.Caption + crlf$
  384.     buf$ = buf$ + crlf$
  385.     buf$ = buf$ + format_hdg$(0) + crlf$
  386.     buf$ = buf$ + format_hdg$(1) + crlf$
  387.     For i% = 1 To pr_num_recs
  388.         buf$ = buf$ + format_line$(i%) + crlf$
  389.     Next i%
  390.     buf$ = buf$ + "--- " + Format$(pr_num_recs, "0") + " records ---" + crlf$
  391.     PreviewFrm.txtReportPreview.Text = buf$
  392.     PreviewFrm.Show 1
  393. End Sub
  394. Sub print_report ()
  395.     Dim buf   As String
  396.     Dim i     As Integer
  397.     Dim tw    As Integer
  398.     Dim pr_num_recs As Integer
  399.     If FlagNewRecordInProgress Then
  400.         pr_num_recs = NumberOfRecords - 1
  401.     Else
  402.         pr_num_recs = NumberOfRecords
  403.     End If
  404.     tw% = 0
  405.     For i% = 1 To pr_num_fields%
  406.         If i% > 1 Then
  407.             tw% = tw% + 1
  408.         End If
  409.         tw% = tw% + pr_fld_widths(i%)
  410.     Next i%
  411.     Printer.Print US_CJustify(DatabaseFileName$, tw%, " ")
  412.     Printer.Print ""
  413.     Printer.Print US_CJustify("Records sequenced by " + EditFrm.lblCurrentSortField.Caption, tw%, " ")
  414.     Printer.Print ""
  415.     Printer.Print format_hdg$(0)
  416.     Printer.Print format_hdg$(1)
  417.     For i% = 1 To pr_num_recs
  418.         Printer.Print format_line$(i%)
  419.     Next i%
  420.     Printer.Print ""
  421.     Printer.Print Format$(pr_num_recs, "0") + " records"
  422.     Printer.Print Chr$(12)
  423.     Printer.EndDoc
  424. End Sub
  425.