2 Replies - 637 Views - Last Post: 22 April 2014 - 05:23 PM Rate Topic: -----

#1 kiad_198  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 128
  • Joined: 19-November 08

Subscript out of range

Posted 22 April 2014 - 02:47 PM

hi guys,

got a problem in Subscript out of range

                Dim RegTemplate() As String
                Dim index As Integer
                Dim filenum As Integer
                Dim fileLength As Integer
                Dim bytes() As Byte
                Dim templateString As String
                Dim data As Byte
                Dim i As Long
    
                filenum = FreeFile()
                Open "D:\sample.txt" For Binary As filenum
                fileLength = LOF(filenum)
                ReDim bytes(fileLength)
                i = 0
                
                Do While Not EOF(filenum)
                Get filenum, , data
                bytes(i) = data
                i = i + 1
                Loop
                Close filenum

                
                RegTemplate(index) = bytes



Posted Image


please help me.


thanks
kiad

Is This A Good Question/Topic? 0
  • +

Replies To: Subscript out of range

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3175
  • View blog
  • Posts: 10,625
  • Joined: 12-December 12

Re: Subscript out of range

Posted 22 April 2014 - 03:09 PM

What is the value of i when the error occurs?
ReDim bytes(fileLength)

I am not certain that this starts indexing from 0, so it is better to be explicit:
ReDim bytes(0 To fileLength-1)

You can also read the entire file in one go:
Get filenum, , bytes

You also haven't dimensioned RegTemplate - perhaps this is where the error occurs(?).
Was This Post Helpful? 0
  • +
  • -

#3 kiad_198  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 128
  • Joined: 19-November 08

Re: Subscript out of range

Posted 22 April 2014 - 05:23 PM

Thank you for the reply, very much appreciated.

Here's the value.
Posted Image


Here's the new value:
Posted Image

I haven't dimensioned RegTemplate.
what should I do?
can you give an idea how please?


thanks
kiad

This post has been edited by kiad_198: 22 April 2014 - 10:39 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1