Adding 21 days to a date
How can I add 21 days to a date?
Macros and Programming
How can I add 21 days to a date?
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
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?
You solution is this:
ActiveField = DateToCardbox(DateAdd("d",21, now),"04/07/1976")
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?
First is important how the format is of the date in Field TS.
I first would try:
If this will not give you right results, please post the used date format.
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:
Here's the macro I'm using:
"SN" is the field that has the date; I want field "TS" to show the result of date SN + 21.
if in SN your date is like dd/mm/yyyy
Fields("TS") = DateToCardbox(DateAdd("d", 21, DateFromCardbox(Fields("SN"))),"04/07/1976")
I tested it, it works.
Perhaps your local date format of Windows can do unwished things, I did not test this all.
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.
Ford J.E. Jr. Learn Microsoft VBScript in a weekend. Premier Press,
The next most useful book I found was
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.
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.
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.
Yes, I also find www.w3schools.com a great reference and even though aimed at browser scripting it is easy to follow.
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:
Greatest help for macros is always: Which result you wish? Seems logic, however...
The 21 days question is a good example for this. And you see: you found it.
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.
Google brought me to this example:
See code under"VB Script"
Did not test it, but it looked good.
|© 2010 Cardbox Software Limited|