home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / big_list / textview.frm < prev    next >
Text File  |  1995-02-26  |  5KB  |  187 lines

  1. VERSION 2.00
  2. Begin Form TextView 
  3.    Caption         =   "Big Text File Viewer"
  4.    ClientHeight    =   4695
  5.    ClientLeft      =   1380
  6.    ClientTop       =   1605
  7.    ClientWidth     =   7500
  8.    FontBold        =   0   'False
  9.    FontItalic      =   0   'False
  10.    FontName        =   "Courier New"
  11.    FontSize        =   8.25
  12.    FontStrikethru  =   0   'False
  13.    FontUnderline   =   0   'False
  14.    Height          =   5160
  15.    Left            =   1290
  16.    LinkTopic       =   "Form1"
  17.    ScaleHeight     =   4695
  18.    ScaleWidth      =   7500
  19.    Top             =   1230
  20.    Width           =   7680
  21.    Begin CommandButton Command2 
  22.       Caption         =   "Quit"
  23.       Height          =   330
  24.       Left            =   1785
  25.       TabIndex        =   0
  26.       Top             =   210
  27.       Width           =   1065
  28.    End
  29.    Begin CommandButton Command1 
  30.       Caption         =   "Open File"
  31.       Height          =   330
  32.       Left            =   525
  33.       TabIndex        =   1
  34.       Top             =   210
  35.       Width           =   1065
  36.    End
  37.    Begin CommonDialog CMDialog1 
  38.       Left            =   6090
  39.       Top             =   1680
  40.    End
  41.    Begin PictureBox Picture2 
  42.       FontBold        =   0   'False
  43.       FontItalic      =   0   'False
  44.       FontName        =   "Fixedsys"
  45.       FontSize        =   9
  46.       FontStrikethru  =   0   'False
  47.       FontUnderline   =   0   'False
  48.       Height          =   1170
  49.       Left            =   6090
  50.       ScaleHeight     =   1140
  51.       ScaleWidth      =   405
  52.       TabIndex        =   4
  53.       Top             =   2415
  54.       Width           =   435
  55.    End
  56.    Begin PictureBox Picture1 
  57.       Height          =   2850
  58.       Left            =   210
  59.       ScaleHeight     =   2820
  60.       ScaleWidth      =   5655
  61.       TabIndex        =   3
  62.       Top             =   735
  63.       Width           =   5685
  64.    End
  65.    Begin VScrollBar VScroll1 
  66.       Height          =   750
  67.       LargeChange     =   10
  68.       Left            =   6195
  69.       TabIndex        =   2
  70.       Top             =   735
  71.       Width           =   225
  72.    End
  73.    Begin Label Label2 
  74.       Height          =   330
  75.       Left            =   5775
  76.       TabIndex        =   6
  77.       Top             =   270
  78.       Width           =   1695
  79.    End
  80.    Begin Label Label1 
  81.       Height          =   330
  82.       Left            =   3465
  83.       TabIndex        =   5
  84.       Top             =   270
  85.       Width           =   2115
  86.    End
  87. End
  88. DefInt A-Z
  89.  
  90. Dim FileArray(10000) As String * 80
  91. Dim LineCount, NLinesToShow
  92.  
  93. Sub Command1_Click ()
  94.   
  95.   On Error GoTo ErrHandler
  96.   CMDialog1.Filter = "All Files (*.*)|*.*"
  97.  
  98.   CMDialog1.Action = 1            ' File Open Dialogue Box
  99.   file$ = CMDialog1.Filename      ' File Name
  100.  
  101.   LineCount = 0
  102.   Open file$ For Input As #1
  103.     Filesize& = LOF(1)
  104.     Do Until EOF(1) Or LineCount = 10000
  105.       Line Input #1, lin$
  106.       FileArray(LineCount) = lin$
  107.       LineCount = LineCount + 1
  108.     Loop
  109.   Close
  110.   
  111.   Label1.Caption = Str$(LineCount) + " lines available."
  112.   
  113.   VScroll1.Max = LineCount - NLinesToShow   ' max value for scroll bar
  114.  
  115.   VScroll1.Value = 0    ' reset for new file
  116.   PrintLines            ' print the lines Subroutine
  117.  
  118. ErrHandler:
  119.   Exit Sub
  120.  
  121. End Sub
  122.  
  123. Sub Command2_Click ()
  124.   End
  125.  
  126. End Sub
  127.  
  128. Sub Form_Load ()
  129.   
  130.   ' n lines to show in the "list box"
  131.   NLinesToShow = 15
  132.  
  133.   TextView.Width = Screen.Width   ' form is maximum width
  134.   TextView.Left = 0               ' centre Picture1 on form
  135.   Picture1.Width = TextView.Width * .9
  136.   Picture1.Left = (TextView.Width - Picture1.Width - VScroll1.Width) \ 2
  137.  
  138.   ScaleMode = 3    ' pixels
  139.   ' -1 to overlap the rt side of the picture box with the left side of the scroll
  140.   VScroll1.Left = Picture1.Left + Picture1.Width - 1
  141.   ScaleMode = 1    ' back to twips
  142.   
  143.   ' determine the height of a line of text in Picture 2
  144.   ' make room for 15 lines of text + a bit of space at the bottom
  145.   Picture1.Height = (NLinesToShow + .2) * Picture2.TextHeight("A")
  146.   
  147.   VScroll1.Height = Picture1.Height
  148.   VScroll1.Top = Picture1.Top
  149.   
  150.   Picture2.AutoRedraw = True
  151.   Picture2.Left = -13000   ' move picture2 off the screen
  152.   Picture2.Height = Picture1.Height
  153.   Picture2.Width = Picture1.Width
  154.  
  155.   VScroll1.LargeChange = NLinesToShow
  156.  
  157. End Sub
  158.  
  159. Sub PrintLines ()
  160.   FirstLine = VScroll1.Value
  161.   If FirstLine > LineCount - NLinesToShow Then
  162.     ' so we don't scroll past the end of the file
  163.     FirstLine = LineCount - NLinesToShow
  164.   End If
  165.   If FirstLine < 0 Then FirstLine = 0
  166.   
  167.   ' if fewer lines in file than n lines height of list box
  168.   If NLinesToShow > LineCount Then NLinesToShow = LineCount - 1
  169.   
  170.   Label2.Caption = "Top Line:" + Str$(FirstLine)
  171.   
  172.   For I = FirstLine To FirstLine + NLinesToShow
  173.     Picture2.Print FileArray(I)  ' print lines to Picture2
  174.   Next I
  175.   
  176.   ' copy lines in Picture2 over to Picture1
  177.   Picture1.Picture = Picture2.Image
  178.   Picture2.Cls    ' clear Picture2 for next lines
  179.  
  180. End Sub
  181.  
  182. Sub VScroll1_Change ()
  183.   PrintLines
  184.  
  185. End Sub
  186.  
  187.