Jose's Read Only Forum 2023

IT-Consultant: Charles Pegge => OxygenBasic => Topic started by: Roland Stowasser on October 09, 2022, 12:37:01 PM

Title: Learning from the [Errors in the] OxygenBasic demo examples.
Post by: Roland Stowasser on October 09, 2022, 12:37:01 PM
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 :-).]
Title: Re: Learning from the [Errors in the] OxygenBasic demo examples.
Post by: Charles Pegge on October 09, 2022, 07:55:05 PM
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
Title: Re: Learning from the [Errors in the] OxygenBasic demo examples.
Post by: Roland Stowasser on January 05, 2023, 11:51:12 PM
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?
Title: Re: Learning from the [Errors in the] OxygenBasic demo examples.
Post by: Charles Pegge on January 06, 2023, 09:35:06 AM
Hi Roland,

pgbar3D3 works, but pgBar3D does not. What are the differences which might cause the CreatePGBar3D function to fail?
Title: Re: Learning from the [Errors in the] OxygenBasic demo examples.
Post by: Roland Stowasser on January 06, 2023, 10:21:41 AM
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.
Title: Re: Learning from the [Errors in the] OxygenBasic demo examples.
Post by: Charles Pegge on January 06, 2023, 11:10:26 AM
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" 
Title: Re: Learning from the [Errors in the] OxygenBasic demo examples.
Post by: Roland Stowasser on January 06, 2023, 12:13:39 PM
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.
Title: Re: Learning from the [Errors in the] OxygenBasic demo examples.
Post by: Charles Pegge on January 06, 2023, 12:25:43 PM
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.
Title: Re: Learning from the [Errors in the] OxygenBasic demo examples.
Post by: Roland Stowasser on January 14, 2023, 11:05:39 AM
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?
Title: Re: Learning from the [Errors in the] OxygenBasic demo examples.
Post by: Charles Pegge on January 14, 2023, 12:25:57 PM
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