-
Feb 26th, 2021, 09:22 AM
#1
Thread Starter
Junior Member
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.
-
Feb 26th, 2021, 05:46 PM
#2
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.
-
Feb 27th, 2021, 05:20 AM
#3
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
-
Feb 27th, 2021, 06:22 AM
#4
Re: Help With Error: Subscript out of range
Originally Posted by westconn1
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
-
Feb 28th, 2021, 01:40 AM
#5
Re: Help With Error: Subscript out of range
Originally Posted by westconn1
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.
-
Feb 28th, 2021, 03:27 AM
#6
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
-
Mar 17th, 2021, 09:11 AM
#7
Thread Starter
Junior Member
Re: Help With Error: Subscript out of range
Originally Posted by Wolfgang Enzinger
...@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
-
Mar 17th, 2021, 12:16 PM
#8
Re: Help With Error: Subscript out of range
Originally Posted by macmacmac
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.
-
Mar 17th, 2021, 01:34 PM
#9
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
-
Mar 17th, 2021, 02:08 PM
#10
Thread Starter
Junior Member
Re: Help With Error: Subscript out of range
Originally Posted by DataMiser
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
-
Mar 17th, 2021, 02:24 PM
#11
Re: Help With Error: Subscript out of range
Originally Posted by macmacmac
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?)
-
Mar 17th, 2021, 11:15 PM
#12
Re: Help With Error: Subscript out of range
Originally Posted by macmacmac
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.
-
Mar 18th, 2021, 09:40 AM
#13
Thread Starter
Junior Member
Re: Help With Error: Subscript out of range
Originally Posted by OptionBase1
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?)
Originally Posted by DataMiser
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.
-
Mar 18th, 2021, 09:44 AM
#14
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.
-
Mar 18th, 2021, 09:57 AM
#15
Re: Help With Error: Subscript out of range
Originally Posted by macmacmac
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...
Originally Posted by macmacmac
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
-
Mar 18th, 2021, 11:39 AM
#16
Re: Help With Error: Subscript out of range
Originally Posted by macmacmac
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|