Android Question Convert the name of an object into the object itself

Discussion in 'Android Questions' started by DanteS, Feb 4, 2015.

  1. DanteS

    DanteS Member Licensed User

    I have some spinners named co_city, co_customers, co_seller, etc, and a rutine Fill_co(co as spinner, data as list) to fill the spinners with the members of a list.

    To fill the list I use the PostString method to execute a query and receive the list from the database in the JobDone rutine. I also store the name of the spinner to be filled in a variable named Objecttofill.

    Inside the JobDone rutine I use this code:
    <code>
    Select case Objecttofill
    Case "co_cities"
    Fill_co(co_cities,list)
    Case "co_customers"
    Fill_co(co_customers,list)
    End Select
    </code>

    Instead of this code, I would like to do this:
    Use a rutine Fill_co2(nco as string, data as list) and call it this way:
    Fill_co2(Objecttofill,list)

    Inside Fill_co2 I would use a code to transform the content of the string variable nco, into a spinner variable co and then use co.Add to fill the spinner.

    How can I perform the last operation
     
  2. derez

    derez Expert Licensed User

    Like this ? move the select to the fill sub:
    Code:
    dim co as spinner
    Select nco
    Case "co_cities"
    co  = co_cities
    ....

    end select
    co.add...
     
  3. DanteS

    DanteS Member Licensed User

    Thanks for your reply
    No I don't want to write a list of Case "xxx" Fill(xxx) Case "yyy" Fill(yyy) ...
    I want to write only something like Fill(nco)
     
  4. derez

    derez Expert Licensed User

    That is what I wrote:
    Code:
    Sub Fill(nco As String, data As List)
    Dim co As Spinner
    Select nco
    Case "co_cities"
        co  = co_cities
    Case "co_customers"
        co  = co_customers
    Case ...


    End Select
    co.add...
    End Sub
    Another solution:In stead of select, put the spinners in a list and get them from that list by the index number which will be supplied by nco (it will change to int):

    Dim co as spinner = spinners_list.get(nco)
    co.add ...

    Another alternative - instead of a list, a map with the name of the spinner as key and the spinner object as value, then you get the object from the map by the name(nco) as the key.
     
    Last edited: Feb 5, 2015
    DonManfred and lemonisdead like this.
  5. Erel

    Erel Administrator Staff Member Licensed User

    +1
     
    lemonisdead and DonManfred like this.
  6. DanteS

    DanteS Member Licensed User

    Thanks again
    I am going to try it using the map solution.
    I asked because in .net there is something like co=FindControl(nco)
    What means the "+1" answer of Erel?
     
  7. DonManfred

    DonManfred Expert Licensed User

    That he think the quoted answer is a GOOD answer. And when "Erel" (our guru) post a +1 then it MUST be for sure a GOOD answer! :)
     
    mangojack, lemonisdead and Erel like this.
  8. DonManfred

    DonManfred Expert Licensed User

    I like Erels like :D
     
    lemonisdead likes this.
  9. derez

    derez Expert Licensed User

    And with all that talking I get only one like and not even from you but from lemonisdead ? thanks !
     
    lemonisdead and DonManfred like this.
  10. KMatle

    KMatle Expert Licensed User

    I like @DonManfred liking Erels like :D
     
    DonManfred likes this.
  11. DonManfred

    DonManfred Expert Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice