Android Question Testing the type of a variable

Discussion in 'Android Questions' started by Troberg, Feb 18, 2015.

  1. Troberg

    Troberg Well-Known Member Licensed User

    Once again, I'm pondering my settings framework. I still don't like to have:

    Code:
    * SettingStr(Key as string, Value as string, Write as bool) as string
    * SettingInt(Key 
    as string, Value as int, Write as bool) as int
    * SettingLong(Key 
    as string, Value as long, Write as bool) as long
    * SettingBool(Key 
    as string, Value as bool, Write as bool) as bool
    * SettingFloat(Key 
    as string, Value as float, Write as bool) as float
    * SettingDouble(Key 
    as string, Value as double, Write as bool) as double
    * SettingDate(Key 
    as string, Value as long, Write as bool) as long
    Yet, I do want to do some special stuff on some types, to maintain human readability. This mainly applies to bools (save as Yes/No) and dates (save in ISO format).

    As overloading is not likely to happen soon, I started thinking about doing this:

    Code:
    * Setting(Key as string, Value as object, Write as bool) as object
    Then I'd test the type of the Value argument and do whatever formatting needed. Possible?
     
  2. DonManfred

    DonManfred Expert Licensed User

    Sadly B4a does not allow overloading
     
    Peter Simpson likes this.
  3. Troberg

    Troberg Well-Known Member Licensed User

    I know, that's why I was considering this workaround.
     
  4. eurojam

    eurojam Well-Known Member Licensed User

    did you try:
    Code:
    Dim o As Object
        o = Setting(
    "abc","abc",True)
        
    Dim VarType As String = GetType(o)
        
    Log(VarType)
    and then parse the return string like:
    • java.lang.String
    • java.lang.Double
    ....and so on
     
    Troberg likes this.
  5. Troberg

    Troberg Well-Known Member Licensed User

    Nope, but I will!
     
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