REDEBOLT
11-10-2011, 03:46
I have to admit I'm new to Oxygen.
I'm trying to run the program listed here. (http://www.thinbasic.com/community/showthread.php?9678-Classes-and-Methods&highlight=oxygen+class)
'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
I'm trying to run the program listed here. (http://www.thinbasic.com/community/showthread.php?9678-Classes-and-Methods&highlight=oxygen+class)
'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