Select to view content in your preferred language

Script for ArcPad Studio to enter current system time in textbox

925
2
06-10-2011 11:46 AM
PatrickMurphy
Frequent Contributor
I would love it if someone had some script code that I can use for the onsetfocus event for a text box that would enter the system time.  Currently the Date control only enters the date and not the current time.

What I want is for the system time in hours:minutes to be entered into the control when I tap it.  If I tap it a second time it would clear the control then enter the new time.

Thanks,
Pat
Tags (3)
0 Kudos
2 Replies
PatrickMurphy
Frequent Contributor
I would love it if someone had some script code that I can use for the onsetfocus event for a text box that would enter the system time.  Currently the Date control only enters the date and not the current time.

What I want is for the system time in hours:minutes to be entered into the control when I tap it.  If I tap it a second time it would clear the control then enter the new time.

Thanks,
Pat


RElated to this is a basic characteristic of the vb script implementation.  I assume when I am in ArcPad studio and I have a control that I want to trigger an event for, there is an event script box right below the event selection area.  Can I enter code directly here, or is this just supposed to reference and external .vbs file?  I though there was an indication in the instructions that I could enter code right here.
The field is called Time and the control name is nowtime

Here is some code that I have tried without success.
-
nowtime = FormatDateTime(Now(), DateFormat.Shorttime)
-
Time = FormatDateTime(Now(), DateFormat.Shorttime)
-
nowtime = FormatDateTime(Now(), 4)
-
Teststring = FormatDateTime(Now(), DateFormat.Shorttime)
nowtime = "teststring"
-

Typically I will either get no response when I tap the control, or an error that points to one of the lines and says "Source Text unavailable"
0 Kudos
PatrickMurphy
Frequent Contributor
Here is the code that worked.  I got this from another forum called Experts Exchange that I belong to.

The following code goes in the Script box associated with the gotfocus event.

Set objControl = ThisEvent.Object
Teststring = FormatDateTime(Now(), 4)
objControl.Value = teststring

The format options are:
' 0 = vbGeneralDate - mm/dd/yy hh:mm:ss PM/AM.
' 1 = vbLongDate - weekday, month name, year
' 2 = vbShortDate - mm/dd/yy
' 3 = vbLongTime - hh:mm:ss PM/AM
' 4 = vbShortTime - hh:mm
0 Kudos