Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Doubt about classes in another module

  1. #1
    Member
    Join Date
    Aug 2015
    Location
    Keralam, India
    Posts
    121
    Rep Power
    21

    Doubt about classes in another module

    Hi all,
    I was playing with some classes. This is my class file.
    Class MyClass
         
        Dim a As Integer = 1500
        Dim b As String = "This is from class"     
        Method MyFunc(ByVal c As Integer)
             Return C * 10
        End Method
        
    End Class
    
    I saved this file as MyClass1.inc in ThinbasicPath\Mod.
    And this is my working file.
    Uses "Console"
    Module "MyClass1.inc" 
    
    Dim My_cls As New MyClass1
    Print My_cls.b
    Print "====================="
    Print My_cls.a
    Print "====================="
    Print My_cls.MyFunc(5)
    
    WaitKey
    
    This is saved as ClassTest.tbasicc in another directory. When i execute this script, the console came and vanish very speed. What is wrong with this script. I have test this script with "Uses" instead of "Module" also.
    Note: All i want is to create a class and save it in a module. Then use that class in another script.
    Last edited by kcvinu; 03-11-2016 at 23:44.

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Dear kcvinu,

    thinBasic pseudo OOP is a little different from standard OOP languages that use Classes/Methods/Instance variables.
    thinBasic has used TYPEs to implement a sort of OOP. So you have to use TYPE/END TYPE

    Correct possible script based on your code can be the following:
    '---Load console Module
    Uses "Console"
                              
    '---Type definition                               
    Type MyClass
    
    
      '---Local variables
      a As Integer
      b As String 
      
      '---Default constructor.
      '---In this special functions can take place initialization of the type variables
      Function _Create()
        Me.a = 1500
        Me.b = "This is from class"  
      End Function
      
      '---Type method
      Function MyFunc(ByVal c As Integer) As Long
        Return C * 10
      End Function
    
    
    End Type         
    
    
    
    
    Dim My_cls As New MyClass
    PrintL My_cls.b
    PrintL "====================="
    PrintL My_cls.a
    PrintL "====================="
    PrintL My_cls.MyFunc(5)
    
    
    WaitKey
    
    You can put you TYPE/END TYPE declaration into a separate file and use #INCLUDE to include its source code in many different scripts. See #INCLUDE help to have more info on how to use it.
    Example
    '---Load console Module
    Uses "Console"
                              
    #INCLUDE "MyClassIncludeFile.tbasic"
    
    
    Dim My_cls As New MyClass
    PrintL My_cls.b
    PrintL "====================="
    PrintL My_cls.a
    PrintL "====================="
    PrintL My_cls.MyFunc(5)
    
    
    WaitKey
    
    You can place your include files in any directory you want but you need to tell in your script where to load them. Usually included files are placed into a sub directory of your project and you can use partial include dir like:
    #INCLUDE ".\IncludeDirectory\MyClassIncludeFile.tbasic"
    

    Instead Modules are not source code but compiled DLL specifically developed for thinBasic using thinBasic SDK.
    Modules are loaded into the script using the keyword USES

    Ciao
    Eros
    Last edited by ErosOlmi; 05-11-2016 at 10:33.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    Member
    Join Date
    Aug 2015
    Location
    Keralam, India
    Posts
    121
    Rep Power
    21
    Hi ErosOlmi,
    Thanks a lot. Well, that worked fine. I am learning tb now.
    But when i search in hep file for keyword "_Create", i dont get any result. That means these infos are not in help file. Kindly suggest me some links or pages where i can learn about these functions.
    Anyway, i am eager to wait for your unicode aware version of ThinBasic.
    Last edited by kcvinu; 04-11-2016 at 18:58.

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Yes, my fault. Pseudo OOP in thinBasic is quite recent and still had no time to create proper help material.
    Have a look at \thinBasic\SampleScripts\OOP\ directory for some script examples

    Regarding unicode version, I'm working on it. Already have something working but I first need to finish thinAir (editor) migration from old edit control (CodeMax) to new unicode aware text control Scintilla.
    Anyway, hope to have something to be released for test in few weeks.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5
    Member
    Join Date
    Aug 2015
    Location
    Keralam, India
    Posts
    121
    Rep Power
    21
    Hi ErosOlmi,
    Its ok. No problem. If you don't mind, I am willing to do some documentation work. And it's a glad news that you are planning to use Scintilla. Its very good and customizable. By using it, we can get intellisense and auto complete also. Well, if you don't mind, i have some feature requests.
    1. When hitting enter key after typing a line with keywords like "If, For, Do, While, Select, Function, Type, Sub" automatically add the end appropriate end keywords like "End If, Next, Until, Wend, End Select, End Function, End Type, End Sub".

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Yes, I will add this as an option.

    Actually you can already do it in thinAIR using right click and choosing "Insert code block ..."

    Code blocks can also be customized with personal code blocks. Check inside \thinBasic\thinAir\Syntax\thinBasic\
    Files thinBasic_Blocks_Usr.ini and thinBasic_Blocks.ini
    thinBasic_Blocks_Usr.ini is the user specific version and will never be replaced in future thinBasic versions
    thinBasic_Blocks.ini is the official one and will be replaced when thinBasic is updated.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  7. #7
    Member
    Join Date
    Aug 2015
    Location
    Keralam, India
    Posts
    121
    Rep Power
    21
    Hi ErosOlmi,
    Thanks. That is a good feature. Especially Callback function. But how can i tell ThinAir to rest the cursor in my favourite position ?

  8. #8
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170
    Hi guys,
    Regarding "If" and automatic adding "End If" etc. I already tried when I created thinICE.
    I stumbled over the following: when editing an existing Script and using enter-key then the editor added more "End If" even if none required. So I came to the conclusion to make it different and wait for the user to type "End" & $Spc and the editor adds the required "If", "Const", 'Type", "With", "Function", "Select" or whatever is currently needed when the space is typed in
    Last edited by ReneMiner; 07-11-2016 at 01:49.
    I think there are missing some Forum-sections as beta-testing and support

  9. #9
    Member
    Join Date
    Aug 2015
    Location
    Keralam, India
    Posts
    121
    Rep Power
    21
    @ReneMiner,
    I think if you are going to add that feature, you need to apply this pseudo code.
    When user press an enter key
    1. get the current line number & line text from scite editor control.
    2. Get the first word and last word from line text.
    3. Get the tab position of first word.
    4. If first word is "If" then check the last word for the presence of a "Then". If it is not there, then add "Then".
    5. If first word is "Function" then check the last word for the presence of a "()". If it is not there, then add "()".
    6. Find appropriate end keyword for the first word.
    7. Loop through all lines from current line number + 1. Check each line's specific tab position for the presence of the appropriate end key word. If there is not an end key word, add one and rest cursor in a specific position. If there is an end keyword, just add another line under current line.

  10. #10
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170
    It could work if the user cares for exact intended lines. However if the line Starts with "if" and it does not end with "then" there are different causes. Either it's a one-line if-statement, the user decided to make use of line-continuation - a special Feature of thinBasic)or the user simply forgot it

    C-users or purebasic-users are a group them will happen this very often
    For me typing "end" and spacebar and the editor selects the correct Keyword that has to follow seems quite ok
    I think there are missing some Forum-sections as beta-testing and support

Page 1 of 2 12 LastLast

Similar Threads

  1. Classes and Methods
    By Charles Pegge in forum O2h Compiler
    Replies: 8
    Last Post: 05-12-2011, 15:56
  2. Module classes
    By ErosOlmi in forum thinBasic vaporware
    Replies: 19
    Last Post: 02-12-2011, 12:15
  3. Article: Module classes
    By ErosOlmi in forum vBCms Comments
    Replies: 9
    Last Post: 30-06-2011, 16:38
  4. Concealing Globals in Classes
    By Charles Pegge in forum O2h Compiler
    Replies: 9
    Last Post: 10-07-2009, 10:14
  5. Classes Simplified
    By Charles Pegge in forum O2h Compiler
    Replies: 12
    Last Post: 07-05-2009, 07:34

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
  •