Author Topic: Learning from the [Errors in the] OxygenBasic demo examples.  (Read 415 times)

0 Members and 1 Guest are viewing this topic.

Offline Roland Stowasser

  • Newbie
  • *
  • Posts: 27
  • User-Rate: +1/-0
Learning from the [Errors in the] OxygenBasic demo examples.
« 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 :-).]
« Last Edit: October 09, 2022, 07:17:56 PM by Theo Gottwald »

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 880
  • User-Rate: +33/-1
    • Charles Pegge
Re: Learning from the [Errors in the] OxygenBasic demo examples.
« Reply #1 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

Offline Roland Stowasser

  • Newbie
  • *
  • Posts: 27
  • User-Rate: +1/-0
Re: Learning from the [Errors in the] OxygenBasic demo examples.
« Reply #2 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?

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 880
  • User-Rate: +33/-1
    • Charles Pegge
Re: Learning from the [Errors in the] OxygenBasic demo examples.
« Reply #3 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?

Offline Roland Stowasser

  • Newbie
  • *
  • Posts: 27
  • User-Rate: +1/-0
Re: Learning from the [Errors in the] OxygenBasic demo examples.
« Reply #4 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:

Code: [Select]
...
  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.

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 880
  • User-Rate: +33/-1
    • Charles Pegge
Re: Learning from the [Errors in the] OxygenBasic demo examples.
« Reply #5 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:

Code: [Select]
      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" 
« Last Edit: January 06, 2023, 11:13:06 AM by Charles Pegge »

Offline Roland Stowasser

  • Newbie
  • *
  • Posts: 27
  • User-Rate: +1/-0
Re: Learning from the [Errors in the] OxygenBasic demo examples.
« Reply #6 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.

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 880
  • User-Rate: +33/-1
    • Charles Pegge
Re: Learning from the [Errors in the] OxygenBasic demo examples.
« Reply #7 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.

Offline Roland Stowasser

  • Newbie
  • *
  • Posts: 27
  • User-Rate: +1/-0
Re: Learning from the [Errors in the] OxygenBasic demo examples.
« Reply #8 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?
« Last Edit: January 14, 2023, 11:09:37 AM by Roland Stowasser »

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 880
  • User-Rate: +33/-1
    • Charles Pegge
Re: Learning from the [Errors in the] OxygenBasic demo examples.
« Reply #9 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:
Code: [Select]
'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
« Last Edit: January 14, 2023, 12:37:05 PM by Charles Pegge »