what is error with this code

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

    what is error with this code

    [CODE=vb]Private Sub cmdscan_Click()

    Dim a As Long

    a = arrByte(i)

    For i = 49 To mFileSize
    If a <> "4" Then
    a = "4"
    End If
    i = i + 5
    Next i

    End Sub[/CODE]


    this coding give error msg the subscript out of range.Actually i want to read bytes from 49 to end of file.if the byte 49 is 4 then just leave it abd if the value other than that i would like to change to 4.Using for loop mean every 5th value i would like to do same thing.What is the error with the this coding......
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by kirubagari
    Private Sub cmdscan_Click()

    Dim a As Long

    a = arrByte(i)

    For i = 49 To mFileSize
    If a <> "4" Then
    a = "4"
    End If
    i = i + 5
    Next i

    End Sub


    this coding give error msg the subscript out of range.Actually i want to read bytes from 49 to end of file.if the byte 49 is 4 then just leave it abd if the value other than that i would like to change to 4.Using for loop mean every 5th value i would like to do same thing.What is the error with the this coding......
    Please do not post questions in the articles section.
    Moved to forum

    Comment

    • hariharanmca
      Top Contributor
      • Dec 2006
      • 1977

      #3
      Originally posted by kirubagari
      Private Sub cmdscan_Click()

      Dim a As Long

      a = arrByte(i)

      For i = 49 To mFileSize
      If a <> "4" Then
      a = "4"
      End If
      i = i + 5
      Next i

      End Sub


      this coding give error msg the subscript out of range.Actually i want to read bytes from 49 to end of file.if the byte 49 is 4 then just leave it abd if the value other than that i would like to change to 4.Using for loop mean every 5th value i would like to do same thing.What is the error with the this coding......






      Code:
      For i = 49 To mFileSize
      i = i + 5
      Next i
      You are increment the value as 5 steps, so after increase the value it should contain the index number otherwise, can u post where and all you using I value inside for loop.

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        I think people are missing the point here. The line a = arrByte(i) is obviously in the wrong place. As written, this will use whatever value happens to be in variable i when the routine is called. If you don't have Option Explicit at the top of the module, then i may not even exist, in which case VB will simply create it at this point and (I think) assign it the value 0.

        Do you have the "require explicit variable declaration" option turned on? If not, I highly recommend you do so. And add Option Explicit at the top of each module, if it isn't there already.

        Plus, the loop achieves nothing. Presumably, it is intended to check various occurrences in the byte array. But without that a = line, it's doing nothing useful.

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          P.S. You could have replaced that entire loop with the statement a = 4 to get the same effect. This code has a lot of problems.

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            P.P.S. Sorry to be so negative. I've made a quick attempt at correcting the code. Haven't tested this, but I think it will work.

            [CODE=vb]Private Sub cmdscan_Click()
            For i = 49 To mFileSize Step 5
            arrByte(i) = 4
            Next
            End Sub[/CODE]

            Comment

            • hariharanmca
              Top Contributor
              • Dec 2006
              • 1977

              #7
              Originally posted by Killer42
              P.P.S. Sorry to be so negative. I've made a quick attempt at correcting the code. Haven't tested this, but I think it will work.

              [CODE=vb]Private Sub cmdscan_Click()
              For i = 49 To mFileSize Step 5
              arrByte(i) = 4
              Next
              End Sub[/CODE]

              thats good Suggestions.

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                Originally posted by hariharanmca
                thats good Suggestions.
                See my post in your other thread for a more complete solution.

                Comment

                Working...