1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| Private Sub BT_Load_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadFile.Click
Dim ArrayHold() As Byte
Dim Index As Integer = 0
Dim Str As New StringBuilder
Dim tStr As String = ""
Dim tempStr As String = ""
Dim IndexEnd As Integer = 0
Dim InputString As String = ""
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.Filter = "All Files|*.*"
If openFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
' ArrayHold = My.Computer.FileSystem.ReadAllBytes(OpenDia.FileName)
'==============================================================
Dim myStreamReader As StreamReader = Nothing
' Ensure that the creation of the new StreamReader is wrapped in a
' Try-Catch block, since an invalid filename could have been used.
' Create a StreamReader using a Shared (static) File class.
myStreamReader = File.OpenText(openFileDialog1.FileName)
' Read the entire file in one pass, and add the contents to
' txtFileText text box.
InputString = myStreamReader.ReadToEnd()
'Convert string to byte and copy to byte array
ArrayHold = Encoding.Default.GetBytes(InputString)
'=================================================================
'ArrayHold = FileSystem.ReadAllBytes(OpenDia.FileName)
Do
IndexEnd = Index + 9
For x As Integer = Index To IndexEnd
If x > UBound(ArrayHold) Then
Str.Append(" ")
tempStr = tempStr & " "
Else
tStr = UCase(Convert.ToString(ArrayHold(x), 16))
If tStr.Length < 2 Then tStr = "0" & tStr
Str.Append(tStr & " ")
If ArrayHold(x) < 32 Then
tempStr = tempStr & ". "
Else
tempStr = tempStr & Chr(ArrayHold(x)) & " "
End If
End If
Next
Str.Append(" | " & tempStr & vbCrLf)
tempStr = ""
Index = Index + 10
Loop While IndexEnd < UBound(ArrayHold)
DispalyHex.Text = Str.ToString
End If
End Sub |
Partager