IDE - just a thought on Next and Out of Subscript
#1
Would be helpful and not too onerous to have NEXT include the control variable to which it is attached? For example

For x = 1 to 50
 For y = 2 to 75
 .... code here..
 NEXT y
NEXT x

Sometimes the control variable provides important info on data being manipulated in the loop and the manipulation can be complex and nested deeply so that the NEXT statements come on  multiple pages of code.
 
For Temperature = 90 to 190 
  ... code here...

   For Windspeed = 20 to 150
      >>> code here <<<
   Next Windspeed

.... more code 

Next Temperature

Also, I'm not sure if the Error Warning which for me pops up a lot, and invariably is telling me the Subscript on Line 10250 is out of range. Would it be possible to have a feature where pushing enter or some such key will take me directly to the offending line?
Reply
#2
On Error might catch your subscript error and you could message box the index values then?

When subscript out of range: #1 cause for me is that I am using index twice (two different ways) usually an i variable, specially likely in huge amount of code.

Code: (Select All)
On Error GoTo ehandle
Dim a(1 To 15)
For i = 1 To 20
    a(i) = i ' error at i = 16
Next
End

ehandle:
Print i
Print "Error: "; Err
End

I got error code 9 a general error code?

I try and look up Error codes in Wiki and no numbers = error descriptions are listed under Error codes.
b = b + ...
Reply
#3
b ..That's a great routine to id the error and line. I have used it in the past, and to it, wouldn't it be nice if the "Possible Causes" came with it? For me it's actually getting to the offending line. At the bottom of the IDE, often I just need to click on the STATUS description and it takes me right where I need to go and when your code is multi lines it's very helpful. There is an option under Search to go to a line, which is what I use, so I'm pretty well spoiled with the IDE the way it is and I put up this post in frustration from this mornings coding session as I changed the wrong For Next code, and if that wasn't bad enough, to fix the out of range script I had to find the actual line that was trigging the damn array being out of range in the first place. Lots of time waisted. There is a disconnect between the speed of my brain and the speed at which my fingers can type errors that my brain can't catch.
Reply
#4
Quote:I got error code 9 a general error code?

This is the standard error message when the index range is exceeded: 9 -> Subscript out of range
Code: (Select All)
Option _Explicit
Option Base 1

Dim As Integer feld(15), i, fehlerNummer

For i = 1 To 16
  feld(i) = i * 2
  Print feld(i)
  If fehlerNummer = 9 Then
    GoTo Fehler
  End If
Next

Fehler:
Locate CsrLin + 2, 3
Beep: Print "Feldindex wird ueberschritten!"

End

[Image: Ausserhal-des-Index2023-05-14.jpg]
Reply
#5
Hi Dimster,

As KernelPanic has shown, the regular Subscript error shows the line number at fault but I added it to our little error handler code because there is the codeword _ErrorLine
Code: (Select All)
On Error GoTo ehandle
Dim a(1 To 15)
For i = 1 To 20
    a(i) = i ' error at i = 16
Next
End

ehandle:
Print "Index i is"; i
Print "Error line "; _ErrorLine
Print "Error: "; Err
End

Yeah also your error could occur way up the line of code and not effect anything until the rubber meets the road like a subscript error. IDE would have to be pretty darn smart to say, "Hey dude, that's a typo or the wrong variable on line xxx, you should fix it before you get a subscript out of range error on line yyy."

PS If it can distinguish you as a dude as opposed to dudette then... well I don't know what then ;-))
b = b + ...
Reply
#6
@Dimster Remember, when you run the EXE, you're running the compiled program which executes independent of the IDE.  A subscript error only happens at run time, and there's no real way for the IDE to interact with your program itself at that point.  The easiest solution in this case is simply to write down or remember the line number and then CTRL-G and type in that number to instantly go to that line.  (Or use the main menu and Search>Goto Line #...)
Reply
#7
(05-14-2023, 05:40 PM)bplus Wrote: Hi Dimster,

As KernelPanic has shown, the regular Subscript error shows the line number at fault but I added it to our little error handler code because there is the codeword _ErrorLine
Code: (Select All)
On Error GoTo ehandle
Dim a(1 To 15)
For i = 1 To 20
    a(i) = i ' error at i = 16
Next
End

ehandle:
Print "Index i is"; i
Print "Error line "; _ErrorLine
Print "Error: "; Err
End

Yeah also your error could occur way up the line of code and not effect anything until the rubber meets the road like a subscript error. IDE would have to be pretty darn smart to say, "Hey dude, that's a typo or the wrong variable on line xxx, you should fix it before you get a subscript out of range error on line yyy."

Even then, the IDE can't catch a runtime error.  For example, have the IDE tell you what's wrong with the  following:

DIM foo(100)
INPUT "Which foo do you want?"; query
PRINT foo(query)

Now, enter -1 as an user input.  Or 102.  Or 3.6...  Or "football"...

How's the IDE going to tell you the code is wrong, when there's technically nothing invalid to it?  It's only at runtime where the user can enter an invalid response that the program glitches.
Reply
#8
I don't know works pretty good for foo too


Attached Files Image(s)
   
b = b + ...
Reply
#9
Quote:Remember, when you run the EXE, you're running the compiled program which executes independent of the IDE.  A subscript error only happens at run time, and there's no real way for the IDE to interact with your program itself at that point.  The easiest solution in this case is simply to write down or remember the line number and then CTRL-G and type in that number to instantly go to that line.  (Or use the main menu and Search>Goto Line #...)


Hi Steve - So the EXE is running and picks up an out of range error. The program stops running and you get a choice of Continuing or not. The line number is already identified. If I chose Continue, I'm assuming the program starts running again after the line the EXE has just informed me where the error is. Why is it, if I chose NOT to continue, the cursor not on or near the line which caused the error.
Reply
#10
I'm not sure now but in the early days of QB64 when the IDE was opened it also opened "stdin", "stdout" and "stderr" files on Windows. This caused a problem with EXE files created by the program system that were burned to CD or DVD. However it might have written a runtime error message to "stderr". This was so it was picked up by a program like Geany or Notepad++ which was able to navigate to the line that caused the error. But that's for using an editor independent from QB64, and not the QB64 IDE.

LOL at pressing [ENTER] on the "MessageBox" of Windows. QuickBASIC/QBasic didn't show a dialog box when it wanted to complain about a runtime error, it simply stopped grinding, dumping an error message into the terminal. It wrote it into the graphics screen if it had to. Also it wasn't possible to "continue" running code although in QB64 in 99% of the cases it's useless or risky.

While using the Programmer's Workbench on BASIC PDS v7.1 and the program was compiled in debug mode, it was able to react to a runtime error by showing in the editor where it occurred. But this made the whole thing even slower than it already was, especially on any crappy disk made by Seagate such as what I was unfortunate enough to own.

Purebasic, something else that is payware could do the same thing. It even has a debugger independent from the Scintilla-based IDE, and a remote debugger that is less intuitive to use. I'm speaking about v4 primarily since I haven't used this product in years.

I'm saying that because QB64 would have to do the same thing. It might need a special version of the IDE to compile the user's program in a "detailed" debug mode. Then when the user's program is run and there is a runtime error, open that IDE to navigate to the line that triggered the problem. As Steve said, it's more like "LOL we're telling you where it is, just go find it and figure it out and fix it."
Reply




Users browsing this thread: 11 Guest(s)