PopUp Calendar - NB Objects and NB function only

Questions and information about using VBScript and JavaScript in NeoBook functions

Moderator: Neosoft Support

Locked
User avatar
dpayer
Posts: 1394
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

PopUp Calendar - NB Objects and NB function only

Post by dpayer »

Pop Up calendar using NB Actions only

* * * * Major update * * * *
Localization of languages
Additional Calendar formatting options SMTWTFS & MTWTFSS
"Today" option highlites current day
* * * * * * * * * * * * * * * * *

The following is a project done to emulate a Sharepoint calendar used in webpages (so you will see the variable preface 'sp' alot) so I could do a training program using NB.

Sample Demo displays:
ImageImage]Image]Image

The calendar is composed of a group of NB objects which are then filled with the desired values (calendar display date, month, year, etc. and the value of the day, ie: date in proper format as a variable) by a function that is called.

The function has four parameters you must supply. Usage of the function is as follows:

CALL "CalSelectDate" "month" "groupname" "date format" "calendar format"

Month can either be "today" (no quotes) for the current month or in the format of M/YYYY (no leading zero for month).
GroupName is the name of the NB group that composes the form. I have used spCalGroup1 in my demo. You can have different names for your group or use multiple groups for multiple calendars. The group of NB objects is provided below.
Date Format uses the Neobook NumToDate formatting. See the NB helpfile for details.
Calendar Format is either "USA" (SMTWTFS) or "EURO" (MTWTFSS)

This version uses localization of names for days and months. It will display the right language based on how the computer is configured.

Methodology

The calendar is a grid of text objects 7 x 6 giving 42 objects. When a starting month is determined, the day of the first of that month is determined using DateToNum and then resolved to a day of the week using NumToDate. If month does not start on a Sunday, the previous month is determined and the trailing days of that month are inserted before the current month. Then the current month is generated and the following month values are generated and inserted after that.

The values of the display day and the variable containing the desired format of the date are populated using loops. This makes the generation of a month a bit slower than I would like but I think it is acceptable in a compiled app.NOTE: it is quite slow when tested inside the IDE.

This was my first time needing to localize by language. I grabbed sample days that I knew were Sun Mon Tues, etc and then took the first letter from the date for the header.

See the coding of the function for details. I have attempted to comment as I created this to make it easier for me to stay on track.

Display
The calendar can be used as is (see the code for the group object below) but you can change the color of the rectangle used for the background as needed. My demo color selector will give you a limited selection of choices but you should be able to figure out how to use the RGB codes for your purposes. The calendar is not currently designed to scale in size. You can display the calendar as a popup that closes when a day is clicked (this is built into the action for the text object)Image or you can insert the calendar on a page for permanent display and a new value for the variable will be created with each click of a day.

When clicked, the calendar will populate the [spDateClicked] variable with the formatted date. You determine the format of the date when calling the function. You can use any of the formatting options provided by the Neobook NumToDate Action (see NB help file for details). If you call the function using the month date as "today" it will highlite today on the calendar.

Image

I have a demo to show the capabilities of this function/form. If you don't want to install the function on your system, you can download the compiled version of the demo here.
If you would like to run this demo as an app in your NB install, download the function,
save it in your functions folder with the name: CalSelectDate (no extension name)

The entire demo pub file is here (requires function file to be installed to work)

The calendar form ONLY is here. You can open this in Notepad and then copy the contents to the clipboard and then paste into NB to create the calendar form.

Comments are welcome. If this is useful for you, this is provided as an open source project and is freely offered. If you do use it in your pub, please include a note to that effect in your acknowledgements.

Many thanks to Christian for testing out my multiple versions :)

David Payer
Last edited by dpayer on Tue Sep 17, 2013 12:02 pm, edited 3 times in total.
David Payer
Des Moines, Iowa
USA
Neosoft Support
NeoSoft Team
Posts: 5628
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA
Contact:

Re: PopUp Calendar - NB Objects and NB function only

Post by Neosoft Support »

Excellent work David!

Thank you for sharing this with us.
NeoSoft Support
Luiz Alfredo
Posts: 198
Joined: Thu Apr 19, 2007 6:58 am
Location: Brazil

Re: PopUp Calendar - NB Objects and NB function only

Post by Luiz Alfredo »

Very good work. Thanks.
L.A.G.M.
User avatar
Wrangler
Posts: 1531
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA
Contact:

Re: PopUp Calendar - NB Objects and NB function only

Post by Wrangler »

Thanks, David!
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
CN_Iceman
Posts: 300
Joined: Tue Mar 01, 2011 11:04 am
Location: España
Contact:

Re: PopUp Calendar - NB Objects and NB function only

Post by CN_Iceman »

Thank's David. Good work.
Greetings/Saludos, Jose.
www.icemansoft.es
User avatar
christian
Posts: 39
Joined: Sat Apr 02, 2005 9:25 am
Location: Germany
Contact:

Re: PopUp Calendar - NB Objects and NB function only

Post by christian »

Hello,
just tested the compiled exe-version. Looks fine, but I get the following error-messages, when starting:

spCalD0 This object does not exist
spCalD-1 This object does not exist
spCalD0 This object does not exist

When I click "today"
spCalD0 This object does not exist
spCalD-1 This object does not exist
spCalD0 This object does not exist

and so on...
What to do?
User avatar
dpayer
Posts: 1394
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: PopUp Calendar - NB Objects and NB function only

Post by dpayer »

christian wrote:Hello,
just tested the compiled exe-version. Looks fine, but I get the following error-messages, when starting:

spCalD0 This object does not exist
spCalD-1 This object does not exist
spCalD0 This object does not exist
What to do?
I will look into this when behind my work computer. I recall the spCalD0 error at times but I had done something to remove that, I thought.

Could you try downloading the function and the demo pub and see if you get the same error?

I just downloaded the compiled exe from the link on the forum page and executed it on my home computer and did not get the error.

I will post again tomorrow.

David P.
David Payer
Des Moines, Iowa
USA
User avatar
dec
Posts: 1663
Joined: Wed Nov 16, 2005 12:48 am
Location: Spain
Contact:

Re: PopUp Calendar - NB Objects and NB function only

Post by dec »

Hello,

It's not the same if you chose "Run (this page only)", "Run (from start)" or "Run (from this page)":

Image

For example, if you choose the "Run (this page only)" option but some actions are placed into the Book "Startup actions" this kind of problems can appear, because this last actions are not executed. So try if using "Run (from start)" solve the problem.
.
Enhance your NeoBook applications!
.
58 plugins, 1131 actions and 233 samples
.
NeoPlugins website: www.neoplugins.com
.
User avatar
christian
Posts: 39
Joined: Sat Apr 02, 2005 9:25 am
Location: Germany
Contact:

Re: PopUp Calendar - NB Objects and NB function only

Post by christian »

dpayer wrote:Could you try downloading the function and the demo pub and see if you get the same error?
I just downloaded the compiled exe from the link on the forum page and executed it on my home computer and did not get the error.
Hi,
loading the pub I get the following message by NB, may be, belongs to the other organisation of program-path in XP:
Page: New Page
C:\Program Files (x86)\NeoBook 5\Buttons\Resources\BrowserPrevBtn.png
C:\Program Files (x86)\NeoBook 5\Buttons\Resources\BrowserNextBtn.png


"Running from Start" causes the same error-messages as the EXE does, the debugger stops 3 times at the line
SetObjectFont "SpCalD{SPWILL}" "gray" "Arial" "10" "Italic" .......
Object does not exist
Hope that helps... :idea:

Another idea: To show the European date-format, it would bei nice to have dd.mm.yy and dd.mm.yyyy and ddd, dd.mm.yy. instead or in addition of "ddddd" :)
User avatar
dpayer
Posts: 1394
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: PopUp Calendar - NB Objects and NB function only

Post by dpayer »

christian wrote:Hi, loading the pub I get the following message by NB, may be, belongs to the other organisation of program-path in XP:
Page: New Page
C:\Program Files (x86)\NeoBook 5\Buttons\Resources\BrowserPrevBtn.png
C:\Program Files (x86)\NeoBook 5\Buttons\Resources\BrowserNextBtn.png
I just used a standard button in NB for this. You could select the group and change the properties of that button. Try using a standard button with the less than and greater than signs on them as a replacement. It appears your install of NB is in a different location and it can't find those NB standard button images.
"Running from Start" causes the same error-messages as the EXE does, the debugger stops 3 times at the line
SetObjectFont "SpCalD{SPWILL}" "gray" "Arial" "10" "Italic" .......
Object does not exist
Hope that helps... :idea:
I will have to look where this happens. I use that code for both the previous month and the following month and I did run into a situation where the loop counter somehow had a zero for its value. I will review the code. It works properly on my system.
Another idea: To show the European date-format, it would bei nice to have dd.mm.yy and dd.mm.yyyy and ddd, dd.mm.yy. instead or in addition of "ddddd" :)
You already can do that! When you call the function, put in the format you want using the NB NumToDate code of your preference. Read that section of the help file for details. I simply put a couple examples in my demo but you can add to it! Remember, the demo only demonstrates the use of the function and the form. The 'options' page on the demo is to show you how you can expand on the use of the function.

I did think about making it more Euro-friendly by having a week be M T W T F S S but I think that can wait until any other flaws are found. If you are interested, I can tell you how to do it. First, change the form so the column head is M T W T F S S and then look into the function code where it has:

Code: Select all

.determine day of week the selected month begins on
.Alertbox "test" "checking startday of selected month, recorded as: [spSelectedMonth]/1/[spSelectedYear]"
DateToNum "![spSelectedMonth]/1/[spSelectedYear]" "m/d/y" "[D2NResult]"
NumToDate "[D2NResult]" "ddd" "[NumtoDayResult]"

If "[NumtoDayResult]" "=" "Sun"
 SetVar "[spCalStartDay]" "1"
Endif
If "[NumtoDayResult]" "=" "Mon"
 SetVar "[spCalStartDay]" "2"
Endif
If "[NumtoDayResult]" "=" "Tue"
 SetVar "[spCalStartDay]" "3"
Endif
If "[NumtoDayResult]" "=" "Wed"
 SetVar "[spCalStartDay]" "4"
Endif
If "[NumtoDayResult]" "=" "Thu"
 SetVar "[spCalStartDay]" "5"
Endif
If "[NumtoDayResult]" "=" "Fri"
 SetVar "[spCalStartDay]" "6"
Endif
If "[NumtoDayResult]" "=" "Sat"
 SetVar "[spCalStartDay]" "7"
and make Mon=1, Tue=2, etc.

edit:
Upon reflection, I wonder if you may have copied the form more than once onto a page. If so, NB would rename the objects so they would not conflict with the other form (group).

Anyway - still looking into this. - End edit



Thanks for your feedback. I'll look for a solution to the issue you are facing.

David P.
David Payer
Des Moines, Iowa
USA
User avatar
christian
Posts: 39
Joined: Sat Apr 02, 2005 9:25 am
Location: Germany
Contact:

Re: PopUp Calendar - NB Objects and NB function only

Post by christian »

Hi, as you wrote per PM we try to solve the problem by PM.

Seems to be a problem with the array, all my monthly-calenders start with the "2." instead of the "1.", and when building it there ist shown a "33", replaced by the "2", when the 3 described errors are gone. There is a negative counter spWILL=-1, may cause the "wrong" object "spCallD-1" to fail...
User avatar
christian
Posts: 39
Joined: Sat Apr 02, 2005 9:25 am
Location: Germany
Contact:

German translation for the CAL

Post by christian »

... if you like, I can do the German translation later... (S M D M D F S) and all the other

Here comes the screenshot of the wrong calendar-dates, but clicking a date, the "day of the week" is OK!!!!
It's Friday, the 13.!!! (not Thursday) :)
Image
As you see, the translation of the selected date is mady by the OS already!

There is another bug, in the pulldownlist, choosing a month, the first character is gone!
Image

The color changer is not working correctly, using the min- and max-position, from RGB WHITE to BLACK.
Shown is RED, but SET brings the correct result BLACK!!!
Image
User avatar
christian
Posts: 39
Joined: Sat Apr 02, 2005 9:25 am
Location: Germany
Contact:

Re: PopUp Calendar - NB Objects and NB function only

Post by christian »

dpayer wrote:Upon reflection, I wonder if you may have copied the form more than once onto a page. If so, NB would rename the objects so they would not conflict with the other form (group).
No, I didn't, the behaviour is all the same by the PUB or you compiled version.
User avatar
dpayer
Posts: 1394
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: PopUp Calendar - NB Objects and NB function only

Post by dpayer »

Christian et al,

Well, I think you have introduced me to the issues associated with Internationalization! :)

Many of my variables set use the English names for months, days, etc. This may be a factor when I go to set a start day, if your language in Windows uses a different 3 letter abbreviation for the day's name I think my routines will not work the way I expected.

I will work on this a bit and get back to you with an updated version that should grab your local language.

I will post here when done.

Again thanks for your feedback.

For those in the USA, let me know if you are experiencing any issues.

David Payer
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
Posts: 1394
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: PopUp Calendar - NB Objects and NB function only

Post by dpayer »

dpayer wrote:Christian et al,

Well, I think you have introduced me to the issues associated with Internationalization! :)

I will post here when done.

David Payer

I have done a major update to the function / form. I have edited the initial post to provide details.
David P.
David Payer
Des Moines, Iowa
USA
Locked