Results 1 to 6 of 6

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

  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170

    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.
    I think there are missing some Forum-sections as beta-testing and support

  2. #2
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159
    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
    57
    Posts
    8,777
    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/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  4. #4
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170
    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.
    I think there are missing some Forum-sections as beta-testing and support

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    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 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  6. #6
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170
    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.)
    I think there are missing some Forum-sections as beta-testing and support

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

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
  •