Results 1 to 16 of 16

Thread: Help With Error: Subscript out of range

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2019
    Posts
    25

    Help With Error: Subscript out of range

    Hi,
    I'm no expert with VB, I've just done the odd simple program from time to time.

    I have a program that's been given to me by its author, which he created some time ago, that has developed a problem.
    It used to function OK, but now when the application is run:

    The program starts it process, but then stops with this popup error message:
    Error : 9
    Description : Subscript out of range
    LineNumber : 7250


    I get the same message when I RUN the program via the VB Project Window.
    This popup is not the standard grey VB popup error message,
    but a bespoke error-handler, so when the error occurs, the Project Window doesn't hi-lite the part of the code that is causing the problem.

    So my initial queries are:
    Q1: In a previously working app, what kinds of problems can cause the above error?
    Q2: How can I get the suspect code to be hi-lited in the the Project Window?
    Q3: Any suggestions how to proceed with this type of problem.

    Many thanks.

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Help With Error: Subscript out of range

    The error message is giving you a line number so your first step should be to go to that line and see what the code is doing there.

    The error message is common and basically means that your code is trying to access an array element that does not exist.

    As for getting it highlighted you can try going into your options and set it to Break on All Errors.

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Help With Error: Subscript out of range

    is this vb6? i have never seen a line number with that error
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4
    Addicted Member Wolfgang Enzinger's Avatar
    Join Date
    Apr 2014
    Location
    Munich, Germany
    Posts
    160

    Re: Help With Error: Subscript out of range

    Quote Originally Posted by westconn1 View Post
    is this vb6? i have never seen a line number with that error
    My guess is that it is indeed VB6, with a custom error handler in action.

    @macmacmac: right-cklick into the code window of the IDE, click "Toggle" and then "Break on All Errors". Then run the project.

    This should answer your Q2. Answers to Q1 and Q3 depend on the situation which will be clearer as soon as the breakpoint is reached.

    Wolfgang

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Help With Error: Subscript out of range

    Quote Originally Posted by westconn1 View Post
    is this vb6? i have never seen a line number with that error
    It is returned by ERL but only if the code actually has line numbers.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Help With Error: Subscript out of range

    It is returned by ERL but only if the code actually has line numbers.
    i realized that, but if someone has a error handler that can return line numbers etc i would have thought this thread would have been redundant, hence my question

    @ OP
    while it is easy to know what will cause the problem (accessing and array or collection outside of its boundries), and it should not be difficult to pinpoint the line where the error occurs, fixing the problem is is totally dependent on what the code is (or should be) doing at that point and nothing in this thread gives any indication of what the code does at all
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Apr 2019
    Posts
    25

    Re: Help With Error: Subscript out of range

    Quote Originally Posted by Wolfgang Enzinger View Post
    ...@macmacmac: right-cklick into the code window of the IDE, click "Toggle" and then "Break on All Errors". Then run the project...
    Wolfgang
    Many thanks, yes that worked OK.

    I have another question but not sure if this should be in a new post...

    I have several VB books, some with downloadable example code.
    Most use the Visual-Basic-Project file with the extension of: test.vbp
    Which runs OK in my IDE.

    But one has this extension: test.vbproj
    Which doesn't seem to run correctly in my IDE, as it only displays that file.

    So why the two different extensions ?

    Many thanks

  8. #8
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: Help With Error: Subscript out of range

    Quote Originally Posted by macmacmac View Post
    Many thanks, yes that worked OK.

    I have another question but not sure if this should be in a new post...

    I have several VB books, some with downloadable example code.
    Most use the Visual-Basic-Project file with the extension of: test.vbp
    Which runs OK in my IDE.

    But one has this extension: test.vbproj
    Which doesn't seem to run correctly in my IDE, as it only displays that file.

    So why the two different extensions ?

    Many thanks
    vbproj is the extension for a VB.Net project rather than a VB6 project.

  9. #9
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Help With Error: Subscript out of range

    Yes vbproj is a vb.net extension and those files are xml where as VB6 uses vbp files that are just plain text. Older versions used a .mak file

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Apr 2019
    Posts
    25

    Re: Help With Error: Subscript out of range

    Quote Originally Posted by DataMiser View Post
    Yes vbproj is a vb.net extension and those files are xml where as VB6 uses vbp files that are just plain text. Older versions used a .mak file
    Thanks.
    So that's confusing:
    Q1: So why are those vbproj example supplied with a book for VB (eg: not VB Net) ?
    Q2: And will those vbproj examples run with my VB software, or do I have to use VB Net?
    Q3: Will VB Net Software run both the VB-vbp-example & VB-Net-vbproj example ?

    Many thanks

  11. #11
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Help With Error: Subscript out of range

    Quote Originally Posted by macmacmac View Post
    Thanks.
    So that's confusing:
    Q1: So why are those vbproj example supplied with a book for VB (eg: not VB Net) ?
    Q2: And will those vbproj examples run with my VB software, or do I have to use VB Net?
    Q3: Will VB Net Software run both the VB-vbp-example & VB-Net-vbproj example ?

    Many thanks
    1. Since you have given no indication what book it is, we can only speculate. But it is very possible that if this book was written in the early 2000's, there might be a late chapter or appendix that gives a preview of what VB.NET code/projects/stuff looks like, and thus the existence of said files.

    2. No, they will not run with VB 6.0.

    3. No, VB.NET software will not run VB 6.0 projects, with a minor caveat that there used to be an option in earlier versions of VB.NET that would try and convert a VB 6.0 project to VB.NET. It didn't work well, and it hasn't been included in any recent versions of VB.NET for many years (2008?)

  12. #12
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Help With Error: Subscript out of range

    Quote Originally Posted by macmacmac View Post
    Thanks.
    So that's confusing:
    Q1: So why are those vbproj example supplied with a book for VB (eg: not VB Net) ?
    Well if the book is about VB6 or VB5 or was published prior to 2000 then I would not expect to see any VB.Net related projects or code but if the book is newer and just about VB then I would expect it to include VB.Net which covers several versions of VB something like 8 or 9 versions have used the .Net variant versions 5 and 6 and to an extent 4 were like VB6. 3 and prior were different and there was also VBDos. There have been lots of changes in VB over the last 30 years but all of those versions are still VB.

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Apr 2019
    Posts
    25

    Re: Help With Error: Subscript out of range

    Quote Originally Posted by OptionBase1 View Post
    1. Since you have given no indication what book it is, we can only speculate. But it is very possible that if this book was written in the early 2000's, there might be a late chapter or appendix that gives a preview of what VB.NET code/projects/stuff looks like, and thus the existence of said files.

    2. No, they will not run with VB 6.0.

    3. No, VB.NET software will not run VB 6.0 projects, with a minor caveat that there used to be an option in earlier versions of VB.NET that would try and convert a VB 6.0 project to VB.NET. It didn't work well, and it hasn't been included in any recent versions of VB.NET for many years (2008?)
    Quote Originally Posted by DataMiser View Post
    Well if the book is about VB6 or VB5 or was published prior to 2000 then I would not expect to see any VB.Net related projects or code but if the book is newer and just about VB then I would expect it to include VB.Net which covers several versions of VB something like 8 or 9 versions have used the .Net variant versions 5 and 6 and to an extent 4 were like VB6. 3 and prior were different and there was also VBDos. There have been lots of changes in VB over the last 30 years but all of those versions are still VB.
    OK, thanks for the comments, so to clarify:

    My original VB book, that uses the .vbp project-file, is:
    Visual basic in Easy Steps / Pub 1997/2004
    (there are no working example for this book)

    The 2nd book, that uses the .vbproj project-file, all of the way through the book is:
    Visual basic in Easy Steps / 2nd edition / Pub 2008

    See Amazon here, (where you can also check out some of its pages)
    https://www.amazon.com/gp/product/18...SIN=1840783583

    You can download its working examples eg: Projects (7,802 KB)
    from here: https://ineasysteps.com/downloads/
    (just scroll down the page to the 2nd edition)

    Inside the book its says:
    Examples created for VB9 but many of their core language is common to previous versions.
    VB Express edition used throughout this book, but Visual Studio can also be used.

    I think I'm using: Microsoft Visual Studio 6.0
    So I guess I would need Visual Studio 9.0 or later ?

    Many thanks.

  14. #14
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: Help With Error: Subscript out of range

    The .NET versions are called: Visual Studio 2002 .. Visual Studio YYYY

    https://en.wikipedia.org/wiki/Micros...Studio#History

    The .NET versions are not compatible with VB6.

  15. #15
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Help With Error: Subscript out of range

    Quote Originally Posted by macmacmac View Post
    OK, thanks for the comments, so to clarify:

    My original VB book, that uses the .vbp project-file, is:
    Visual basic in Easy Steps / Pub 1997/2004
    (there are no working example for this book)
    That was probably then using VB6 projects...


    The rest... on the other hand were all using VB.NET...
    Quote Originally Posted by macmacmac View Post
    The 2nd book, that uses the .vbproj project-file, all of the way through the book is:
    Visual basic in Easy Steps / 2nd edition / Pub 2008

    See Amazon here, (where you can also check out some of its pages)
    https://www.amazon.com/gp/product/18...SIN=1840783583

    You can download its working examples eg: Projects (7,802 KB)
    from here: https://ineasysteps.com/downloads/
    (just scroll down the page to the 2nd edition)

    Inside the book its says:
    Examples created for VB9 but many of their core language is common to previous versions.
    VB Express edition used throughout this book, but Visual Studio can also be used.

    I think I'm using: Microsoft Visual Studio 6.0
    So I guess I would need Visual Studio 9.0 or later ?

    Many thanks.
    Well... it's not that simple...

    You see... there was VB6... and then there was VB.NET ... between the two there was something of a fundamental break. A shift. A massive shift. A lot of VB6 stuff will still work in .NET, but .NET won't work in VB6.

    So the real quesiton is... do you want ot stick with VB6, or do you want to move on to .NET?

    A lot has changed in the last 12 + years... heck, a lot has changed in the last 5 years.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  16. #16
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Help With Error: Subscript out of range

    Quote Originally Posted by macmacmac View Post
    So I guess I would need Visual Studio 9.0 or later ?

    Many thanks.
    Yes the core code is mostly compatible across versions but the support framework changes and in some cases you can't jump back to an older version because of the framework used.
    Version 9 is VB2008 which is the version I use on this system. It was the last version that included support for Windows CE and Windows Mobile devices and also was the last version that included the VB6 convertor program. I also have the newer versions of course but I keep 2008 around because of Windows CE and Mobile apps I need to support.

    The more recent projects I have done have been in VS2017 using C#

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