Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations SSS148 on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subscript Out Of Range Error Message

Status
Not open for further replies.

Thunder2k4

Computer
Jul 26, 2006
3
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:
Upon debugging the program the error is displayed at the following line in the code:
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
 
Replies continue below

Recommended for you


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.
 
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
 
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:
 
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
Cheers,
Joerd

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor