Results 1 to 3 of 3

Thread: Oxygen Run Time Error

  1. #1
    Member REDEBOLT's Avatar
    Join Date
    Dec 2006
    Location
    Pickerington, Ohio, USA
    Age
    88
    Posts
    62
    Rep Power
    25

    Oxygen Run Time Error

    I have to admit I'm new to Oxygen.
    I'm trying to run the program listed here.

    'CLASSES AND METHODS
     '
     
    Uses "oxygen","file"
     Dim p0,p1 As Long, src As String
     Dim dd(100) As Double
     
    src = "
     
    CLASS stat
     METHOD Sum() As Double
     METHOD average() As Double
     /
     da(100) As Double
     dn As Long
     End CLASS
     
    '-------------- 
    methods of stat
     '==============
     METHOD Sum() As Double
     Dim i
     For i = 1 To THIS.dn
     METHOD += THIS.da(i)
     Next
     End METHOD
     METHOD average() As Double
     METHOD = THIS.Sum / THIS.dn
     End METHOD
     End methods
     '====
     'TEST
     '====
     Dim s As stat
     s.da=>2,4,6,8,10,12,14,16,18
     s.dn=9
     Print `Sum: ` str(s.Sum) ` Average: ` str s.average
     "
     
    O2_BASIC src
     
    'msgbox 0, o2_view "o2h "+src
     
    If Len(O2_ERROR) Then
     MsgBox 0, O2_ERROR : Stop
     End If
     
    O2_EXEC
    
    and I get a runtime error.

    So I make changes
    'CLASSES AND METHODS
     '
     
    Uses "oxygen","file"
     Dim p0,p1 As Long, src As String
     Dim dd(100) As Double
     
    src = "
     
    CLASS stat
       METHOD Sum() As Double
       METHOD average() As Double
       /
       da(100) As Double
       dn As Long
     End CLASS
     
    '-------------- 
    methods of stat
     '==============
     METHOD Sum() As Double
       Dim i
       Dim mysum as double        ' Added
       For i = 1 To THIS.dn
    '     METHOD += THIS.da(i)
         mysum += THIS.da(i)      ' Added
       Next
       METHOD = mysum             ' Added
     End METHOD
     METHOD average() As Double
        METHOD = THIS.Sum / THIS.dn
     End METHOD
     End methods
     '====
     'TEST
     '====
     Dim s As stat
     s.da=>2,4,6,8,10,12,14,16,18
     s.dn=9
     Print `Sum: ` str(s.Sum) ` Average: ` str s.average
     "
     
    O2_BASIC src
     
    'msgbox 0, o2_view "o2h "+src
     
    If Len(O2_ERROR) Then
     MsgBox 0, O2_ERROR : Stop
     End If
     
    O2_EXEC
    
    I make changes, but I still get error.

    I have TB 1.8.9.0.

    Regards,
    Bob

  2. #2
    Hi Bob,

    These examples need to be updated. Sorry about that.

    There were 2 bugs due to old syntax, but this is how I would express it more clearly now.

    '===================
    'CLASSES AND METHODS
    '===================
    '
      
    Uses "oxygen"
      
    dim as string src = "
      
     CLASS stat
       da(100) As Double
       dn As Long
    
    
     METHOD Sum() As Double
       Dim sys i
       For i = 1 To dn
         METHOD += da(i)
       Next
     End METHOD
     '
     METHOD average() As Double
       METHOD = Sum() / dn
     End METHOD
     '
     End CLASS
      
     '====
     'TEST
     '====
     '
     Dim s As stat
     s.da<=2,4,6,8,10,12,14,16,18
     s.dn=9
     Print "Sum: " str(s.Sum) " Average: " str (s.average)
     "
      
    O2_BASIC src
      
    'msgbox 0, o2_view "o2h "+src
      
    If Len(O2_ERROR) Then
     MsgBox 0, O2_ERROR : Stop
     End If
      
    O2_EXEC
    
    I will review the other examples as soon as possible.

    Charles
    Last edited by Charles Pegge; 11-10-2011 at 07:15.

  3. #3
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,865
    Rep Power
    405
    I should add that in oxygen you can use "return" in a function to return a value instead of "method" as Charles showed. I think return is better as it makes the code less confusing.

    METHOD average() As Double
       RETURN ( Sum() / dn )
     End METHOD
    

Similar Threads

  1. Run-time error in TAB version 12
    By ErosOlmi in forum T.A.B. (ThinBasic Adventure Builder)
    Replies: 10
    Last Post: 17-09-2006, 14:29

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •