Android Question [RESOLVED] Storing Ticks in KVS, reading back issue

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hi All

I am storing the datetime.now in a KVS, using KVS.putsimple. I read it back and I can see it is numeric, verified with isnumeric(), when I assign the return value to a long variable I am getting the long variable being zero !

I am confused .

Regards

John.
 

James Chamblin

Active Member
Licensed User
Longtime User
Can you give a small example that shows this problem? I can't seem to replicate it here. Assigning the key to a long gives the expected results.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
Good Morning

I have done as suggested, but alas I still seem to be getting 0 for the return value. Below is the relevant code.


B4X:
' // this is my type 
Type mRT_iBeacon(enabled As Int,  _
           update_freq As Int, _
           iBeaconAPvalidtime As Int, _
           iBeaconAPdataRecordValidTime As Int, _
           iBeaconAPwaitTimeSOS As Int, _
           iBeaconAPwaitTimeSOSTimeout As Long, _
           send_alert_via_wifi As Int, _
           next_update As Long, _
           networks As String, _
           last_networks As String, _
           ws As mSocket, _
           iBeacon_last_fix As String, _
           iBeacon_last_time As Long, _    ' // this is var that store the ticks
           pkt As String, _
           pkt_alert As String, _
           pkt_alert_pending As Boolean, _
           pkt_alert_sent As Boolean, _
           track As Int, _
           timeout As Long, _
           iBeacon_valid_until As Long, _
           iBeacon_valid_kill As Long, _
           restart As Boolean, _
           restart_msg As String, _
           restart_type As String _
           )
 
' // this is the line of code that assigns the datetime ticks
Main.APPSET.RT_iBeacon.iBeacon_last_time = DateTime.Now
mod_settings.put_ibeacon_last_time

' // this is theline of code that gets the store ticks
Main.APPSET.RT_iBeacon.iBeacon_last_fix = mod_settings.get_ibeacon_last_time

' // these functions are in a module, mod_settings
Sub put_iBeacon_last_time
   
   Try
     KVS.PutSimple("iBeacon_last_time",Main.APPSET.RT_iBeacon.iBeacon_last_time)
   Catch
     ToastMessageShow("mod_settings(), put_ibeacon_last_networks_time, error - " & LastException.Message,True)
     mod_functions.writelog("mod_settings(), put_ibeacon_last_networks_time, error - " & LastException.Message )
   End Try
   
End Sub

Sub get_ibeacon_last_time As Long
   
   Try
     Dim res As Long =  KVS.GetSimple("iBeacon_last_time")
     mod_functions.writelog("mod_settings(), get_ibeacon_last_time, res - " & res )
     Return res
   Catch
     ToastMessageShow("mod_settings(), get_ibeacon_last_time, error - " & LastException.Message,True)
     mod_functions.writelog("mod_settings(), get_ibeacon_last_time, error - " & LastException.Message )
     Return ""
   End Try
   
End Sub

When try to get the store value this is my log results:

B4X:
' // load last visibility
       Main.APPSET.RT_iBeacon.last_networks = mod_settings.get_ibeacon_last_networks
       Main.APPSET.RT_iBeacon.iBeacon_last_fix = mod_settings.get_ibeacon_last_time
       
       mod_functions.writelog("svc_ibeacon(), * loading historical data " )
       mod_functions.writelog("svc_ibeacon(), last beacon is  " & Main.APPSET.RT_iBeacon.last_networks)
       mod_functions.writelog("svc_ibeacon(), last fix value  " & Main.APPSET.RT_iBeacon.iBeacon_last_time)
       mod_functions.writelog("svc_ibeacon(), last fix date is " & DateTime.date(Main.APPSET.RT_iBeacon.iBeacon_last_time))
       mod_functions.writelog("svc_ibeacon(), last fix time is " & DateTime.Time(Main.APPSET.RT_iBeacon.iBeacon_last_time))

' // logs results for above
10/08/2015 10:03:56.032 - mod_settings(), get_ibeacon_last_time, res = 1444294075896
10/08/2015 10:03:56.046 - svc_ibeacon(), * loading historical data
10/08/2015 10:03:56.053 - svc_ibeacon(), last beacon is F1A703B3915A-630.1348
10/08/2015 10:03:56.057 - svc_ibeacon(), last fix value 0
10/08/2015 10:03:56.061 - svc_ibeacon(), last fix date is 01/01/1970
10/08/2015 10:03:56.066 - svc_ibeacon(), last fix time is 01:00:00

I must admit, I am totally stumped.

Regards

John.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
I am stupid, sorry.
Main.APPSET.RT_iBeacon.iBeacon_last_fix is a string, it should have been
Main.APPSET.RT_iBeacon.iBeacon_last_time.

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…