现有一个文件,用winhex打开在99baH处有个字符ascii码为aaked,请问用vb如何实现在文件中搜索这几个字符并定位到其偏移地址。
谢谢啦!

解决方案 »

  1.   


    open  filename for binary  as #1
      dim Data as byte
      while not eof(1)
        get #1,i,Data
        if Data=asc("a") then
           dim bData(1 to 4) as byte
           get #1,i+1,bData
           if bdata(1)=asc("a") and bdata(1)=asc("k") and bdata(1)=asc("e") and bdata(1)=asc("d") then
              msgbox "找到了字符,地址为:" i
           end if
        end if
      wend
    close #1
      

  2.   


    '晕,错了,i 没有让其增加open  filename for binary  as #1
      dim Data as byte
      while not eof(1)
        get #1,i,Data
        if Data=asc("a") then
           dim bData(1 to 4) as byte
           get #1,i+1,bData
           if bdata(1)=asc("a") and bdata(1)=asc("k") and bdata(1)=asc("e") and bdata(1)=asc("d") then
              msgbox "找到了字符,地址为:" i
           end if
        end if
        i=i+1
      wend
    close #1
      

  3.   

    楼上的代码运行以来好像有点问题,我改了一下,但运行到If D = 3A And E = 5C Then出错,我知道数据格式不对,但不知怎么改?
    Private Sub Command1_Click()
    Dim D As Byte
    Dim E As Byte
    With CommonDialog1
    .Flags = cdlOFNHideReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer
    .Filter = ("所有文件|*.*")
    .ShowOpen
    End With
    FN = CommonDialog1.FileName
    F = FreeFile()
    i = 1
    Open FN For Binary As F
      While Not EOF(F)
        Get F, i, D
        Get F, i + 1, E
        If D = 3A And E = 5C Then
              Text1.Text = i
           End If
        i = i + 1
      Wend
    Close F
    End Sub
      

  4.   

    If D = 3A And E = 5C Then  '因是是16进制改为 If D = &H3A And E = &H5C Then 
      

  5.   


    Open FN For Binary As F 
      While Not EOF(F) 
        Get F, i, D 
        Get F, i + 1, E 
        If D = 3A And E = 5C Then 
              Text1.Text = i 
          End If 
        i = i + 1 
      Wend 
    Close F 
    '上面一段这样改:dim Data() as long
    dim Count as long Open FN For Binary As F 
      While Not EOF(F) 
        Get F, i, D 
        Get F, i + 1, E 
        If D = &H3A And E = &H5C Then
           count=count+1
           redim preserve Data(Count) as long
           Data(Count) = i 
         End If 
        i = i + 1 
      Wend 
    Close F '要读取所有的
    for i=1 to count
       msgbox data(i)
    next