2014-10-29 43 views
0

我当前的代码要求我在项目仍然在VB时编辑搜索值。我一直无法弄清楚如何编码输入值来使用文本框进行搜索。我真的很想能够构建这个项目并在不打开VB的情况下使用它。以下是我的代码:为十六进制值创建一个搜索栏

Dim filePath As String = Me.TextBox1.Text 'The path for the file you want to search 
    Dim fInfo As New FileInfo("C:\MyFile.File") 
    Dim numBytes As Long = fInfo.Length 
    Dim fStream As New FileStream("C:\MyFile.File", FileMode.Open, FileAccess.Read) 
    Dim br As New BinaryReader(fStream) 
    Dim data As Byte() = br.ReadBytes(CInt(numBytes)) 
    Dim pos As Integer = -1 
    Dim searchItem As String = "b6" 'The hex values of what you want to search 
    Dim searchItemAsInteger As Integer 
    Dim locationsFound As New List(Of Integer) 
    MessageBox.Show("Wait while I Scan?") 
    br.Close() 
    fStream.Close() 
    Integer.TryParse(searchItem, Globalization.NumberStyles.AllowHexSpecifier, CultureInfo.CurrentCulture, searchItemAsInteger) 

    For Each byteItem As Byte In data 
     pos += 1 
     If CInt(byteItem) = searchItemAsInteger Then 
      locationsFound.Add(pos) 
      Me.ListBox1.Items.Add(Hex(pos)) 
     End If 
    Next 
    For i As Integer = 0 To Me.ListBox1.Items.Count - 1 
     Me.ListBox1.SetSelected(i, True) 
    Next 

End Sub 
+0

两点:“我真的很希望能够建立这个项目,并使用它,而无需打开VB” VB.net创建与每一个.exe建立在调试文件夹。你可以在没有Visual Studio的情况下运行。 “一直未能弄清楚如何编码输入值以使用文本框进行搜索”输入值是什么?我对你的目标感到困惑,你的问题是什么。你能详细说明一下吗? – Kat 2014-10-29 16:05:38

+0

我的应用程序没有搜索栏。我不得不编辑我的代码中的搜索值,并调试才能使用它。因此要求我打开VB以输入和搜索下一个值。上面的代码返回一个偏移量列表,表示我在文件中的值。 – King96 2014-10-29 16:35:07

+0

我想使用文本框来搜索“b6”而不是在我的代码中 – King96 2014-10-29 16:36:33

回答

0

在Form1中放置一个名为“txtHexValueToSearch”的文本框。然后替换被注释掉的代码:

' Dim searchItem As String = "b6" 'The hex values of what you want to search 
Dim searchItem As String = Me.txtHexValueToSearch.Text 'The hex values of what you want to search 
+0

非常感谢你,先生。那正是我需要的。 – King96 2014-10-29 20:35:25