Extract integer from text in Base

I am using a macro to format text in a base document and have come across a strange occurrance using
Version: 6.4.7.2
Build ID: 1:6.4.7-0ubuntu0.20.04.1
The intent is to format a number of 4 digit length with trailing text that might also include numbers. The critical part is the first four characters. If they are numbers less than 100 I add leading zeros. So far, so good. If the number is greater than 1000, then no processing need be done, also if there is an alpha-numeric the first four characters need to be numeric unless the field starts with an alpha character, the code works for all of the above UNTIL I enter a number greater than 32767 when I get an

Inadmissible data type
Overflow

message. I extract data from a field using the following code
iSG is set as Integer and fails when I attempt to store sSG value in it (a String) - as I said, it works up to 32767 , I can even enter 32767fsdfwrgghtrhth and it works, but any number above this value falls over

Sub fmtSG
Dim lSG, vSG , oForm, tSG, leftSG
Dim sSG$ , iSG as integer, SGno, z,SGlen, p, j, counter

 	oForm = ThisComponent.DrawPage.Forms.getByIndex(0)    ' Main Form

’ oSubForm = oForm.GetByName(“FRM_STAMPS”) ’ SubForm Name
lSG = oForm.findColumn(“SM_SG_REF”) ’ determine location of field
sSG = oForm.getString(lSG) ’ get data from field
SGlen=len(sSG) ’ determine length of the data
iSG = sSG ’ extract numeric info from field

Am I missing something or should I use another method to extract the numbers from the leading edge of the string?

[quote=“LSemmens, post:1, topic:70750”] the code works for all of the above UNTIL I enter a number greater than 32767 when I get an
[/quote]
Column type SMALLINT is 2 bytes long. It is limited to values between -32768 and +32767. Change it to INT (4 bytes) or even BIGINT (8 bytes).

Note:
There is a difference between database and Basic.
HSQLDB: Integer will be 4 byte ( - 2147483648 to + 2147483647)
Basic: Integer will be 2 byte ( - 32768 to + 32767)
You have to set LONG in Basic for getting all values of INTEGER in HSQLDB.

Why Basic anyway? Why do people waste so much time with it when all they need is a working database?

Thanks Villeroy, I thought it might have been something like that.