Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error List
#1
Okay, some people can't make heads or tails out of the various Errors that appear when compiling a game.

The most common and annoying of them are "Subscript Out of Range"

O.M.Bloody.G.

That error is sooo annoying. BUT! Sometimes, it isn't a clients fault. Sometimes it's the coder's fault. For example...

Code:
Private Apple(1 to 10) As Boolean
The code above just makes an array for Apple, so you can set the Boolean value for it as true or false 10 different times.(Hint, this saves you from storing like this: Dim Apple1 As Boolean, Apple2 As Boolean, etc...)

Now, what happens if you make an application where the user can enter in a numeric value that allows them to edit which ever apple variable(1 to 10) they want? Let's also say that you forgot to add a trapping(makes it so that the program runs error free) to prevent that bloody error 'Subscript out of Range'?

Let's write another program.

Code:
Dim AppleNum As Byte

'Get the input
AppleNum = txtAppleNum.Text

Apple(AppleNum) = False

Let's say AppleNum is 12. Uh-oh... You declared Apple as 1 to 10. They tried to edit apple number 12. It doesn't exist. So, the index is 'out of range' to the array you defined. Therefore, you'll get that error. One way of preventing it from getting that error is to use trappings. Here is an example of a trapping.

Code:
Dim AppleNum As Byte

AppleNum = txtAppleNum.Text

'trapping
If AppleNum = 11 Then
    Call MsgBox("You can't define an apple out of scope!")
    Exit Sub
End if

Apple(AppleNum) = False

That checks if AppleNum is equal to or less than 0 or if AppleNum is equal to or greater than 11. If so, exit the sub and prevent the error. If AppleNum is within 1 to 10, it'll skip the Exit Sub and procede with the code.

This is the best way to prevent the subscript error. If you ever get the error, the best way to figure it out is to see if the index is out of scope to what you defined. If so, redefine your scope or add a trapping.


Great, we know what Subscript is now! Let's point out another common error that drives people insane.

"Sub or Function Not Defined"

ZOMG, SUM1 HLP ME! DIS ERROR IZ TEH ANNOYINSG!

Read what it says.

Do it again.


Read it one more time...



Understand what it means yet? It means the Sub or Function you are trying to Call does not exist, or isn't defined... This is important! YOU MUST DEFINE YOUR SUBS BEFORE CALLING THEM!

That's like trying to yell for your mom when you're at home and she's at work.


Another one, "Variable Not Defined"
Lol, this one is brought on by yourself. You used Option Explicit(GOOD FOR YOU! You get a cookie!) But your silly self forgot to define the variable you meant to use! Isn't that a problem? =/

Code:
Option Explicit

Sub Hi()
x = 10
End Sub

OH NOEZ! THIS CAN'T BE! VARIABLE NOT DEFINED!

Simple fix.

Code:
Option Explicit

Sub Hi()
Dim x As Byte
x = 10
End Sub

There we go. That wasn't too bad.


Here's one that sometimes throws people for a loop. "Ambiguous Name Detected"

For many of us, we've barely passed vocab tests in school. People are often confused by the word Ambiguoius. Let's take a Latin lesson, shall we?

Ambi- is the English root for more than one. It comes from the latin amphi which means more than one. Yes, we still use amphi, but ambi is the exact same root.

With that being said, Ambiguous means more than one. When it says Ambiguous Name, what does that mean? You have more than one Name Defined. Guess what you have to do. Get rid of one.

Code:
Sub Hello()
Call Goodbye
End Sub

Sub Hello()
Call Goodnight
End Sub

You can't define a sub with the same name twice. Same goes for declaration of variables.

Code:
Dim x as Long
Dim x as String

That would cause the error 'Ambiguous Name Detected'

I think I got most of the noobie bugs taken care of. If they are any more, please tell me so I can add and explain them as I did the others. I hope this helps the new programmers to have good programming practices. =D
Reply
#2
Thank you for that. I'll go and fix it.
Reply
#3
Can i repost this on the mr forums? Will give credit of course, covers alot of the 'i am new to programming and trying to put this tutorial in and it said this help plx' posts that are oh so common these days...

I like the initiative :]
Reply
#4
Free for anyone to use, with or without credit, I don't care.

I'd be nice to have the credit, though.
Reply
#5
Thankyou :wink:. Will reword it and such, credit still given - informative and useful post.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)