home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / fieldpak / fpdemo2r.frm < prev    next >
Text File  |  1993-11-09  |  15KB  |  501 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. End
  167. Option Explicit
  168.  
  169. Sub cmdCancel_Click ()
  170.  
  171.     Unload ReportFrm
  172.  
  173. End Sub
  174.  
  175. Sub cmdDeselectField_Click ()
  176.     Dim i As Integer
  177.     Dim w As Integer
  178.  
  179.     If lstSelectedFields.ListIndex <> -1 Then
  180.         lstAvailableFields.AddItem lstSelectedFields.Text
  181.         w% = Val(DS_GetField((lstSelectedFields.Text), FldDlm$, 3))
  182.         If lstAvailableFields.ListCount = 1 Then
  183.             lstAvailableFields.ListIndex = 0
  184.         End If
  185.         i% = lstSelectedFields.ListIndex
  186.         lstSelectedFields.RemoveItem lstSelectedFields.ListIndex
  187.         If lstSelectedFields.ListCount > 0 Then
  188.             If i% >= lstSelectedFields.ListCount Then
  189.                 i% = lstSelectedFields.ListCount - 1
  190.             End If
  191.             lstSelectedFields.ListIndex = i%
  192.             lblTotalWidth.Caption = Format$(Val(lblTotalWidth.Caption) - w% - 1)
  193.         Else
  194.             lblFieldWidth.Caption = "0"
  195.             lblTotalWidth.Caption = "0"
  196.         End If
  197.     End If
  198.  
  199. End Sub
  200.  
  201. Sub cmdMoveDown_Click ()
  202.     Dim i As Integer
  203.     Dim temp As String
  204.  
  205.     If lstSelectedFields.ListIndex <> -1 Then
  206.         If lstSelectedFields.ListIndex < lstSelectedFields.ListCount - 1 Then
  207.             i% = lstSelectedFields.ListIndex
  208.             temp$ = lstSelectedFields.List(i%)
  209.             lstSelectedFields.RemoveItem i%
  210.             lstSelectedFields.AddItem temp$, i% + 1
  211.             lstSelectedFields.ListIndex = i% + 1
  212.         End If
  213.     End If
  214.  
  215. End Sub
  216.  
  217. Sub cmdMoveUp_Click ()
  218.     Dim i    As Integer
  219.     Dim temp As String
  220.  
  221.     If lstSelectedFields.ListIndex <> -1 Then
  222.         If lstSelectedFields.ListIndex > 0 Then
  223.             i% = lstSelectedFields.ListIndex
  224.             temp$ = lstSelectedFields.List(i%)
  225.             lstSelectedFields.RemoveItem i%
  226.             lstSelectedFields.AddItem temp$, i% - 1
  227.             lstSelectedFields.ListIndex = i% - 1
  228.         End If
  229.     End If
  230.  
  231. End Sub
  232.  
  233. Sub cmdNarrower_Click ()
  234.     Dim w As Integer
  235.     
  236.     If lstSelectedFields.ListCount > 0 Then
  237.         w% = Val(lblFieldWidth.Caption)
  238.         If w% > 0 Then
  239.             lblFieldWidth.Caption = Str$(w% - 1)
  240.             lblTotalWidth.Caption = Format$(Val(lblTotalWidth.Caption) - 1)
  241.             lstSelectedFields.List(lstSelectedFields.ListIndex) = DS_PutField((lstSelectedFields.List(lstSelectedFields.ListIndex)), FldDlm$, 3, (lblFieldWidth.Caption))
  242.         End If
  243.     End If
  244.  
  245. End Sub
  246.  
  247. Sub cmdPreview_Click ()
  248.     Dim i As Integer
  249.     Dim t As String
  250.     
  251.     If lstSelectedFields.ListCount > 0 Then
  252.         pr_num_fields% = lstSelectedFields.ListCount
  253.         ReDim pr_fld_numbers(pr_num_fields% + 1)
  254.         ReDim pr_fld_widths(pr_num_fields% + 1)
  255.         For i% = 1 To pr_num_fields%
  256.             t$ = lstSelectedFields.List(i% - 1)
  257.             t$ = DS_ReplaceDlms(t$, String$(40, " "), "")   ' trim   ???
  258.             pr_fld_numbers(i%) = Val(DS_GetField(t$, FldDlm$, 2))
  259.             pr_fld_widths(i%) = Val(DS_GetField(t$, FldDlm$, 3))
  260.         Next i%
  261.     End If
  262.  
  263.     preview_report
  264.     
  265. End Sub
  266.  
  267. Sub cmdPrint_Click ()
  268.     Dim i As Integer
  269.     Dim t As String
  270.     
  271.     If lstSelectedFields.ListCount > 0 Then
  272.         pr_num_fields% = lstSelectedFields.ListCount
  273.         ReDim pr_fld_numbers(pr_num_fields% + 1)
  274.         ReDim pr_fld_widths(pr_num_fields% + 1)
  275.         For i% = 1 To pr_num_fields%
  276.             t$ = lstSelectedFields.List(i% - 1)
  277.             t$ = DS_ReplaceDlms(t$, String$(40, " "), "")   ' trim   ???
  278.             pr_fld_numbers(i%) = Val(DS_GetField(t$, FldDlm$, 2))
  279.             pr_fld_widths(i%) = Val(DS_GetField(t$, FldDlm$, 3))
  280.         Next i%
  281.     End If
  282.  
  283.     i% = MsgBox("OK to send report to printer?", 4 + 32, "FieldPack Demo Program 2")
  284.     If i% = 6 Then
  285.         print_report
  286.     End If
  287.  
  288. End Sub
  289.  
  290. Sub cmdSelectField_Click ()
  291.     Dim i    As Integer
  292.     Dim temp As String
  293.     Dim tmp  As String
  294.  
  295.     If lstAvailableFields.ListIndex <> -1 Then
  296.         lstSelectedFields.AddItem lstAvailableFields.Text
  297.         If lstSelectedFields.ListCount = 1 Then
  298.             lstSelectedFields.ListIndex = 0
  299.             temp$ = lstSelectedFields.List(lstSelectedFields.ListIndex)
  300.             tmp$ = DS_GetField(temp$, FldDlm$, 3)
  301.             lblTotalWidth.Caption = tmp$
  302.         Else
  303.             lstSelectedFields.ListIndex = lstSelectedFields.ListCount - 1
  304.             temp$ = lstSelectedFields.List(lstSelectedFields.ListIndex)
  305.             tmp$ = DS_GetField(temp$, FldDlm$, 3)
  306.             lblTotalWidth.Caption = Format$(Val(lblTotalWidth.Caption) + 1 + Val(tmp$))
  307.         End If
  308.         i% = lstAvailableFields.ListIndex
  309.         lstAvailableFields.RemoveItem lstAvailableFields.ListIndex
  310.         If lstAvailableFields.ListCount > 0 Then
  311.             If i% >= lstAvailableFields.ListCount Then
  312.                 i% = lstAvailableFields.ListCount - 1
  313.             End If
  314.             lstAvailableFields.ListIndex = i%
  315.         End If
  316.     End If
  317.  
  318. End Sub
  319.  
  320. Sub cmdWider_Click ()
  321.     Dim w As Integer
  322.  
  323.     If lstSelectedFields.ListCount > 0 Then
  324.         w% = Val(lblFieldWidth.Caption)
  325.         lblFieldWidth.Caption = Str$(w% + 1)
  326.         lblTotalWidth.Caption = Format$(Val(lblTotalWidth.Caption) + 1)
  327.         lstSelectedFields.List(lstSelectedFields.ListIndex) = DS_PutField((lstSelectedFields.List(lstSelectedFields.ListIndex)), FldDlm$, 3, (lblFieldWidth.Caption))
  328.     End If
  329.  
  330. End Sub
  331.  
  332. Sub Form_Load ()
  333.     Dim i As Integer
  334.     Dim n As Integer
  335.  
  336.     n% = DS_CountDlms(field_names$, FldDlm$) + 1
  337.     For i% = 1 To n%
  338.         lstAvailableFields.AddItem DS_GetField(field_names$, FldDlm$, i%) + String$(40, " ") + FldDlm$ + Format$(i%) + FldDlm$ + Format$(DS_GetField(field_widths, FldDlm$, i%))
  339.     Next i%
  340.     lstAvailableFields.ListIndex = 0
  341.  
  342. End Sub
  343.  
  344. Function format_hdg$ (opt%)
  345.     Dim rec As String
  346.     Dim buf As String
  347.     Dim fc  As String
  348.     Dim i   As Integer
  349.  
  350.     buf$ = ""
  351.  
  352.     If opt% = 0 Then
  353.         ' show field names
  354.         For i% = 1 To pr_num_fields
  355.             If i% > 1 Then
  356.                 buf$ = buf$ + " "
  357.             End If
  358.             buf$ = buf$ + US_CJustify(DS_GetField(field_names$, FldDlm$, pr_fld_numbers(i%)), pr_fld_widths(i%), " ")
  359.         Next i%
  360.     Else
  361.         ' underline
  362.         For i% = 1 To pr_num_fields
  363.             If i% > 1 Then
  364.                 buf$ = buf$ + " "
  365.             End If
  366.             buf$ = buf$ + String$(pr_fld_widths(i%), "-")
  367.         Next i%
  368.     End If
  369.     
  370.     format_hdg = buf$
  371.  
  372. End Function
  373.  
  374. Function format_line$ (recno%)
  375.     Dim rec As String
  376.     Dim buf As String
  377.     Dim i   As Integer
  378.  
  379.     rec$ = DS_GetField(DatabaseMemoryBuffer$, RecDlm$, recno%)
  380.     'Rearrange record in "normal" field order for simplicity of field extraction:
  381.     rec$ = DS_InsertField(DS_RemoveField(rec$, FldDlm$, 1), FldDlm$, FirstField, DS_GetField(rec$, FldDlm$, 1))
  382.  
  383.     buf$ = ""
  384.  
  385.     For i% = 1 To pr_num_fields
  386.         If i% > 1 Then
  387.             buf$ = buf$ + " "
  388.         End If
  389.         buf$ = buf$ + US_LJustify(DS_GetField(rec$, FldDlm$, pr_fld_numbers(i%)), pr_fld_widths(i%), " ")
  390.     Next i%
  391.     
  392.     format_line = buf$
  393.  
  394. End Function
  395.  
  396. Sub lstAvailableFields_DblClick ()
  397.  
  398.     cmdSelectField_Click
  399.  
  400. End Sub
  401.  
  402. Sub lstSelectedFields_Click ()
  403.     Dim i    As Integer
  404.     Dim iw   As Integer
  405.     Dim tw   As Integer
  406.     Dim temp As String
  407.     Dim tmp  As String
  408.  
  409.     If lstSelectedFields.ListIndex <> -1 Then
  410.         i% = lstSelectedFields.ListIndex
  411.         temp$ = lstSelectedFields.List(i%)
  412.         tmp$ = DS_GetField(temp$, FldDlm$, 3)
  413.         lblFieldWidth.Caption = tmp$
  414.     End If
  415.    
  416. End Sub
  417.  
  418. Sub lstSelectedFields_DblClick ()
  419.  
  420.     cmdDeselectField_Click
  421.  
  422. End Sub
  423.  
  424. Sub preview_report ()
  425.     Dim buf   As String
  426.     Dim i     As Integer
  427.     Dim crlf  As String
  428.     Dim pr_num_recs As Integer
  429.     
  430.     If FlagNewRecordInProgress Then
  431.         pr_num_recs = NumberOfRecords - 1
  432.     Else
  433.         pr_num_recs = NumberOfRecords
  434.     End If
  435.     
  436.     Load PreviewFrm
  437.  
  438.     crlf$ = Chr$(13) + Chr$(10)
  439.  
  440.     buf$ = crlf$
  441.  
  442.     buf$ = buf$ + "Records sequenced by " + EditFrm.lblCurrentSortField.Caption + crlf$
  443.  
  444.     buf$ = buf$ + crlf$
  445.  
  446.     buf$ = buf$ + format_hdg$(0) + crlf$
  447.     
  448.     buf$ = buf$ + format_hdg$(1) + crlf$
  449.     
  450.     For i% = 1 To pr_num_recs
  451.         buf$ = buf$ + format_line$(i%) + crlf$
  452.     Next i%
  453.  
  454.     buf$ = buf$ + "--- " + Format$(pr_num_recs, "0") + " records ---" + crlf$
  455.  
  456.     PreviewFrm.txtReportPreview.Text = buf$
  457.     PreviewFrm.Show 1
  458.  
  459. End Sub
  460.  
  461. Sub print_report ()
  462.     Dim buf   As String
  463.     Dim i     As Integer
  464.     Dim tw    As Integer
  465.     Dim pr_num_recs As Integer
  466.     
  467.     If FlagNewRecordInProgress Then
  468.         pr_num_recs = NumberOfRecords - 1
  469.     Else
  470.         pr_num_recs = NumberOfRecords
  471.     End If
  472.  
  473.     tw% = 0
  474.     For i% = 1 To pr_num_fields%
  475.         If i% > 1 Then
  476.             tw% = tw% + 1
  477.         End If
  478.         tw% = tw% + pr_fld_widths(i%)
  479.     Next i%
  480.  
  481.     Printer.Print US_CJustify(DatabaseFileName$, tw%, " ")
  482.     Printer.Print ""
  483.     Printer.Print US_CJustify("Records sequenced by " + EditFrm.lblCurrentSortField.Caption, tw%, " ")
  484.     Printer.Print ""
  485.     Printer.Print format_hdg$(0)
  486.     Printer.Print format_hdg$(1)
  487.  
  488.     For i% = 1 To pr_num_recs
  489.         Printer.Print format_line$(i%)
  490.     Next i%
  491.  
  492.     Printer.Print ""
  493.     Printer.Print Format$(pr_num_recs, "0") + " records"
  494.  
  495.     Printer.Print Chr$(12)
  496.     
  497.     Printer.EndDoc
  498.     
  499. End Sub
  500.  
  501.