OOP in LB ?

Algemene discussies en vragen omtrent Liberty BASIC programma's. Stuur zoveel mogelijk delen van listings (snippets) in als je hulp wilt.

Moderators: anthonio, Abcott

OOP in LB ?

Berichtdoor bluatigro » vr jul 24, 2015 10:40 am

ik probeerde mijn algemene OOP code
maar ik krijg niet wat ik verwacht
Code: Selecteer alles
''first we create some objects
obj1$ = v3d$( 1 , 2 , 3 )
obj2$ = v3d$( 4 , 5 , 6 )
''then we print them
print "vectors :"
print " a = " ; obj1$
print " b = " ; obj2$
''then we do some OOP math
print "adding :"
print "a + b = " ; addv3d$( obj1$ , obj2$ )
print "subtracting :"
print "a - b = " ; subv3d$( obj1$ , obj2$ )
print "lenght :"
print "| a | = " ; lenghtv3d( obj1$ )
print "| b | = " ; lenghtv3d( obj2$ )
clas$ = "x y z"
print "general OOP test"
print "class = " ; clas$
object$ = v3d$( 1 , 2 , 3 )
print "v3d$ = " ; object$
object$ = setprop$( clas$ , object$ , "x" , "77" )
print "v3d.x = 77 = " ; object$
property$ = getprop$( clas$ , object$ , "z" )
print "v3d.z = " ; property$
end
''special class functions
function v3d$( x , y , z )
''constructor of a v3d object$
  v3d$ = str$( x ) + " " + str$( y ) + " " + str$( z )
end function
function xv3d( a$ )
''property
  xv3d = val( word$( a$ , 1 ) )
end function
function yv3d( a$ )
''property
  yv3d = val( word$( a$ , 2 ) )
end function
function zv3d( a$ )
''property
  zv3d = val( word$( a$ , 3 ) )
end function
function addv3d$( a$ , b$ )
''first get property's
  ax = xv3d( a$ )
  ay = yv3d( a$ )
  az = zv3d( a$ )
  bx = xv3d( b$ )
  by = yv3d( b$ )
  bz = zv3d( b$ )
''use constructor to get new object$
  addv3d$ = v3d$( ax + bx , ay + by , az + bz )
end function
function subv3d$( a$ , b$ )
''first get property's
  ax = xv3d( a$ )
  ay = yv3d( a$ )
  az = zv3d( a$ )
  bx = xv3d( b$ )
  by = yv3d( b$ )
  bz = zv3d( b$ )
''use constructor to get new object$
  subv3d$ = v3d$( ax - bx , ay - by , az - bz )
end function
function lenghtv3d( a$ )
  x = val( word$( a$ , 1 ) )
  y = val( word$( a$ , 2 ) )
  z = val( word$( a$ , 3 ) )
  lenghtv3d = sqr( x ^ 2 + y ^ 2 + z ^ 2 )
end function
''genaral class functions
''these work slow
''so i dont think of using them
function setprop$( clas$ , object$ , prop$ , val$ )
  pointer = 1
  out$ = ""
  while pointer < 20 _
  and word$( clas$ , pointer ) <> prop$ _
  and word$( clas$ , pointer ) <> ""
    if word$( clas$ , pointer ) = prop$ then
      out$ = out$ + " " + val$
    else
      out$ = out$ + " " + word$( object$ , pointer )
    end if
    pointer = pointer + 1
  wend
  setprop$ = out$
end function
function getprop$( clas$ , object$ , prop$ )
  pointer = 1
  out$ = "error"
  while pointer < 20 _
  and word$( clas$ , pointer ) <> prop$ _
  and word$( clas$ , pointer ) <> ""
    if word$( clas$ , pointer ) = prop$ then
      out$ = word$( object$ , pointer )
    end if
    pointer = pointer + 1
  wend
  getprop$ = out$
end function
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Keer terug naar Liberty BASIC Code

Wie is er online

Gebruikers op dit forum: Geen geregistreerde gebruikers. en 1 gast

cron