Is there a correct way of doing this in vb.net?
I want to read a file as a set of numbers such as long integers ,say the file contains the string "Hello World - Its a beautiful day blah blah blah"
This would read as a set of long integers that are 4 bytes long
ie ascii (hex)
48 65 6C 6C 6F 20 57 6F
H e l l o W o
etc and that would also be an 4 byte word represented as a number 1819043144 thus stepping through the file 4 bytes at a time.
Instead of reading and looking for certain words in the file I would look for certain numbers, thus eliminating read errors in certain file types.
I am new to vb.net, and have coded this type of thing in vb6 before , this would be done with the 'get' method and a file pointer.
I have managed to read it a byte at a time with this code but I am unsure where to go with it as the 'get' method isn't in vb.net
Any help would be appreciated
I want to read a file as a set of numbers such as long integers ,say the file contains the string "Hello World - Its a beautiful day blah blah blah"
This would read as a set of long integers that are 4 bytes long
ie ascii (hex)
48 65 6C 6C 6F 20 57 6F
H e l l o W o
etc and that would also be an 4 byte word represented as a number 1819043144 thus stepping through the file 4 bytes at a time.
Instead of reading and looking for certain words in the file I would look for certain numbers, thus eliminating read errors in certain file types.
I am new to vb.net, and have coded this type of thing in vb6 before , this would be done with the 'get' method and a file pointer.
I have managed to read it a byte at a time with this code but I am unsure where to go with it as the 'get' method isn't in vb.net
VB.NET:
Imports System.IO
Imports System.Text
Public Class Form1
Dim Infile As String
Dim StopApplication As Boolean
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.ShowDialog()
Infile = OpenFileDialog1.FileName
ReadBytes()
End Sub
Public Sub ReadBytes()
Dim myFileStream As FileStream
Dim intByte As Integer
Dim lngLoop As Long = 0
Dim bteRead() As Byte
Dim fFile As New FileInfo(Infile)
Dim fSize As Integer = fFile.Length
lblFilesize.Text = "Filesize " & CStr(fSize) & " bytes"
Try
myFileStream = File.OpenRead(Infile)
ReDim bteRead(myFileStream.Length)
For a = 0 To fSize - 1
intByte = myFileStream.ReadByte()
If intByte <> -1 Then bteRead(lngLoop) = CByte(intByte)
lngLoop += 1
lblStatus.Text = "Reading: " & lngLoop
If StopApplication = True Then Exit Sub
Application.DoEvents()
Next
Console.WriteLine(Encoding.ASCII.GetString(bteRead))
myFileStream.Close()
Catch ex As IOException
Console.WriteLine(ex.Message)
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonStopApplication.Click
StopApplication = True
End Sub
End Class
Any help would be appreciated