Recent Posts

Pages: [1] 2 3 ... 10
1
Bugs & Feature Requests / Re: Removal of C-style Ternary
« Last post by John on September 18, 2020, 03:33:37 PM »
Are macros like user defined syntax extensions?

SB has a COMMAND extension module type beyond functions. It isn't very well documented so I haven't used it much. An IIF() example exists in Peter's trial extension module.
2
Bugs & Feature Requests / Re: Removal of C-style Ternary
« Last post by Nicola on September 18, 2020, 02:53:36 PM »
Ok Charles.
For me it is clearer in this way, using variables with different names, because I can better identify which are the variable parameters and which are part of the macro and which depend on the values ​​passed through the call of the macro itself. In our case iif ...
Still, a really good thing. Good job.

Code: OxygenBasic
  1. use console
  2. cls
  3.  
  4. 'macro iif int(r, a ,b, c)
  5. macro iif int(r, x ,y, z)
  6.   if x
  7.     r=y
  8.   else
  9.     r=z
  10.   endif
  11. end macro
  12.  
  13. '==main==========
  14. int a=5, b=6, c=7, d=9
  15.  
  16. int t=iif(a>b , c, d)
  17. print t
  18. wait

In this case, rightly so, the result is 9.
3
Development / O2 Documentation
« Last post by John on September 18, 2020, 12:56:01 PM »
Is there anyone here on the forum that may have some spare time to pickup where Jose Roca left off with the docs?

Simply download the existing markdown text files as your base and once your done with your corrections and additions post them as an attachment to this thread for Charles and other forum members to review.

You don't have to own the project, treat it like contributing to a wiki.
4
Bugs & Feature Requests / Re: Is this a bug?
« Last post by John on September 16, 2020, 06:41:00 AM »
I tend to use grid controls for formatted columns of data in a GUI environment using the controls alignment properties to do the work.
5
Bugs & Feature Requests / Re: Is this a bug?
« Last post by Charles Pegge on September 16, 2020, 04:21:22 AM »
Yes Nicola,

But with GUI edit boxes showing aligned data, you will need to set a monospaced typeface like "Courier" or "Lucida Console"

Code: [Select]
...
  function SetFont(sys *hwnd,n,height,width,weight,string fontname) as sys
  ========================================================================
  indexbase 1
  sys hFont,i
  hfont=CreateFont( height,width,0,0,weight,0,0,0,0,0,0,0,0,fontname)
  int i
  for i=1 to n
    SendMessage hwnd(i),WM_SETFONT,hfont,0
  next
  return hFont
  end function
...

    hFont=SetFont(hchw[1],6,13,9,400,"Lucida console")

6
Bugs & Feature Requests / Re: Is this a bug?
« Last post by John on September 16, 2020, 03:06:21 AM »
sprintf is generating a formatted string that can be used in any UI environment.
7
Bugs & Feature Requests / Re: Is this a bug?
« Last post by Nicola on September 16, 2020, 02:46:41 AM »
@Charles
 Reply #58

Great!
Is this good for both console and gui edit-text?
8
Bugs & Feature Requests / Re: Is this a bug?
« Last post by John on September 15, 2020, 03:38:54 AM »
That's close enough for me. I do use the custom SB number formatting string a lot as well. It looks like it wouldn't be too hard to create a O2 FORMAT function using sprintf and a bit of extra code to handle the numeric formatting.

Code: Script BASIC
  1. PRINT FORMAT("Line Number: %~0000~ Square root of 5 is %.3f\n", 25, SQR(5))


C:\ScriptBASIC\examples>sbc format.sb
Line Number: 0025 Square root of 5 is 2.236

C:\ScriptBASIC\examples>



The FORMAT function is in string.c SB source.
9
Bugs & Feature Requests / Re: Is this a bug?
« Last post by Charles Pegge on September 15, 2020, 01:53:02 AM »
Hi John,

I see that SB Format is based on sprintf.

This is a useful reference:

http://www.cplusplus.com/reference/cstdio/printf/

Variadics are supported for all msvcrt functions that use them.

Example:
Code: [Select]
uses corewin
uses console
char buf[100]
double d=pi()
char buf[100]
double d=pi()

'sprintf_s(buf,100,"floats: %4.2f %+.0e %E " cr, d, d, d)
'sprintf(buf, "floats: %4.2f %+.0e %E " cr, d, d, d)

   sprintf (buf, "Characters: %c %c ", asc("a"), 65)
   print buf cr
   sprintf (buf, "Decimals: %d %ld", 1977, 650000L)
   print buf cr
   sprintf (buf, "Preceding with blanks: %10d ", 1977)
   print buf cr
   sprintf (buf, "Preceding with zeros: %010d ", 1977)
   print buf cr
   sprintf (buf, "Some different radices: %d %x %o %#x %#o ", 100, 100, 100, 100, 100)
   print buf cr
   sprintf (buf, "floats: %4.2f %+.0e %E", double 3.1416, double 3.1416, double 3.1416)
   print buf cr
   sprintf (buf, "Width trick: %*d", 5, 10)
   print buf cr
   sprintf (buf, "%s", "A string")
   print buf cr
   print cr
wait
10
Bugs & Feature Requests / Re: Is this a bug?
« Last post by John on September 14, 2020, 04:48:26 PM »
Charles,

It might be worth translating ScriptBasic's PRINT FORMAT function from C to O2. A function I couldn't live without.

FORMAT

Not sure how O2 would deal with a varidic like argument passing.
Pages: [1] 2 3 ... 10