Visual Basic Subscript out of range

15 pts.
Tags:
Visual Basic
Visual Basic 6
Here's the code: 
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
 
I need help please
 
thanks


Software/Hardware used:
Digital Persona UareU 5160, VB 6.0

Answer Wiki

Thanks. We'll let you know when a new response is added.

from your screen it seems that the arraysize is redim to filelength =256 and you are storing the 257th item in the array. Try initializing i=1, instead of i=0 or put the condition where you increment i=i+1 as;

if i<filelength then i=i+1 

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • lester143
    Thanks for your reply, very much appreciated.

    I tried to replace i=1 but still problem persist. 
    I tried the condition and the value change:


    thanks

    15 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following