Does SysTime library work

pclinx

Member
Licensed User
Longtime User
I have been trying to use the SysTime Library to set the the time and date on a WM6.5 phone, It does not seem to change the date or time, can anyone see what I am doing wrong?

B4X:
Sub App_Start
'   Form1.Show
    resp = GetText("http://www.mywebservice.co.uk/AnyJunk/php/getDateTime.php")
'   resp = "2010-05-25T10:50:48"
   Dim year As int32
   Dim month As int32
   Dim day As int32
   Dim Hours As int32
   Dim Minutes As int32
   Dim Secs As int32
   year = SubString (resp, 0, 4)
   month = SubString (resp, 5, 2) 
   day = SubString (resp, 8, 2) + 1
   Hours = SubString (resp, 11, 2)
   Minutes = SubString (resp, 14, 2)
   Secs = SubString (resp, 17, 2)

   Systime.New1
   Systime.SetDate(month, day ,year)
   Systime.SetTime(Hours, Minutes, Secs)
   today = Systime.GetDate & " : " & Systime.GetTime
   Msgbox(today)
   Systime.Dispose

End Sub

Sub GetText (URL)
      Response.New1
      Request.New1(URL)
      Response.Value = Request.GetResponse 'This line calls the server and gets the response.
      String = Response.GetString 'Get the Response string.
      Response.Close
      Return String
End Sub
 
Last edited:

specci48

Well-Known Member
Licensed User
Longtime User
Hello pclinx,

I haven't testet you code on the device but as far as i can see it, you mixed up day and month in the setDate method.

Excerpt from the help file:
Syntax: SetDate(Day As Integer, Month As Integer, Year As Integer)

So you tried to set an invalid date in which case nothing is changed.


specci48
 

agraham

Expert
Licensed User
Longtime User
AutoComplete shows a different order for the SetDate parameters than the help does.

SETDATE (Month As Int32, Day As Int32, Year As Int32)

So I looked inside the library code and it seems that the help is wrong, the order is really Month, Date, Year.

SetDate and SetTime use a call to the native SetLocalTime API. SetDate does not work on my Vista desktop. This has been reported by other posts on the Web as a privilege problem, it works on XP but not Vista, and so probably not on Windows 7 either. Running as an Administrator doesn't solve this, at least not for me and for some others on the Web. Apparently turning off UAC lets it work but I will not do that. I don't know enough about the nitty-gritty of Vista privileges - and can't be bothered to learn!

I haven't tried on a device but I haven't found any similar reason why it would not work there so your WM 6.5 problem is a puzzle :confused:
 

derez

Expert
Licensed User
Longtime User
May be the problem is because of the variables types. You declare the variables first as int32 but afterwards you assign them as substrings, meaning that the parameters for setdate are strings instead of integers.
 

agraham

Expert
Licensed User
Longtime User
I don't think that will be the problem. Remember that regular untyped default variables are actually strings even if they are assigned numeric values. Basic4ppc will always try to convert the parameters to the proper type for the library and will throw an exception if this is not possible.

Array parameters are treated differently as Basic4ppc doesn't convert these so they must be declared to be the correct type.

EDIT :- Sorry I slightly missed the point but the same applies. Whan assiging between variables of different type Basic4ppc will try to convert them and throw an exception if it is not possible. In this case the sub-strings convert OK to integers so it works fine.
 
Last edited:
Top