home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / bigfoot / bigfoot.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-03-14  |  8.3 KB  |  237 lines

  1. VERSION 2.00
  2. Begin Form frmBigFoot 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "BIGFOOT File Viewer"
  5.    ClientHeight    =   6510
  6.    ClientLeft      =   1110
  7.    ClientTop       =   1755
  8.    ClientWidth     =   8415
  9.    FontBold        =   0   'False
  10.    FontItalic      =   0   'False
  11.    FontName        =   "Fixedsys"
  12.    FontSize        =   9
  13.    FontStrikethru  =   0   'False
  14.    FontUnderline   =   0   'False
  15.    Height          =   7200
  16.    Icon            =   BIGFOOT.FRX:0000
  17.    Left            =   1050
  18.    LinkTopic       =   "Form1"
  19.    ScaleHeight     =   6510
  20.    ScaleWidth      =   8415
  21.    Top             =   1125
  22.    Width           =   8535
  23.    Begin CommonDialog CMDialog1 
  24.       Left            =   7800
  25.       Top             =   120
  26.    End
  27.    Begin VScrollBar vsbFile 
  28.       Height          =   4575
  29.       LargeChange     =   30
  30.       Left            =   7800
  31.       Max             =   100
  32.       Min             =   1
  33.       TabIndex        =   0
  34.       Top             =   960
  35.       Value           =   1
  36.       Width           =   255
  37.    End
  38.    Begin TextBox txtFile 
  39.       FontBold        =   0   'False
  40.       FontItalic      =   0   'False
  41.       FontName        =   "Fixedsys"
  42.       FontSize        =   9
  43.       FontStrikethru  =   0   'False
  44.       FontUnderline   =   0   'False
  45.       Height          =   5655
  46.       Left            =   480
  47.       MultiLine       =   -1  'True
  48.       ScrollBars      =   1  'Horizontal
  49.       TabIndex        =   1
  50.       TabStop         =   0   'False
  51.       Top             =   360
  52.       Width           =   7215
  53.    End
  54.    Begin Menu mnuFile 
  55.       Caption         =   "&File"
  56.       Begin Menu mnuFileOpen 
  57.          Caption         =   "&Open"
  58.       End
  59.    End
  60.    Begin Menu mnuHelp 
  61.       Caption         =   "&Help"
  62.       Begin Menu mnuHelpItem 
  63.          Caption         =   "&Help"
  64.          Index           =   0
  65.       End
  66.       Begin Menu mnuHelpItem 
  67.          Caption         =   "-"
  68.          Index           =   1
  69.       End
  70.       Begin Menu mnuHelpItem 
  71.          Caption         =   "&About BIGFOOT"
  72.          Index           =   2
  73.       End
  74.    End
  75. Option Explicit
  76. Dim fileBuff()  As Variant       'array of buffers to store file
  77. Dim numBuffTotal%, numBuffNow%
  78. Dim numLinesTotal%, saveLineNum%
  79. Dim buffLines%, buffBytes%, extraBytes%
  80. Sub Form_Resize ()
  81.     Dim i%, numvisible%
  82.     txtFile.Top = 0
  83.     txtFile.Left = 0
  84.     txtFile.Height = ScaleHeight
  85.     txtFile.Width = ScaleWidth - vsbFile.Width
  86.     vsbFile.Top = 0
  87.     vsbFile.Left = txtFile.Width
  88.     vsbFile.Height = txtFile.Height - vsbFile.Width  'for txtFile's hsb
  89.     numvisible = GetVisibleLines()
  90.     vsbFile.LargeChange = numvisible - 1
  91.     If vsbFile.LargeChange >= numLinesTotal Then   'if all lines visible
  92.         vsbFile.Max = 1
  93.     Else
  94.         vsbFile.Max = numLinesTotal - vsbFile.LargeChange
  95.     End If
  96. End Sub
  97. Function GetVisibleLines% ()
  98.     Dim rc As RECT
  99.     Dim lc%, hDC%
  100.     Dim lfont%, oldfont
  101.     Dim tm As TEXTMETRIC
  102.     Dim di%
  103.     ' Get the formatting rectangle - this describes the
  104.     ' rectangle in the Text Box in which text is placed.
  105.     lc = SendMessage(txtFile.hWnd, EM_GETRECT, 0, rc)
  106.     ' Get a handle to the logical font used by the control.
  107.     ' The VB font properties are accurately reflected by
  108.     ' this logical font.
  109.     lfont = SendMessageByNum(txtFile.hWnd, WM_GETFONT, 0, 0&)
  110.     ' Get a device context to the text control.
  111.     hDC = GetDC(txtFile.hWnd)
  112.     ' Select in the logical font to obtain the exact font
  113.     ' metrics.
  114.     If lfont <> 0 Then oldfont = SelectObject(hDC, lfont)
  115.     di = GetTextMetrics(hDC, tm)
  116.     ' Select out the logical font
  117.     If lfont <> 0 Then lfont = SelectObject(hDC, oldfont)
  118.     ' The lines depends on the formatting rectangle and font height
  119.     GetVisibleLines = (rc.bottom - rc.top) / tm.tmHeight
  120.     ' Release the device context when done.
  121.     di = ReleaseDC(txtFile.hWnd, hDC)
  122. End Function
  123. Sub mnuFileOpen_Click ()
  124.     Dim nextline$, ndx&, linenum%, buff$, msg$, numErr%, avelength%
  125.     CMDialog1.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt"
  126.     CMDialog1.FilterIndex = 2
  127.     CMDialog1.Action = 1     'Open
  128.     If CMDialog1.Filename = "" Then Exit Sub  'Open-Dialog Canceled
  129.     avelength = AVELINELENGTH
  130.     Screen.MousePointer = HOURGLASS
  131. startNewFile:
  132. 'extraBytes is number of bytes which will be added to each buffer
  133. 'from the next buffer in line, to be displayed in the textbox, below
  134. 'the "last" line of current buffer.
  135.     extraBytes = MAXLINESVISIBLE * (avelength + 2)
  136.     buffBytes = 30000 - extraBytes
  137.     buffLines = buffBytes \ (avelength + 2)
  138.     'reset before possible re-Open
  139.     Close #1
  140.     numBuffTotal = 0
  141.     numLinesTotal = 0
  142.     Erase fileBuff
  143.     Open CMDialog1.Filename For Input As #1
  144.     Do Until EOF(1)
  145.         buff = Space$(buffBytes)
  146.         linenum = 0
  147.         ndx = 1
  148.         On Error GoTo errorRead
  149.         Do Until linenum = buffLines Or EOF(1)
  150.             linenum = linenum + 1
  151.             Line Input #1, nextline
  152.             nextline = nextline & Chr(13) & Chr(10)
  153.             Mid$(buff, ndx, Len(nextline)) = nextline
  154.             ndx = ndx + Len(nextline)
  155.         Loop
  156.         On Error GoTo 0
  157.         numLinesTotal = numLinesTotal + linenum
  158.         If linenum > 0 Then        'at least one line
  159.             numBuffTotal = numBuffTotal + 1       'starts at one
  160.             ReDim Preserve fileBuff(numBuffTotal)
  161.             fileBuff(numBuffTotal - 1) = RTrim$(buff)
  162.             buff = ""
  163.         End If
  164.     Loop
  165.     Screen.MousePointer = DEFAULT
  166.     numBuffNow = 1
  167.     If vsbFile.LargeChange >= numLinesTotal Then  'all lines visible
  168.         vsbFile.Max = 1           'disable the vert scroll bar
  169.     Else
  170.         vsbFile.Max = numLinesTotal - vsbFile.LargeChange
  171.     End If
  172.     If numBuffNow = numBuffTotal Then  ' if only one buffer
  173.         txtFile.Text = fileBuff(numBuffNow - 1)
  174.     Else
  175.         txtFile.Text = fileBuff(numBuffNow - 1) & Left$(fileBuff(numBuffNow), extraBytes)
  176.     End If
  177.     caption = CMDialog1.Filename
  178.     vsbFile.Value = 1
  179.     vsbFile.SetFocus
  180.     saveLineNum = 1  'start at first line
  181.     Exit Sub
  182. errorRead:
  183.     numErr = numErr + 1
  184.     Beep
  185.     If Err = 5 And numErr <= 5 Then    'could not fit into file buffer
  186.         avelength = 1.25 * avelength    'so try less lines per buffer
  187.         Resume startNewFile
  188.     End If
  189.     msg = "ERROR During File Read !" & Chr(13) & Chr(10)
  190.     msg = msg & "Attempts to adjust average line length failed" & Chr(13) & Chr(10)
  191.     msg = msg & "HUGE line length? (Try adjusting Const AVELINELENGTH)"
  192.     MsgBox msg, 16
  193.     End
  194. End Sub
  195. Sub mnuHelpItem_Click (Index As Integer)
  196.     Dim msg$
  197.     Select Case Index
  198.         Case 0   'Help
  199.             msg = "BIGFOOT is a read-only viewer for large files." & Chr$(13) & Chr$(10)
  200.             msg = msg & "Program uses Visual Basic Text-Box control for view-port." & Chr$(13) & Chr$(10)
  201.             msg = msg & "See About BIGFOOT for contact information."
  202.             MsgBox msg, 64
  203.         Case 2   'About
  204.             msg = "Dan Metzger  dmetzger@ngdc.noaa.gov" & Chr$(13) & Chr$(10)
  205.             msg = msg & "U.S. National Geophysical Data Center"
  206.             Call ShellAbout(Me.hWnd, "BIGFOOT FREEWARE", msg, Me.Icon)
  207.     End Select
  208. End Sub
  209. Sub txtFile_KeyDown (KeyCode As Integer, Shift As Integer)
  210.     KeyCode = 0
  211.     vsbFile.SetFocus
  212. End Sub
  213. Sub vsbFile_Change ()
  214.     vsbFile_Scroll
  215. End Sub
  216. Sub vsbFile_KeyDown (KeyCode As Integer, Shift As Integer)
  217.     If KeyCode = 37 Or KeyCode = 39 Then  'disable left, right arrows
  218.         KeyCode = 0
  219.     End If
  220. End Sub
  221. Sub vsbFile_Scroll ()
  222.     Dim numtoscroll&, l&, numbuffcorrect%
  223.     numtoscroll = vsbFile.Value - saveLineNum   'started at 1
  224.     saveLineNum = vsbFile.Value
  225.     numbuffcorrect = (vsbFile.Value - 1) \ buffLines + 1
  226.     If numBuffNow <> numbuffcorrect Then
  227.         numBuffNow = numbuffcorrect
  228.         If numBuffNow = numBuffTotal Then  ' if no more buffers
  229.             txtFile.Text = fileBuff(numBuffNow - 1)
  230.         Else
  231.           txtFile.Text = fileBuff(numBuffNow - 1) & Left$(fileBuff(numBuffNow), extraBytes)
  232.         End If
  233.         numtoscroll = vsbFile.Value - ((numBuffNow - 1) * buffLines) - 1
  234.     End If
  235.     l = SendMessageByNum(txtFile.hWnd, EM_LINESCROLL, 0, numtoscroll)
  236. End Sub
  237.