• Welcome to Jose's Read Only Forum 2023.
 

Learning from the [Errors in the] OxygenBasic demo examples.

Started by Roland Stowasser, October 09, 2022, 12:37:01 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Roland Stowasser

Hi Charles,

Since I have to reorient myself a bit in OxygenBasic, I let the apps run in Demos/Basics. Unfortunately four programs showed an error message:

iteration.o2bas:
ERROR:   not found
WORD:    }
COL:    3
LINE:    43

linenumbers1.o2bas:
ERROR:   not found
WORD:    a
COL:    7
LINE:    9

linenumbers2.o2bas:
ERROR:   not found
WORD:    a
COL:    7
LINE:    9

subroutine.o2bas:
ERROR:   unclosed brackets at end of script (1)
LINE:    29

I assume these reports are side effects of the recent changes at O2?

[TG: Added something to Headline to get more attention for the topic :-).]

Charles Pegge

Many thanks Roland,

I've updated 050P11.
https://github.com/Charles-Pegge/OxygenBasic/blob/master/OxygenBasic050P11.zip

The most serious problem disabled autodim variable creation in the linenumbers examples

Roland Stowasser

Hi Charles,

there is \demo\WinDynDialogs\Pgbar3d.o2bas which doesn't work properly anymore. It worked once with version 04/2020. The error occurs in Pgbar3d.inc, line 169 of the CreatePGBar3D function. I'm not sure what has changed in the meantime. Do I need to use stricter argument handling in CreateWindowEx?

Charles Pegge

Hi Roland,

pgbar3D3 works, but pgBar3D does not. What are the differences which might cause the CreatePGBar3D function to fail?

Roland Stowasser

Hi Charles,

if I modify Pgbar3d.inc and add in function CreatePGBar3D starting at about line 162 int x,y,w,h then Pgbar3d.o2bas works:


...
  if DlgUnits then
      RECT rc = {0, 0, 4, 8}
      MapDialogRect (hParent, @rc)
      float PixelX = rc.right/4
      float pixelY = rc.bottom/8
      int x = vLeft*PixelX
      int y = vTop*PixelY)
      int w = vWidth*PixelX
      int h = vHeight*PixelY
      'create control using dialog units
      hBar = CreateWindowEx(wStyleEx, "PGBAR3D",  null, wStyle,
                           'int(vLeft*PixelX), int(vTop*PixelY), int(vWidth*PixelX), int(vHeight*PixelY),
                           x,y,w,h,
                           hParent, id, GetWindowLongPtr(hParent, GWL_HINSTANCE),  null)
      if hBar = 0 then mbox "Error 1: CreateWindowEx PGBAR3D failed" 
   else
      'create control using pixels
      hBar = CreateWindowEx(wStyleEx, "PGBAR3D",  null, wStyle,
                           vLeft, vTop, vWidth, vHeight,
                           hParent, id, GetWindowLongPtr(hParent, GWL_HINSTANCE),  null)
      if hBar = 0 then mbox "Error 2: CreateWindowEx PGBAR3D failed"
   end if
   
   if hBar and len(txt) then SetWindowText(hBar, txt)
   function = hBar
end function
...


This is what I mean with stricter handling of arguments. Or is there another way with casting? E.g. int(vLeft*PixelX) does not work anymore.

Charles Pegge

#5
Yes,

Because CreateWindowEx is unprototyped, the param type is decided by the type of the expression used.

In this case the 4 expressions result in floats, even though the int function is used.  This is resolved by explicitly converting to int:


      hBar = CreateWindowEx(wStyleEx, "PGBAR3D",  null, wStyle,
                           convert int vLeft*PixelX,
                           convert int vTop*PixelY,
                           convert int vWidth*PixelX,
                           convert int vHeight*PixelY,
                           hParent, id, GetWindowLongPtr(hParent, GWL_HINSTANCE),  null)
      if hBar = 0 then mbox "Error: CreateWindowEx PGBAR3D failed" 

Roland Stowasser

Thank you Charles. Perhaps there are some more examples which will need convert. Reading the Help file I assume cast is used for changing temporarily the type of a variable, convert is used for the type of an expression.

Charles Pegge

Thanks Roland,

Yes, I draw a distinction between cast and conversion. Many type conversions are performed automatically  in BASIC to make coding easier, especially between float and integer types.

Roland Stowasser

#8
Hi Charles,

there is an error message in demos\RosettaCode\Arrays.o2bas. If I modify the first 2 lines to:
'CREATING A DYNAMIC ARRAY
redim float f[100]

then everything works as expected. I assume you have changed the rule to use an array either static or dynamic but not both at the same time?

Charles Pegge

#9
Thanks Roland,

Yes, a dimmed and a redimmed array should not share the same name., in the current version of o2.

corrected Arrays example:

'CREATING A STATIC ARRAY
float f[100]

'SETTING INDEX BASE
indexbase 1 'default

'FILLING PART OF AN ARRAY
f[20]={2,4,6,8,10,12}

'MAPPING AN ARRAY TO ANOTHER
float *g
@g=@f[20]
print g[6] 'result 12

'DYNAMIC (RESIZEABLE) ARRAYS
redim float fd(100)
fd={2,4,6,8}               'assign some values
redim float fd(200)        'expand array
print fd(2)                'original values are preserved by default
redim float fd(200) clear  'array elements are cleared
print fd(2)                'value set to 0.0
redim float fd(0)          'release allocated memory          '



I am waiting for an account  confirmation code before submitting this correction to Rosettacode