Android Question create a child sub into parent sab

Discussion in 'Android Questions' started by ArminKH, Jul 2, 2015.

  1. ArminKH

    ArminKH Well-Known Member

    hi
    if you see Picasso lib we have so subs in this library
    and one of this subs is "LoadFile" but on this sub we have too many other subs such as Fetch and...
    Code:
    dim Picasso1 as Picasso
    Picasso1.LoadFile.Fetch
    now i want to create a library which that has child subs to one parent sub(Subs to Sub)
    maybe my code can be similar to following codes
    Code:
    Sub Result
        
    Sub male() As String
            
    Return "Male"
        
    End Sub
     
        
    Sub Female() As String
            
    Return "Female"
        
    End Sub
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        
    Dim A As MyLib
            
    Log(A.Result.male)
    End Sub
    how is possible same future on B4A??!!
    thanx to all
     
  2. Cableguy

    Cableguy Expert Licensed User

    I would be interested in knowing how you did that!
     
    ArminKH likes this.
  3. ArminKH

    ArminKH Well-Known Member

    lemonisdead likes this.
  4. ArminKH

    ArminKH Well-Known Member

    Not anyone can help me?
    @Erel?
    Any idea?
     
  5. LucaMs

    LucaMs Expert Licensed User

    Most likely LoadFile is a class (an object), not a sub.
     
    ArminKH likes this.
  6. ArminKH

    ArminKH Well-Known Member

  7. LucaMs

    LucaMs Expert Licensed User

    Try reading STARTING FROM this :(:)
     
    ArminKH likes this.
  8. ArminKH

    ArminKH Well-Known Member

    THANK U but thats not exactly is relevant to my purpose :(:(:(:(:(:(:(:(:(:(:(:(:(:(:(
     
  9. LucaMs

    LucaMs Expert Licensed User

    Then I should read your question well :)
     
    ArminKH likes this.
  10. ArminKH

    ArminKH Well-Known Member

    here is your code on that thread
    On activity Main
    Code:
    #Region  Project Attributes
        
    #ApplicationLabel: lm Create Library
        
    #VersionCode: 1
        
    #VersionName:
        
    'SupportedOrientations possible values: unspecified, landscape or portrait.
        #SupportedOrientations: unspecified
        
    #CanInstallToExternalStorage: False
    #End Region

    #Region  Activity Attributes
        
    #FullScreen: False
        
    #IncludeTitle: True
    #End Region

    Sub Process_Globals

    End Sub

    Sub Globals
      
    End Sub

    Sub Activity_Create(FirstTime As Boolean)

    End Sub

    Sub Activity_Resume
        
    Private ObjA As ClassA
        ObjA.Initialize
        ObjA.ShowSum
    End Sub

    Sub Activity_Pause (UserClosed As Boolean)

    End Sub
    and on ClassA
    Code:
    'Class module
    Sub Class_Globals
        
    Private ObjB As ClassB
    End Sub

    'Initializes the object. You can add parameters to this method if needed.
    Public Sub Initialize
        ObjB.Initialize
    End Sub

    Public Sub ShowSum
        
    Msgbox(ObjB.Add(5,6),"")
    End Sub
    and on ClassB
    Code:
    'Class module
    Sub Class_Globals
      
    End Sub

    'Initializes the object. You can add parameters to this method if needed.
    Public Sub Initialize

    End Sub

    Public Sub Add(Num1 As Int, Num2 As Int) As Int
        
    Return Num1 + Num2
    End Sub
    maybe if this sub
    Code:
    Public Sub ShowSum
        
    Msgbox(ObjB.Add(5,6),"")
    End Sub
    can be changed to
    Code:
    Public Sub ShowSum As ClassB

    End Sub
    then my problem solved
    but i cant do this since last night to now :(

    and excuse me if my BAD English makes misunderstanding :(
     
    LucaMs likes this.
  11. LucaMs

    LucaMs Expert Licensed User

    I do not fear rivals: my English is the worst :D
     
    Cableguy, lemonisdead and ArminKH like this.
  12. Cableguy

    Cableguy Expert Licensed User

    I'll
    I would say you're winning by a nose!
     
  13. LucaMs

    LucaMs Expert Licensed User


    Yes, but my nose (about 25... inches :D) !!!
     
    ArminKH, Cableguy and lemonisdead like this.
  14. ArminKH

    ArminKH Well-Known Member

    ok after discussion about nose...please suggest a solution to solve my problem pleasezzzzzzzzzzzzzzzzzz :D
     
  15. LucaMs

    LucaMs Expert Licensed User



    As mentioned, my English is poor (and at this time I do not understand even Italian :D).

    I did not understand if you want help in creating classes or you need to know how to hide the properties and methods of the "service" class used by the main class.

    In this second case, this was the Erel's answer and it works.
     
    ArminKH likes this.
  16. ArminKH

    ArminKH Well-Known Member

    English : ok all of my problem is knowing how is possible following method on Picasso Lib

    Italian : ok tutto il mio problema è sapere come sia possibile seguente metodo su Picasso Lib
    Code:
    Dim Picasso1 As Picasso
            Picasso1.LoadFile.Fetch(Target1)
    English :In this method we have a sub named ReadFile and another named Fetch
    how is possible to implement this on b4a classes ? because i want to use this on my library

    Italian:In questo metodo abbiamo un sub di nome ReadFile e un altro chiamato Trovalo
    come sia possibile implementare questa sulle classi B4A? perché voglio utilizzare questo sul mio biblioteca

    if still my question is Unclear then we can discuse with b4a Language :D
    Thank u
     
  17. Cableguy

    Cableguy Expert Licensed User

    Well I'm playing around with this and I'm getting a strange error:

    at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:522)

    In my middle class where I define the second class
     
    ArminKH likes this.
  18. ArminKH

    ArminKH Well-Known Member

    Maybe @Erel can answer to this question because we can see similar subs on string builder which is a part of core library
     
  19. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Well this is the closest I have managed to achieve (see attached). I don't think you can do this without exposing the initialize method because when using a class you must initialise it first before being able to use it. Do you have to use Classes or could you use Code Modules? I've not tested whether it will work with code modules, I'm just guessing that you won't need to initialise first.

    Main Activity...
    Code:
    Sub Activity_Create(FirstTime As Boolean)
        
    'Do not forget to load the layout file created with the visual designer. For example:
        'Activity.LoadLayout("Layout1")
        Dim A As ClassA
        A.Initialize
        A.Result.Male
        A.Result.Female
    End Sub
    ClassA...
    Code:
    'Class module
    #IgnoreWarnings:12
    Private Sub Class_Globals
    End Sub

    'Initializes the object. You can add parameters to this method if needed.
    Public Sub Initialize
    End Sub

    Private Sub IsInitialized
    End Sub

    Public Sub Result As ClassB
        
    Dim B As ClassB
        B.Initialize
        
    Return B
    End Sub
    ClassB...
    Code:
    'Class module
    #IgnoreWarnings:12
    Private Sub Class_Globals
    End Sub

    'Initializes the object. You can add parameters to this method if needed.
    Public Sub Initialize
    End Sub

    Private Sub IsInitialized
    End Sub

    Public Sub Male
        
    Log("male")
    End Sub

    Public Sub Female
        
    Log("female")
    End Sub
     

    Attached Files:

    ArminKH likes this.
  20. ArminKH

    ArminKH Well-Known Member

    Thank u your attached source is exactly Something that i want to do
    and now for next step thats can be better if we can Hide Initialize and IsInitialized And also ClassB From Activity and ClassB be Available just from ClassA
    is this possible?
     
Loading...