Visual Basic (VB6 and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

Visual Basic Library

This page was last updated on Saturday, November 24, 2001

Public Function boolChar(intFile As Integer, strText As String, locStart) As Boolean ' Procedure : boolChar ' Description: Test if character of a file are present. ' Copyright: Chris Greaves Inc. ' Inputs: File handle, character string, start position in file. ' Returns: TRUE if match is made. ' Assumes: None. ' Side Effects: None. ' Tested: By the calls shown below. ' Here is a function that tests specific characters of a file. ' Since it is an internal function it can assume that the given file is ' at least long enough to hold the characters. ' I specify a file handle (so we know that the file exists and is open), ' a string of characters to be sought, and a starting location. ' The starting location is zero-origin; ' the first character is at seek position "0" in the file. ' The starting location can be expressed either as a decimal numeric value ' or as a character string. ' If the latter, I assume it is a hexadecimal location. ' This means that if I am unscrambling a file using a hex portrayal ' like Vernon Buerg's List.COM I can offer as a direct parameter ' the displayed hexadecimal location in the file. ' The little testbed below should get you started; it determines if a file is a WordPerfect file. Dim lngStart As Long If IsNumeric(locStart) Then lngStart = locStart Else If VarType(locStart) = vbString Then lngStart = lngHexToLong(locStart) Else MsgBox "boolChar wrong type " & locStart End If End If Dim intLength As Integer intLength = Len(strText) Dim strChars As String Seek intFile, lngStart + 1 strChars = Input(intLength, intFile) boolChar = (strChars = strText) 'Sub TESTboolChar() 'Dim intFile As Integer 'intFile = FreeFile 'Open "d:\greaves\training\wordpr~1\wp51\Maths.w51" For Binary As intFile 'MsgBox boolChar(intFile, "WPC", 1) ' true 'MsgBox boolChar(intFile, "WPC", "01") ' true 'MsgBox boolChar(intFile, "WPC", "02") ' false 'Close intFile 'End Sub End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Monday, November 19, 2001

 

 

Hosted by www.Geocities.ws

1