×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Subscript Out Of Range Error Message

Subscript Out Of Range Error Message

Subscript Out Of Range Error Message

(OP)
Hi, i'm in the process of coding a visual basic RPG game. I have recently added code to allow 1 square of the map to be turned into an object which teleports the user to another map. Although upon running the program it crashes at the stage where the program loads the item responsible for teleporting the user. The debug message is that of a 'Subscript Out Of Range' error, as shown here: http://i71.photobucket.com/albums/i148/Thunder2k6/vb1.jpg

Upon debugging the program the error is displayed at the following line in the code: http://i71.photobucket.com/albums/i148/Thunder2k6/vb2.jpg

Now the .Type variable is supposed to display 0 but for some reason it comes up with the Subscript error message, I have no idea why and I have used loads of different breakpoints to try and find the root of the problem, and have also tried removing sections of the code in order to make it work, as well as setting the variable to 0 manually. Can anyone help me to show me where i'm going wrong?

Thanks in advance,

Thunder

RE: Subscript Out Of Range Error Message


The variable CurObjNo% does not relate to an item in the Item array, or is Item a collection?  Has Item been initialized correctly?

If Item is a collection then:Collections are 1 based, and CurObj% may equal zero.  That is usaually what happens to me in these cases.

RE: Subscript Out Of Range Error Message

(OP)
Hi,

The CurObjNo% variable is used to define which Item is being drawn or is shown in the Inventory.

The (CurObjNo%) part is fine, thats displaying the correct value and that is shown when the mouse is hovered over it, but the .Type part of the variable is supposed to display 0, which it doesn't. This problem is driving me nuts because I can't find the cause of it lol.

Also, what does the Subscript Out Of Range error message mean? I've only been using VB for about a year and haven't encountered it before.

Thanks,

Thunder

RE: Subscript Out Of Range Error Message

I believe that Type is a reserved word. Try changing the variable name

Good Luck
johnwm
________________________________________________________
To get the best from these forums read FAQ731-376 before posting

Steam Engine enthusiasts: www.essexsteam.co.uk

RE: Subscript Out Of Range Error Message

I think GerryMoore is right, %CurObjNo should probably be 1 or greater. By the way, on johnwm's note, both Item and Type are reserved words, so I'd stay away from it. For some fun, you might read http://www.codinghorror.com/blog/archives/000645.html

Cheers,
Joerd

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.

RE: Subscript Out Of Range Error Message

(OP)
Cheers for all the input guys, I just found the problem, I hadn't increased the number of spaces available for Items in the ItemArray lol, bit of a foolish mistake :p

Anyway, thanks for all the help.

Thunder

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close