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
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.basic4ppc.com/forum/addi...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

Paul Jennings

Member
Licensed 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.basic4ppc.com/forum/addi...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
 

Paul Jennings

Member
Licensed 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
 

Mahares

Well Known Member
Licensed 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.
 
Top