Author Topic: Strange Error Message, need help  (Read 6005 times)

0 Members and 1 Guest are viewing this topic.

kryton9

  • Guest
Strange Error Message, need help
« on: October 30, 2011, 01:30:32 AM »
Charles, I am getting a strange error.
Please unzip the file into the projects folder in OxygenBasic. It will put a folder named error with the files in it. This way the include files should all path properly.
OxygenBasic
      Projects   - extract the zip to this folder to get the error folder as shown
            Error

The file to look at is "test GLWindow.bas" . You can compile and run this as it is.
To see the error. Uncomment:
line 14 'include once "Helpers.inc"
line 67 '            win.Print 0.1 * Win.GetWidth, ....

Thanks.
« Last Edit: October 30, 2011, 01:35:54 AM by kryton9 »

Charles Pegge

  • Guest
Re: Strange Error Message, need help
« Reply #1 on: October 30, 2011, 03:07:42 AM »

Hi Kent,

Last line of helpers.inc

the Basic syntax does not support Void as a return type


declare sub Sleep lib "kernel32.dll" ( byval dwMilliseconds as DWORD )

declare function Sleep lib "kernel32.dll" ( byval dwMilliseconds as DWORD ) as void


MinWin has Sleep defined already in low level form, if you prefer.

Charles

Charles Pegge

  • Guest
Re: Strange Error Message, need help
« Reply #2 on: October 30, 2011, 05:11:32 AM »

Future releases will tolerate the void return type, converting the function into a sub.

In fact, such a function will return whatever value happens to be in the eax register on returning.

Code: OxygenBasic
  1.  
  2. declare function f() as void
  3.  
  4. function f() as void
  5. mov eax,42
  6. end function
  7.  
  8. print f 'result 42
  9.  

Charles


kryton9

  • Guest
Re: Strange Error Message, need help
« Reply #3 on: October 30, 2011, 01:27:46 PM »
Thanks Charles, I just couldn't see what the problem was. It never occurred to me that a function returning void is really just a sub. Easier to take it out as you showed. Thanks again!

kryton9

  • Guest
Now confused on what is happening here.
« Reply #4 on: October 30, 2011, 02:41:00 PM »
My fmt function wasn't working as I was specifying sys as shown below. When I don't specify a type the function works.
What type does trunc and frac return? Thanks for clarification in advance.
Code: OxygenBasic
  1. function fmt( double d, sys s ) as string
  2.     l = trunc( d )
  3.     r = frac( d )
  4.     string r2 = str(r)
  5.     if s = 0 then return ( str(l) )
  6.     return ( str(l)  + "." + mid( r2, 3, s ) )
  7. end function
  8.  
  9. function fmt2( double d, sys s ) as string
  10.     sys l = trunc( d )
  11.     sys r = frac( d )
  12.     string r2 = str(r)
  13.     if s = 0 then return ( str(l) )
  14.     return ( str(l)  + "." + mid( r2, 3, s ) )
  15. end function
  16.  
  17. print fmt(59.9876543210,0)
  18. print fmt(59.9876543210,1)
  19. print fmt(59.9876543210,2)
  20. print fmt(59.9876543210,3)
  21. print fmt(59.9876543210,4)
  22. print fmt(59.9876543210,5)
  23.  
  24. print fmt2(59.9876543210,0)
  25. print fmt2(59.9876543210,1)
  26. print fmt2(59.9876543210,2)
  27. print fmt2(59.9876543210,3)
  28. print fmt2(59.9876543210,4)
  29. print fmt2(59.9876543210,5)

Peter

  • Guest
Re: Strange Error Message, need help
« Reply #5 on: October 30, 2011, 02:59:46 PM »
Hi Kent,

Code: [Select]
function fmt( double d, sys s ) as string 
    l = trunc d   
    r = frac  d   
    string r2 = str(r) 
    if s = 0 then return str(l)   
    return  str(l)  + "." + mid( r2, 3, s )   
end function 
 
function fmt2( double d, sys s ) as string 
    double l = trunc d   
    double r = frac  d   
    string r2 = str(r) 
    if s = 0 then return str(l)   
    return str(l)  + "." + mid( r2, 3, s )   
end function 
 
print fmt(59.9876543210,0) 
print fmt(59.9876543210,1) 
print fmt(59.9876543210,2) 
print fmt(59.9876543210,3) 
print fmt(59.9876543210,4) 
print fmt(59.9876543210,5) 

print "okay"

print fmt2(59.9876543210,0) 
print fmt2(59.9876543210,1) 
print fmt2(59.9876543210,2) 
print fmt2(59.9876543210,3) 
print fmt2(59.9876543210,4) 
print fmt2(59.9876543210,5) 

print "okay"

Charles Pegge

  • Guest
Re: Strange Error Message, need help
« Reply #6 on: October 30, 2011, 03:46:08 PM »
Hi Kent,

Trunc chops off the fractional part of a number, leaving an integer.

Frac chops off the integer part, leaving the fractional part.

Round adjusts a number up or down to the nearest integer.

Charles

kryton9

  • Guest
Re: Strange Error Message, need help
« Reply #7 on: October 30, 2011, 06:55:54 PM »
Peter put a double and it worked, but sys doesn't and yet trunc and frac return ints? So confusing to figure out for me why one works and the other doesn't.

Here is another confusing matter that needs to be resolved hopefully.
Code: OxygenBasic
  1. 'using 1 for true and -2 for false works,
  2. 'but it should be 0 for false
  3. def true 1
  4. def false -2 'make this 0, and it doesn't work correctly
  5.             'as in other languages
  6.             'we need bool variables true 1, false 0
  7.             'so b = not(b) type code can be written
  8.  
  9. sys b = true
  10. string crlf = chr( 13 ) + chr( 10 )
  11. string s = "b starts as true" crlf
  12. for x = 0 to 5
  13.     s += "x: " str(x) "  b: " str(b) crlf
  14.     b = not(b)
  15.     s+= "x: " str(x) "  not b: " str(b) crlf
  16. next x
  17.  
  18. print s
  19.  
  20.  
  21. sys b = false
  22. string s = "b starts as false" crlf
  23. for x = 0 to 5
  24.     s += "x: " str(x) "  b: " str(b) crlf
  25.     b = not(b)
  26.     s+= "x: " str(x) "  not b: " str(b) crlf
  27. next x
  28.  
  29. print s
« Last Edit: October 30, 2011, 07:14:19 PM by kryton9 »

Charles Pegge

  • Guest
Re: Strange Error Message, need help
« Reply #8 on: October 31, 2011, 12:46:41 AM »
Sys is a signed integer (32/64 bits depending on the CPU and operating system).

So it will always return a frac of 0


The not function returns the bit inversion of a number. It is not a boolean function.

Examples

print  hext not(0)  ' ffffffff
print  hex not(1)  ' fffffffe

print not(0)  '  -1
print not(-1)  '  0

print not(5)  '  -6



to obtain a boolean not():

print not(0) and 1  '  1
print not(1) and 1  '  0
print not(5) and 1  '  0
print not(-5) and 1  '  0


Charles
« Last Edit: October 31, 2011, 01:06:35 AM by Charles Pegge »

kryton9

  • Guest
Re: Strange Error Message, need help
« Reply #9 on: October 31, 2011, 01:06:06 AM »
Ahhh, a bit inversion... will we have booleans and be able to use '!' as an operator?

This gives errors.
Code: OxygenBasic
  1. bool b = true
  2.  
  3. b = !b
  4.  
  5. print b

Charles Pegge

  • Guest
Re: Strange Error Message, need help
« Reply #10 on: October 31, 2011, 01:12:33 AM »

Oxygen only supports the != comparator (equvalent to <> in basic)

a=1
b=a+1
if a !=b then print 5



Charles Pegge

  • Guest
Re: Strange Error Message, need help
« Reply #11 on: October 31, 2011, 01:23:15 AM »
There is a circumstance when not has a boolean meaning.

When not immediately follows an if elseif or while

It even works on strings:

string er=error()

if not er then print "no errors found"

kryton9

  • Guest
Re: Strange Error Message, need help
« Reply #12 on: October 31, 2011, 02:42:46 AM »
Amazing how you keep all of this straight in your head Charles and made the code work to begin with. Thanks for the explanations. All very neat!

Charles Pegge

  • Guest
Re: Strange Error Message, need help
« Reply #13 on: October 31, 2011, 02:57:41 AM »
I'm doing some work on number format control. There are some parameters which directly affect the str function. Setting these parameters is the most efficient way to format numbers, so I will make them available for programming.


Meanwhile this is how you can format numbers with a Basic function

Code: OxygenBasic
  1. function DeciPlaces(double n, sys p) as string
  2. '=============================================
  3.  string s,t
  4.   sys a,le,q
  5.   s=round(n*10^p)
  6.   a=instr(s,"E") 'itr convert to plain number
  7.  if p=0 then return s
  8.   le=instr(s,".")
  9.   if le=0 then le=1+len s
  10.   le--
  11.   s=left s,le
  12.   a=asc s
  13.   if a<>45 then t=" "
  14.   if le<=p then s+=string(p-le+1,"0") : le+=p
  15.   return t+left(s,le-p)+"."+mid(s,-p)
  16. end function
  17.  
  18. print deciplaces 0,0
  19. print deciplaces 0,1
  20. print deciplaces 0,3
  21. print deciplaces 3.456789,3
  22. print deciplaces -3.456789,3
  23. print deciplaces 123,25
  24.  
  25.  

Charles
« Last Edit: October 31, 2011, 03:02:20 AM by Charles Pegge »

Peter

  • Guest
Re: Strange Error Message, need help
« Reply #14 on: October 31, 2011, 03:56:48 AM »
Hi Kent,

Code: [Select]
% true  =1 
% false =0 'make this 0, and it doesn't work correctly 
             'as in other languages 
             'we need bool variables true 1, false 0 
             'so b = not(b) type code can be written 
 
bool b = true 
string crlf = chr(13) + chr(10) 
string s = "b starts as true" + crlf + crlf

for x = 0 to 5 
    b = b != (b)   
    s += "x: " str(x) " bool: b= " str(b) crlf 
next x 
 
print s

bool b = false
string s = "b starts as false" + crlf + crlf
for x = 0 to 5 
    b = b not(b)   
    s += "x: " str(x) " bool: b= " str(b) crlf 
next x 

print s 
mBox "Okay, Done"