Results 1 to 4 of 4

Thread: Hello having a run time error

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2017
    Posts
    3

    Hello having a run time error

    Hi I have an error saying Run-Time error 9 subscript out of range.
    vb6.0 highlights this line.

    Code:
    If Player(Index).Version <> GetVar(App.Path & "\data\config.ini", "CONFIG", "VERSION") Then
    What dose it mean when it says, Run-Time error 9 subscript out of range.

    Name:  error.png
Views: 171
Size:  3.3 KB
    Name:  error1.jpg
Views: 150
Size:  12.7 KB

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Hello having a run time error

    Welcome to the forums

    The error is probably because the value Index is not within the LBound or UBound of the Player() array
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,940

    Re: Hello having a run time error

    Interesting. I just sent someone an email about a similar problem. Here's a snippet from that email:

    Basically, in VB, you can grab memory for an array. For instance, we might do something like...

    Dim SomeArray(1 to 5) As Double

    Basically, this says to create space for five numbers. We could set them as following...

    SomeArray(1) = 123
    SomeArray(2) = 234
    SomeArray(3) = 345
    SomeArray(4) = 456
    SomeArray(5) = 567

    However, what's going to happen if we go...

    SomeArray(6) = 678

    That's when we get an Error 9. We've attempted to use some memory that we haven't requested/allocated. VB will stop you from doing this, with Error 9. You get the Error 9 if you're trying to write-to or read-from some non-allocated memory.
    Blueboxos, in your case, the GetVar(...) piece is almost certainly a request to dig something out of an INI file. However, without the code, that isn't 100% certain. But, since there are multiple arguments, some Strings, that's almost certainly not producing the Error 9. And, if something down in that function were out-of-bounds for an array, it would have shown you the line down in that function.

    Therefore, as LaVolpe pointed out, we should be focusing on Player(...). Since you've used the dot-reference with it (Player(...).Version), it must be either an array of class objects, or an array of user-defined-types (UDTs) (or, maybe a control array of some control with a Version property?).

    You are definitely over-running an array. However, an array of what is still an outstanding question. If you could tell us a bit more about what Player(...) is, we could probably help more.

    Good Luck,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  4. #4
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: Hello having a run time error

    Quote Originally Posted by blueboxos View Post
    Hi I have an error saying Run-Time error 9 subscript out of range.
    vb6.0 highlights this line.

    Code:
    If Player(Index).Version <> GetVar(App.Path & "\data\config.ini", "CONFIG", "VERSION") Then
    What dose it mean when it says, Run-Time error 9 subscript out of range.

    Name:  error.png
Views: 171
Size:  3.3 KB
    Name:  error1.jpg
Views: 150
Size:  12.7 KB
    I notice you are using Index in 3 cases
    • IsPlaying(Index)
    • Player(Index)
    • GetPlayerName(Index)


    Questions
    1. Are IsPlaying() and GetPlayerName() arrays or functions?
    2. What is the value of Index at the highlighted line?


    To answer the second one, move your mouse over the word "Index" and the value should show

    Spoo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width