Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

User Image
Leon André Bergman
60 discussion posts
I am in the process of setting up macros that navigate between text boxes.
Most of them I can use the BFS.Clipboard.PasteText for, but I have 1 field that changes, and it's a date/time field.
So I decided to set up a pinned item in the #1 slot, with the date and time I want to use every time the macro is run.
So if the date changes, I just change the pinned item, not the macro.

I assumed I could use one of the BFS.ClipboardFusion statements to do this, but if I use BFS.ClipboardFusion.GetLocalPinnedText(1); my current clipboard item is not updated. When I try to paste, it just pastes what ever I had copied before I ran the macro.

How can I make this work?

Alternatively, is there a way where I can just get the date, and set it to say 4 days from now, and paste that?
Jan 16, 2019  • #1
Keith Lammers (BFS)'s profile on WallpaperFusion.com
To get the pinned text in the first slot you need to use index 0, and you have to call BFS.Clipboard.SetText, like so:

BFS.Clipboard.SetText(BFS.ClipboardFusion.GetLocalPinnedText(0));


You can get the date in a macro as well. What format do you need the date to be in?
Jan 16, 2019  • #2
User Image
Leon André Bergman
60 discussion posts
dd.mm.yy and if possible hh:mm:ss but not essential.
Jan 16, 2019  • #3
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Ok, try this out:

Code

using System;
using System.Collections.Generic;

public static class ClipboardFusionHelper
{
    public static string ProcessText(string text)
    {
        int daysToAdd = 4;
        DateTime currentDateTime = DateTime.Now;
        
        text = currentDateTime.AddDays(daysToAdd).ToString("dd.MM.yyyy hh.mm.ss");
        BFS.Clipboard.PasteText(text);
        return text;
    }
}
Jan 16, 2019  • #4
User Image
Leon André Bergman
60 discussion posts
Nice. This works. Thank you for your help.
Jan 17, 2019  • #5
Keith Lammers (BFS)'s profile on WallpaperFusion.com
No worries, glad we could help!
Jan 17, 2019  • #6
User Image
Leon André Bergman
60 discussion posts
Thanks again. This has been very helpfull. I want to make it skip weekends. Possibly holidays, I see some commands on stack overflow for AddBusinessDays, but that doesnt follow the syntax in use here. Is there a way to do it in the code you already made for me?
Mar 8, 2019  • #7
Keith Lammers (BFS)'s profile on WallpaperFusion.com
I'm not sure if this is the best way to do it, but it should work :)

Code

using System;
using System.Collections.Generic;

public static class ClipboardFusionHelper
{
    public static string ProcessText(string text)
    {
        // Set the days to add and get the current date/time
        int daysToAdd = 7;
        DateTime currentDateTime = DateTime.Now;
        
        // Set the potential new date/time
        DateTime newDate = currentDateTime.AddDays(daysToAdd);
        
        // Check if the new date is a Saturday or Sunday, if so, add some more days
        if (newDate.DayOfWeek == DayOfWeek.Saturday)
            newDate = newDate.AddDays(2);
        else if (newDate.DayOfWeek == DayOfWeek.Sunday)
            newDate = newDate.AddDays(1);
        
        // Convert the date/time to text
        text = newDate.ToString("dd.MM.yyyy hh.mm.ss");
        
        // Paste and return the text to the clipboard
        BFS.Clipboard.PasteText(text);
        return text;
    }
}
Mar 11, 2019  • #8
User Image
Leon André Bergman
60 discussion posts
Maybe not, but it looks like it should work for me. Thanks a bunch. :D
Mar 12, 2019  • #9
User Image
Leon André Bergman
60 discussion posts
Since it's friday, I've had a chance to try out your code, and I realized a limitation.
If I want to add 3 working days, it only adds 3 days, and sets monday, instead of seeing that its been a weekend, and adding another 2 days.
Mar 15, 2019  • #10
Thomas Malloch (BFS)'s profile on WallpaperFusion.com
I was able to put something together that should work for you. I've modified Keith's code a little to check for the weekend after each day, so the Macro should work if you run it on a weekend, or if the time you want to add spans for more than one week.

I hope this works for you!

Code

using System;
using System.Collections.Generic;

public static class ClipboardFusionHelper
{
    public static string ProcessText(string text)
    {
        // Set the days to add and get the current date/time
        int daysToAdd = 7;
        
        // Get the date
        DateTime date = DateTime.Now;
        
        // Fix the date in case it's a weekend
        if (date.DayOfWeek == DayOfWeek.Saturday)
            date = date.AddDays(2);
        else if (date.DayOfWeek == DayOfWeek.Sunday)
            date = date.AddDays(1);
        
        // Add the days one at a time, and check for a weekend after each time
        for(int i = 0; i < daysToAdd; i++)
        {
            // Add one day
            date = date.AddDays(1);
        
            // Check if the new date is a Saturday or Sunday, if so, add some more days
            if (date.DayOfWeek == DayOfWeek.Saturday)
                date = date.AddDays(2);
            else if (date.DayOfWeek == DayOfWeek.Sunday)
                date = date.AddDays(1);
        }
        
        // Convert the date/time to text
        text = date.ToString("dd.MM.yyyy hh.mm.ss");
        
        // Paste and return the text to the clipboard
        BFS.Clipboard.PasteText(text);
        return text;
    }
}
Sep 25, 2019 (modified Sep 25, 2019)  • #11
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(-)  Login to Vote(-)