The upper bound of the for loop

For i% = 0 To 32767 crashes. The program stops with an error ar the Next statement.
For i% = 0 to 32766 is OK.
This malfunction surprises those wishing to use the full range of long.
Can it be corrected?

I have corrected my post. Thank you.

"Inadmissible value or data type. Overflow."?
Don’t use variables of type Integer. Use instead type Long.

No way! The lower bound is missing.

And: the old Basic standard of typing variables by a one-character-suffix is outdated, imo, and should be abandoned. (Alas, there are the file handles.).
Dim i As Long is what you need.
LibO Basic has integer types Byte, Integer, Long.
Dim i% is “shorthand” for Dim i As Integer. The range then is
-32768(=-2^15) .. 32767(=2^15 - 1).
Range for Long is -2147483648(-2^31) .. 2147483647(=2^31 - 1)
That you can’t use 32767 as the upper bound of an Integer For-Next loop is due to the way LibO Basic handles such Loops (badly): The Next i% used after the statements for i% = 32767 woud first try to increment i% wich causes the error.

The one step after the last is always executed and the for…next loop is finished when the upper limit is exceeded.

for i = 1 to 32766
   if some_condition() = True then exit for
next
if i = 32767 then
   Msgbox "Condition not met"
else
  Msgbox "Condition met at step "& i
endif

Run this in step mode:

for i = 1 to 2
next i

At the end (next i) of the first cycle i is 1, then 2 and then it goes back to the for line, counts up to 3 and exits the loop.

A (prinitive but clear) way to loop through the full Range of type Integer is demonstrated by

Sub Main
i% = - 32768
loopNext:
  If (i% Mod 1000)=0 Then MsgBox(i%) REM Just an example statement!
  If i%>=32767 Then Goto afterLoop
  i% = i% + 1
Goto loopNext
afterLoop:
msgBox(i%)
End Sub