Results 1 to 5 of 5

Thread: is this example destinated for a class for converting into thinbasic?

Share/Bookmark
  1. #1

    is this example destinated for a class for converting into thinbasic?

    this code example I've found from freebasic manual. I'm only asking if this example has to be translated as class/method ? or there's another way (oop like) to convert this example?

       ' Empty GUI script created on 01-31-2013 13:26:32 by  (thinAir)
     Uses "console"
     
    
     Type sample
     
    
       Texty As String
     
    
       Declare Constructor ()
       Declare Constructor ( a As Integer )
       Declare Constructor ( a As Single  )
       Declare Constructor ( a As String, b As Byte )
     
    
       Declare Operator Cast () As String
     End Type
     
    
     Constructor sample ()
       Print "Konstruktor sample ()"
       Print
       THIS.Texty = "Leer"
     End Constructor
     
    
     Constructor sample ( a As Integer )
       Print "Konstruktor sample ( a As Integer )"
       Print "  a = "; a
       Print
       THIS.Texty = Str(a)
     End Constructor
     
    
     Constructor sample ( a As Single )
       Print "Konstruktor sample ( a As Single )"
       Print "  a = "; a
       Print
       THIS.Texty = Str(a)
     End Constructor
     
    
     Constructor sample ( a As String, b As Byte )
       Print "Konstruktor sample ( a As String, b As Byte )"
       Print "  a = "; a
       Print "  b = "; b
       Print
       THIS.Texty = Str(a) + "," + Str(b)
     End Constructor
     
    
     
    
     Operator sample.Cast () As String
       Return THIS.Texty
     End Operator
     
    
     Print "Erstelle x1" ' (build x1)
     Dim x1 As sample
     
    
     Print "Erstelle x2" ' (build x2)
     Dim x2 As sample = 1
     
    
     Print "Erstelle x3" ' (build x3)
     Dim x3 As sample = 99.9
     
    
     Print "Erstelle x4" ' (build x4)
     Dim x4 As sample = sample( "aaa", 1 )
     
    
     Print "Values:"
     Print "  x1 = "; x1
     Print "  x2 = "; x2
     Print "  x3 = "; x3
     Print "  x4 = "; x4
     'Sleep
     WaitKey
    

    bye, largo

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,105
    Blog Entries
    2
    Rep Power
    10
    thinBasic has no OOP constructs so you must go with usual procedural programming way
    Uses "console"
    
    Type sample
      Texty As String
    End Type
    
    PrintL "Erstelle x1" ' (build x1)
    Dim x1 As sample
    
    PrintL "Erstelle x2" ' (build x2)
    Dim x2 As sample
    x2.Texty = 1
    
    PrintL "Erstelle x3" ' (build x3)
    Dim x3 As sample
    x3.Texty = 99.9
    
    PrintL "Erstelle x4" ' (build x4)
    Dim x4 As sample
    x4.Texty = "aaa" & "," & 1
    
    PrintL "Values:"
    PrintL "  x1 = ", x1.Texty
    PrintL "  x2 = ", x2.Texty
    PrintL "  x3 = ", x3.Texty
    PrintL "  x4 = ", x4.Texty
    'Sleep
    WaitKey
    
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  3. #3
    Member
    Join Date
    Sep 2008
    Location
    Germany
    Posts
    406
    Rep Power
    49
    In comparison to this OOP crap, your demo is a blessing!
    Well done, Eros.

  4. #4
    thank you eros for your answer, never I've seen before such a silly construct like in freebasic for shorten and cutting so simple into thinbasic! bye, largo

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,105
    Blog Entries
    2
    Rep Power
    10
    I think that FreeBasic example was not created to complicate something simple but to show how to construct a FreeBasic Class with different Constructors overloading and class casting.

    Is indeed quite interesting and shows of a possible way to implement OOP.
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

Similar Threads

  1. creating my own class
    By ReneMiner in forum thinBasic General
    Replies: 4
    Last Post: 17-11-2012, 20:07
  2. converting question from c++ to powerbasic
    By Lionheart008 in forum C / C++
    Replies: 3
    Last Post: 13-06-2012, 11:22
  3. How to run a Dot Net 4.0 class from Powerbasic
    By zak in forum Software discussion
    Replies: 1
    Last Post: 17-12-2011, 11:27
  4. Help converting this math formula into code, please.
    By kryton9 in forum Math: all about
    Replies: 21
    Last Post: 06-12-2010, 04:00
  5. How to use asciiz inside a class?
    By efgee in forum O2h Compiler
    Replies: 4
    Last Post: 03-09-2010, 20:20

Posting Permissions

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