-
Im stumped with some array issue thingy....
Ok what I'm doing is loading the first 32 bytes of a file looking for a
string then I start over again and from the last position (minus a few
bytes ) I start searching again. My problem is that it errors the second
time around claiming it (the file io object) cant load the next 32 bytes
into the array as if its already filled or some idiotic thing... HELP!
Here is my code. Use any file for testing longer then 64 bytes
Imports System.IO
Imports System.Text.ASCIIEncoding
Module Module1
Const strtBlock = "MADk" & Chr(80)
Const endBlock = "SCDlt"
Sub Main()
Console.WriteLine("Simcity 4 .dat file parter, Copyright 2003 CPG")
Console.WriteLine("Enter the name of the .dat file you wish to split")
Dim filename As String
filename = Console.ReadLine()
Console.WriteLine("About to process file...")
Dim fs As New FileStream(filename, FileMode.Open)
Dim datfile As IO.BinaryReader
Dim tempByte() As Byte '= New Byte(32) {}
Dim tempString As String
Dim index As Integer = 1
Dim count As Integer = 32
Dim stringExists As Integer ' non zero if true
10: Threading.Thread.CurrentThread.Sleep(New TimeSpan(10)) 'Sleep for 10
ticks (100 nano seconds * 10, 1,000 nanoseconds)
'tempByte = New Byte(32) {} 'Create new array of 32 bytes
tempByte = getbytearray()
datfile = New IO.BinaryReader(fs)
If (datfile.BaseStream.Length - index) < 32 Then count =
(datfile.BaseStream.Length - index) - 32 'Making sure count is never longer
then length of file.
datfile.Read(tempByte, index, count)
tempString = ASCII.GetChars(tempByte) 'Turn my byte array into a string
Erase tempByte
Console.WriteLine(tempString)
stringExists = InStr(tempString, strtBlock, CompareMethod.Binary)
If stringExists = 0 Then
If count < 32 Then
Console.WriteLine("End Searching file")
Console.Read()
End
End If
index = index + (32 - 5)
GoTo 10
Else 'I have found the start Block
Console.WriteLine("Found Start Block @" & index + stringExists) 'Tell user
you have found start byte.
End If
End Sub
Function getbytearray() As Byte()
Dim tempByte() As Byte = New Byte(32) {}
Return tempByte
End Function
End Module
-
Re: Im stumped with some array issue thingy....
On Sat, 18 Jan 2003 05:18:21 -0500, Jay King wrote:
> Ok what I'm doing is loading the first 32 bytes of a file looking for a
> string then I start over again and from the last position (minus a few
> bytes ) I start searching again. My problem is that it errors the second
> time around claiming it (the file io object) cant load the next 32 bytes
> into the array as if its already filled or some idiotic thing... HELP!
In the line
datfile.Read(tempByte, index, count)
the index variable contains the position in the array that you want to
read into, not the position in the input file.
You need to use something like
Dim datfile As IO.BufferedStream
datfile = New BufferedStream(fs)
..
datfile.Seek(index, SeekOrigin.Begin)
datfile.Read(tempByte, 0, count)
Cheers,
Jason
-
Re: Im stumped with some array issue thingy....
Sweet Thanks!
"iGadget" <igadget_@hotmail.com> wrote in message
news:w4n9e6r8ndiy$.bda43ym6lzdy$.dlg@40tude.net...
| On Sat, 18 Jan 2003 05:18:21 -0500, Jay King wrote:
|
| > Ok what I'm doing is loading the first 32 bytes of a file looking for a
| > string then I start over again and from the last position (minus a few
| > bytes ) I start searching again. My problem is that it errors the
second
| > time around claiming it (the file io object) cant load the next 32 bytes
| > into the array as if its already filled or some idiotic thing... HELP!
|
| In the line
| datfile.Read(tempByte, index, count)
| the index variable contains the position in the array that you want to
| read into, not the position in the input file.
|
| You need to use something like
|
| Dim datfile As IO.BufferedStream
| datfile = New BufferedStream(fs)
| .
| datfile.Seek(index, SeekOrigin.Begin)
| datfile.Read(tempByte, 0, count)
|
| Cheers,
| Jason
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks