Android Question Question about variables

Discussion in 'Android Questions' started by kepler, Mar 31, 2015.

  1. kepler

    kepler Active Member Licensed User

    Good morning,

    As you know, I'm facing some troubles with Global vars.
    The fact is that if I have a var in a code module, for instance, I can change it.

    But here's the problem: supose I have a string var called Data in Module1 with the value "None".
    If I, in the Activity_Create, put something like this:

    Code:
    Module1.Data = "777"
    Msgbox(Module1.Data,"Info")
    I get the value 777. Ok.

    If I create a Sub, say Function1, and include it like this:

    Code:
    Sub Function1 as Int
    Module1.Data = 
    "777"
    Msgbox(Module1.Data,"Info")
    End Sub
    I also get 777.

    BUT, supose I do this:

    Code:
    Sub Activity_Create(FirstTime As Boolean)
    dim res as Int = Function1
    Msgbox(Module1.Data,"Info")
    End Sub

    Sub Function1 as Int
    Module1.Data = 
    "777"
    End Sub
    I'll get 777 IF the routine is as it is. But I'll get None, if Function1 is a "catch" function, like for example:

    Sub JobDone (Job As HttpJob)
    Module1.Data = "777"
    ...

    or

    Sub MyWifi_FoundLocation ()
    Module1.Data = "777"
    ...

    In these cases, it seems that there's no time for the Function1 assign the new value to the var.
    And Activity_Create doesn't catch it - perhaps because it runs aside Function1 at the same time?

    Maybe I'm seeing this wrong.

    Kind regards,

    Kepler
     
  2. sorex

    sorex Expert Licensed User

    I think the int declaration method you use is only for static values, not to call a function/sub.

    try it like this instead

    Code:
    Sub Activity_Create(FirstTime As Boolean)
    dim res as Int
    res = Function1
    Msgbox(Module1.Data,"Info")
    End Sub
     
  3. DonManfred

    DonManfred Expert Licensed User

    Function1 does not have a RETURN value. It just set a global variable... So, the "res =" is not needed
     
  4. kepler

    kepler Active Member Licensed User

    Yes, I'm aware of that.
    But how do I catch the values of the routines like Sub MyWifi_FoundLocation () or Sub JobDone (Job As HttpJob)?

    Kepler
     
  5. DonManfred

    DonManfred Expert Licensed User

    You cannot "Catch" a result from JobDone as you DONT call it. What you can do is to call a sub in your activity FROM Jobdone to GIVE the value to your sub.
    I dont use wifi-libs so i dont know MyWifi_FoundLocation () and what it does... But i believe it is the same like Jobdone... You need to call your sub giving the value from that sub too
     
  6. sorex

    sorex Expert Licensed User

    you either store them in the module/class or you call a sub in your main module with callsub2(modulename,"subname","yourvalue")
     
  7. kepler

    kepler Active Member Licensed User

    Hi,

    Actually there's a process - not very nice though - to try to "catch" the variables.
    Using a Timer.

    You fire the Timer in Activity_Create. Create a number of beats too - that you count in Timer1_Tick sub.
    In the subs that take long, declare the new value obtained to a Global variable.
    In Timer1_Tick, just verify if the default Global variables have change - for the time that you want to wait. In the refered subs I mentioned, about 1.5 seconds were enough. If the values don't change, deal the best way - the subs might be jammed.

    It's the best solution I've found.

    Cheers,

    Kepler
     
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