Home

Macros and Programming

 

CardboxForumsMacros and Programming > "Adding 21 days to a date"

Adding 21 days to a date

How can I add 21 days to a date?

Current user: [none]
Register / Log In · Help

Posted By Post

14-Jun-2010 11:26

In the old version of cardbox it was easy to add 21 days to a date field as it was possible to upload the calculator and add 21 like this:

' date+21 days
*Calculator.Clear
           .Expression "date(21)"
           .Copy
*Text Paste

My problem is with cardbox3 there is no calculator so I was wondering whether it is possible to do this via the validator field or is there another trick?

bert

14-Jun-2010 13:08

Hi,
The calculator is now VBScript (and there is much more possible now!).
You can download free all VBScript commands on:

http://www.microsoft.com/downloads/details.aspx?FamilyID=01592c48-207d-4be1-8a76-1c4099d7bbb9&DisplayLang=en

You solution is this:
'place today + 21 days into current field when you are in edit mode
'all content of ActiveField is cleared

ActiveField = DateToCardbox(DateAdd("d",21, now),"04/07/1976")

Success
Bert

Nickc108

9-Oct-2010 07:56

This is useful for me too, Bert. What you have given adds 21 days to the today's date, but what do you put instead of "now" in order to add 21 days to the date in a field called "TS" for example?

bert

9-Oct-2010 08:54

Hi,

First is important how the format is of the date in Field TS.

I first would try:
DateToCardbox(DateAdd("d",21, DateFromCardbox(fields("TS")),"04/07/1976")

If this will not give you right results, please post the used date format.

regards
bert

Nickc108

9-Oct-2010 09:39

Tried this. Date format is same as yours. It required an extra right hand bracket at the end so I amended this. Then gave error message:
 Wrong number of arguments or invalid property assignment: 'DateAdd'

Here's the macro I'm using:

 GoToField "TS"
 DateToCardbox(DateAdd("d",21, DateFromCardbox(fields("SN")),"04/07/1976"))
 SaveRecord

"SN" is the field that has the date; I want field "TS" to show the result of date SN + 21.
Nick

bert

9-Oct-2010 10:55

if in SN your date is like dd/mm/yyyy

use

Fields("TS") = DateToCardbox(DateAdd("d", 21, DateFromCardbox(Fields("SN"))),"04/07/1976")
SaveRecord

I tested it, it works.

Perhaps your local date format of Windows can do unwished things, I did not test this all.
So check also dates like 10/06/2010 and 06/10/2010. If both give good results, than it's ok.

regards
bert

Nickc108

10-Oct-2010 09:35

Yes, it works well, Bert. Wonderful. Can you recommend any website or reading material that I can get stuck into for just VB code? I only need it for Cardbox macros. I got "VB Script" by O'Reilly, recommended by Cardbox, but it's ancient Greek to me. Never studied programming of any kind.

Mary Doyle

10-Oct-2010 12:34

Hi Nick,
When I was new to programming O'Reilly's book was ancient Greek to me as well (I presume you are referring to the one below). I think it may be very good if you are already a programmer, but as a novice I found the following books much more helpful:

Ford J.E. Jr. Learn Microsoft VBScript in a weekend. Premier Press,
2002. ISBN 1931841705. It is aimed at beginner to intermediate. While
it is not comprehensive it covers most of the essentials and gives
simple examples, which are relatively easy to follow, even though they
tend to be web based.

The next most useful book I found was
Microsoft Windows 2000 scripting guide. Washington: Microsoft Press,
2003. This is obviously much more comprehensive and also covers
VBScript is a logical sequence. I might have found this a good
starting point if I had come across it at an earlier stage.

I found Lomax's book intimidating for a beginner (Lomax P. Learning VBScript. Sebastobol: O'Reilly, 1997). It is too web design oriented and the examples are surrounded by so much HTML that it is offputting if you are just trying to get to the nitty gritty of the VBScript (I am thinking in terms of a Cardbox VBScript beginner). It doesn't get to 'Getting Started' until page 57. Dates in VBScript are not covered until page 306, with loads of HTML and ActiveX in intervening chapters.

Now of course you have the Cardbox Macros and Programming Manual which had not been written at the time I was experimenting with the beta version of Cardbox Version 3 and had to use the above books to help me with the VbScript. The Cardbox MP manual is obviously packed with Cardbox related examples and makes learning VbScript for Cardbox a lot easier. (See also my comments on Page 16 of an article I wrote on one of my uses of Cardbox http://www.cardbox.com/bin/uses/glint17p7-16.pdf). When you get familiar with VbScript you might find, like me, that you can use it for a lot more than Cardbox.

There are loads of other books I have delved into since and loads of helpful sites on the Web, but in my view, other than Lomax, the others I mention will give you a good starting point and overview of VbScript, both in general and specifically for Cardbox, and help you to know what to look for on the Web when you need to expand your knowledge or look for more examples.

Personally, when I don't know a program or programming language I like to keep browsing in a logical sequence through a manual or textbooks to get a feel for what the program or programming language is capable of. I don't take it all in to start with, but each time I browse I take in a bit more and see more potential applications. Obviously this is a very personal approach to learning, but I thought I would share it with you in case it is of help.

Regards,

Mary

Mary Doyle

10-Oct-2010 12:54

Re: Microsoft Windows 2000 scripting guide. Washington: Microsoft Press, 2003. You would only need Chapters 1 to 4 (VbScript Primer) http://technet.microsoft.com/en-us/library/ee198896.aspx. The rest of the book is more for network managers.

Mary

Charles Welling

10-Oct-2010 18:28

Have a look at www.w3schools.com, the site of the people that "make" HTML. Their site offers step-by-step and comprehensive instructions on many scripting languages, including VBscript. I always use this site as a reference. Ignore that this site is aimed at browser scripting. VBscript that you can use embedded in HTML is not different from the VBscript that you can use in Cardbox. And no ancient Greek, just plain English.

Mary Doyle

10-Oct-2010 19:19

Yes, I also find www.w3schools.com a great reference and even though aimed at browser scripting it is easy to follow.

bert

10-Oct-2010 20:01

My first steps of learning VB Script -years ago- was record (Cardbox or in Word/Excel) macros, then view and try to understand what was recorded. Then change some things, see what is does.

Also this was a great help:
http://www.microsoft.com/downloads/en/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en
A free Microsoft help file.
The help file of Cardbox also is good.

Greatest help for macros is always: Which result you wish? Seems logic, however...
Try to find out what to do for that goal.

The 21 days question is a good example for this. And you see: you found it.
If you analyze used terms (commands) in that line in mentioned help files, you can see how the things, written in those files, were applied.

regards
bert

Voices4Wellbeing

22-Aug-2011 15:09

Hi,

I am trying to use this macro in my own database.

Is there any way of getting it to work out 20 'working days' from a date. i.e. to only count Monday-Friday and disregard Saturday and Sunday.

bert

22-Aug-2011 19:16

Hi,

Google brought me to this example:

http://classicasp.aspfaq.com/date-time-routines-manipulation/how-do-i-count-the-number-of-business-days-between-two-dates.html

See code under"VB Script"

Did not test it, but it looked good.
regards
Bert

Quick Reply

Please log in or register before trying to post a reply.

 
© 2010 Cardbox Software Limited   Home