Generate date + time and copy to clipboard?

Shohreh

Member
Hello

I know nothing about writing applications for Android: What is the simplest way to create an applet that will simply...

  1. generate the date and time as "[YYYY-MM-DD] ",
  2. copy this string the clipboard
  3. display an OK dialog just to confirm that it worked?

Since I know nothing about development on Android and Java, I'd like something that won't take me days to get up and running. Could I get this done in B4A within a day?

Thank you.
 

ukimiku

Active Member
Licensed User
Longtime User
It can be done with B4A within 10 minutes. I just sat down to try it (had never worked with the clipboard before). You need to install the clipboard library from here: http://www.b4x.com/forum/additional...updates/7382-clipboard-library.html#post42523

Installing means you copy the two files in the library zip file to your folder that holds your additional B4A libraries.

Then activate the library (tick its checkbox, after a right-click refresh onto the library pane) and add the following code to your app:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim ticks As Long
   Dim today As String
   Dim clipb As BClipboard
   
   DateTime.DateFormat = "yyyy-MM-dd"
   ticks = DateTime.Now
   today = "[" & DateTime.Date(ticks) & "] "
   
   clipb.setText(today)
   
   ToastMessageShow("Today's date in clipboard: " & today, True)
End Sub

Regards,
 
  • Like
Reactions: GvD
Upvote 0

Paul Jennings

Member
Licensed User
Longtime User
It can be done with B4A within 10 minutes. I just sat down to try it (had never worked with the clipboard before). You need to install the clipboard library from here: http://www.b4x.com/forum/additional...updates/7382-clipboard-library.html#post42523

Installing means you copy the two files in the library zip file to your folder that holds your additional B4A libraries.

Then activate the library (tick its checkbox, after a right-click refresh onto the library pane) and add the following code to your app:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim ticks As Long
   Dim today As String
   Dim clipb As BClipboard
  
   DateTime.DateFormat = "yyyy-MM-dd"
   ticks = DateTime.Now
   today = "[" & DateTime.Date(ticks) & "] "
  
   clipb.setText(today)
  
   ToastMessageShow("Today's date in clipboard: " & today, True)
End Sub

Regards,
Thankyou for the very fast reply. This code does work , however, what I get is the entire line "ToastMessageShow("Today's date in clipboard: " & today, True)" when I Paste it to my other app. Anyway to just put "today" on the clipboard ?
Thank you
 
Upvote 0

Paul Jennings

Member
Licensed User
Longtime User
Thankyou for the very fast reply. This code does work , however, what I get is the entire line "ToastMessageShow("Today's date in clipboard: " & today, True)" when I Paste it to my other app. Anyway to just put "today" on the clipboard ?
Thank you
Actually after running a few tests it does not put anything to the clipboard that will copy to an external app. What I thought was being copied was from the copy / paste I did on your reply.
pj
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
The code that @ukimiku gave you works very well and exactly how you requested it. If you want to display that in another B4A app, all you need to do after you ran it in your first app, you can have this code in your 2nd app:
B4X:
Dim clipb As BClipboard
ToastMessageShow("Today's date in clipboard obtained from 1st app is: " & clipb.getText, True)
If you want to use the content of the clipboard in you PC, you can save it to a text file like this:
B4X:
File.WriteString(File.DirRootExternal,"MyString",clipb.getText)
and then email it or send it with whatever means.
 
Upvote 0
Top