【问题标题】:Create a search bar for hex values为十六进制值创建一个搜索栏
【发布时间】:2014-12-25 08:38:11
【问题描述】:

我当前的代码要求我在项目仍在 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

【问题讨论】:

  • 两点:“我真的希望能够构建这个项目并在不打开 VB 的情况下使用它” VB.net 在调试文件夹中为每个构建创建一个 .exe。你可以在没有 Visual Studio 的情况下运行。 “一直无法弄清楚如何编码输入值以使用文本框进行搜索”输入值是什么?我对你的目标和你的问题感到困惑。你能详细说明一下吗?
  • 我的应用程序上没有搜索栏。我必须在我的代码中编辑搜索值,并进行调试才能使用它。因此要求我保持 VB 打开以便输入和搜索下一个值。上面的代码返回一个偏移量列表,表明我在文件中的值。
  • 我想使用文本框而不是在我的代码中搜索“b6”
  • 您基本上是在问如何将文本框中的某些文本转换为十六进制值以供您搜索?

标签: vb.net hex bytearray


【解决方案1】:

在 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

【讨论】:

  • 非常感谢先生。这正是我所需要的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-16
  • 2016-07-25
  • 2011-08-04
  • 1970-01-01
  • 1970-01-01
  • 2018-07-26
相关资源
最近更新 更多