Results 1 to 6 of 6

Thread: making Subs/Functions private to .tBasicU-file?

  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Philippines
    Age
    48
    Posts
    1,218
    Blog Entries
    1
    Rep Power
    133

    making Subs/Functions private to .tBasicU-file?

    I want to create some additional Unit-Files with some subs that should only be accessable to the particular unit-file itself. So I would write for example

    Private Sub mySub()
    '...
    End Sub
    
    but help does not tell anything about keyword Private even though it gets colored blue and capitalized in the script.

    So I want to make sure: can just variables be private properties to the unit-file or are subs and functions also allowed?

    Can two different unit-files have the same titled private subs/functions also?

    And some additional small question:
    Can a function call itself (recursive)?
    Last edited by ReneMiner; 15-02-2013 at 15:39.
    [TABLE="class: tblf1 tblf-fullwidth tblf-alternate"]
    [TR]
    [TD][COLOR=#b22222][B][SIZE=1]The limit is[/SIZE][/B][/COLOR][/TD]
    [TD="class: isRelinked"] [COLOR=#0000cd][B][SIZE=1]Imagination[/SIZE][/B][/COLOR][/TD]
    [/TR]
    [/TABLE]

  2. #2
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Blog Entries
    1
    Rep Power
    153
    So I want to make sure: can just variables be private properties to the unit-file or are subs and functions also allowed?

    Can two different unit-files have the same titled private subs/functions also?
    I would say no but Eros will confirm when he gets time.

    and this is my answer to your last question(obviously you will need some escape route)
    Test()
    Stop
    
    
    Sub test()
    Static n As Long
    
      Incr n
      MsgBox 0, "N = "+n
       If n < 10 Then test()
     
    End Sub
    
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,198
    Blog Entries
    2
    Rep Power
    10
    Rene,

    I'm sorry but all thinBasic subs/functions are global. "Private" keyword is reserved for future uses.
    What you would need is a sort of NameSpace which is something I'm thinking about since some time.

    Regarding recursion, yes, you can recursively call a sub/function. Important is to have a sub/function ...exit strategy

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  4. #4
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Philippines
    Age
    48
    Posts
    1,218
    Blog Entries
    1
    Rep Power
    133
    OK, that I can make my function shift some elements until there's enough space to insert a new one is possible. Helps a lot.

    The "private"- stuff makes me think about some extra-thinbasic-filetype, and I call it "Module" instead of "Unit" in this post now.

    So maybe the current unit- and "normal" thinBasic-files are still working as now and forever stay the same, and their contents stays global to keep compatibilty for all the programs we already wrote.
    A module could have variables, subs and functions that could be declared Private or Public in any case and to access a modules public member it should be necessary to call it like

    result = Module\Function()
    or
    Module\Sub()
    or
    Module\Var = X
    X=Module\Var

    So there would be no more fearing of messing up similar controls from one dialog to another for example - ControlID's could be private to the certain module where they are placed on by default since the modules name has to be part of an outside-call. But I don't know if and how this could be realized.
    [TABLE="class: tblf1 tblf-fullwidth tblf-alternate"]
    [TR]
    [TD][COLOR=#b22222][B][SIZE=1]The limit is[/SIZE][/B][/COLOR][/TD]
    [TD="class: isRelinked"] [COLOR=#0000cd][B][SIZE=1]Imagination[/SIZE][/B][/COLOR][/TD]
    [/TR]
    [/TABLE]

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    6,800
    Blog Entries
    3
    Rep Power
    694
    Hi Rene,

    the module is already reserved term for DLL...modules, but I support this idea of isolated code units.

    I personally prefix my "private" routines with private_, so it alerts the user at least visually:
    function private_Something_Action()
    end function
    
    To avoid name conflicts at least partially, when I have code unit named unit_Something.tBasicU, I prefix all types and functions with Something_ -> this is basically emulation of the namespace approach:
    function Something_DoThis()
    end function
    
    function Something_DoThat()
    end function
    

    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

  6. #6
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Philippines
    Age
    48
    Posts
    1,218
    Blog Entries
    1
    Rep Power
    133
    Sure, I read the comments in the multiple-dialogs example with attention. But it makes the code-lines, especially the ones inside the Unit-File very long, so one has to scroll left and right to read them. I'm more the one stuck to clearly arranged and readable stuff.
    The private-scope to modular files, call'em maybe "Subassembly" instead of "Module" would make them multiple-usable without worries of names (as File-Dialogs, Color-Pickers, Loading-routines like "fileformat_IMAGE.tBasicU" etc.)
    [TABLE="class: tblf1 tblf-fullwidth tblf-alternate"]
    [TR]
    [TD][COLOR=#b22222][B][SIZE=1]The limit is[/SIZE][/B][/COLOR][/TD]
    [TD="class: isRelinked"] [COLOR=#0000cd][B][SIZE=1]Imagination[/SIZE][/B][/COLOR][/TD]
    [/TR]
    [/TABLE]

Similar Threads

  1. Rap Music and Private Prisons
    By danbaron in forum Shout Box Area
    Replies: 0
    Last Post: 04-05-2012, 20:58
  2. Using Oxygen subs and functions in thinBasic
    By Charles Pegge in forum O2h Compiler
    Replies: 0
    Last Post: 18-03-2009, 13:25

Posting Permissions

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