reading data until eof

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kirubagari
    New Member
    • Jun 2007
    • 158

    #1

    reading data until eof

    [CODE=vb]Private Sub cmdscan_Click()

    Const a As Byte = 4
    Const b As Byte = &HFF
    Dim I As Long
    Dim AnyChanged As Boolean
    Dim changeMade As Boolean
    Dim value As Byte
    'Dim x
    'Dim tmp As String

    For I = 1 To 100 Step 6
    AnyChanged = False
    Debug.Print "Before : "; HexByte2Char(ar rByte(I)); " "; HexByte2Char(ar rByte(I + 1)); " "; HexByte2Char(ar rByte(I + 2)); _
    " "; HexByte2Char(ar rByte(I + 3)); " "; HexByte2Char(ar rByte(I + 4)); " "; HexByte2Char(ar rByte(I + 5))
    ' Print HexByte2Char(I)

    If arrByte(I) <> a Then
    arrByte(I) = a
    value = a
    changeMade = True

    End If
    If arrByte(I + 1) <> b Then
    arrByte(I + 1) = b
    changeMade = True
    End If
    If changeMade Then
    AnyChanged = True
    Debug.Print "After : "; HexByte2Char(ar rByte(I)); " "; HexByte2Char(ar rByte(I + 1)); " "; HexByte2Char(ar rByte(I + 2)); _
    " "; HexByte2Char(ar rByte(I + 3)); " "; HexByte2Char(ar rByte(I + 4)); " "; HexByte2Char(ar rByte(I + 5)); _
    " <--- Corrected"
    End If
    Debug.Print
    Next

    End Sub[/CODE]


    this is the way i open the file


    [CODE=vb]Open "a:\bonding .bin " For Binary As mHandle
    'Open gcdg.FileName For Binary As #mHandle
    mFileSize = LOF(mHandle)
    If mFileSize = 0 Then
    Close mHandle
    MsgBox "Empty file"
    Exit Sub
    End If
    Screen.MousePoi nter = vbCross

    ReDim arrByte(1 To mFileSize)
    Get #mHandle, , arrByte
    Close mHandle


    rtbChr.Text = ""
    rtbChr.LoadFile gcdg.FileName[/CODE]



    actualy just know u mention to me that ask me to figure out where the problem occur.When i try to loop from byte 1 to 100 it can loop and give the output.When i try to put 1 to mfilesize it cant loop and it stuck.I do no why its happening.The mFilesize is the end of file.When i try to open the file in the binary editor that i did it can read until end of file.im asking why it cant read until end of file.
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Where is the variable mFileSize defined?

    Comment

    • kirubagari
      New Member
      • Jun 2007
      • 158

      #3
      the variable used is Dim mfilesize as long

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by kirubagari
        the variable used is Dim mfilesize as long
        What I asked is where it's defined. The scope of the variable is important. Also, do you have Option Explicit at the start of each module and form? This can prevent a lot of problems.

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by kirubagari
          actualy just know u mention to me that ask me to figure out where the problem occur.When i try to loop from byte 1 to 100 it can loop and give the output.When i try to put 1 to mfilesize it cant loop and it stuck.I do no why its happening.The mFilesize is the end of file.When i try to open the file in the binary editor that i did it can read until end of file.im asking why it cant read until end of file.
          One more thing. I think the next step in debugging this would be to place a break point on the For statement (put the text cursor on it and press F9 - the line will be highlighted, probably in red).

          When you run it, it will stop at that line and you can check what the value is in your variable. It's always a good idea to make sure you really are working with the values you think you are.

          Comment

          Working...