Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

EXCEL Macro to convert DATE format correctly for EVENT script file

Posted on 2007-07-29
4
Medium Priority
?
1,200 Views
Last Modified: 2008-01-09
In creating a javascript calendar, that works very well, I am trying to make it easier for my customer as a missing comma or quotation mark can cause an error resulting in a truncated or even missing calendar display.  To reduce the chance for such errors, I created a macro to convert the event data between the event script file format and the spreadsheet table display.

I have set up the spreadsheet to calculate the day of the week automatically from the date entered to help prevent entry errors. I have also use the conditional fomatting capability of Excel to alternate the background color on even and odd months and turn it red if a date is out of order to help with event entry.

THE PROBLEM IS THAT WHEN IT CONVERTS THE DATE into the events.js file, some dates are correctly entered as YYYYMMDD and others are shown as DD/MM/YYYY.

I can't work out where the problem is.
You can view the EXCEL FILE at http://www.worldsplayground.com/TESTCALENDAR/LayerCalendarTemplate.xls
You can view the *.BAS file at http://www.worldsplayground.com/TESTCALENDAR/LayerCalendarScript.bas
You can view the events script file at http://www.worldsplayground.com/TESTCALENDAR/events.js
0
Comment
Question by:Worldsplayground
  • 2
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
inthedark earned 2000 total points
ID: 19599284
I think this could be an OS config related issue.

As it will use the system settings to convert the date, which may not be as you expect.

Your example seemded to work fine on my machine, but I have revise the cal_cmd code as follows.

I would also suggest that you need some code like this

' for systems in the Europe

If DateValue("1/2/2007") <> DateSerial(2007,2,1) Then
    MsgBox "Your machine date settings incorrect there may be errors with some date conversions"
End If

' for systems in the USA

If DateValue("1/2/2007") <> DateSerial(2007,1,2) Then
    MsgBox "Your machine date settings incorrect there may be errors with some date conversions"
End If


Hope this helps :~)

Private Function cal_cmd(calEvent) As String

'Purpose: Convert event properties array into event command string
       
    ' convert date to yyyymmdd date code
    calEvent(0) = Format(calEvent(0), "yyyymmdd")
    ' set undefined image sizes to zero (29-Apr-2004: image size parameters now optional)
    'If Not IsNumeric(calEvent(6)) Then calEvent(6) = QUOTE & QUOTE
    'If Not IsNumeric(calEvent(7)) Then calEvent(7) = QUOTE & QUOTE
   
    cal_cmd = CMDBEG2 & calEvent(0) & DELIM
    For i = 1 To EVENTCOLUMNS - 1
        cal_cmd = cal_cmd & QuoteWord(calEvent(i)) & DELIM
    Next i
    cal_cmd = cal_cmd & QuoteWord(calEvent(EVENTCOLUMNS)) & CMDEND
   
End Function
0
 

Author Comment

by:Worldsplayground
ID: 19607234
Hi INTHEDARK,
My customer is located in Australia, could this have been the problem.
I will try your revised edition and send it to him to see if it works.

Cheers.
0
 
LVL 17

Expert Comment

by:inthedark
ID: 19607494
Don't forget to put the check bit into the script because in 10 yeras time when he gets a new PC, the guy that sets it up may forget to set the correct date settings for his region; it is so easy to get the default US settings.  Also he may be using other PCs in the same office, so the check is VITAL!!!!!!!!!!!!!!!!!
0
 

Author Comment

by:Worldsplayground
ID: 19661155
Thanks, add your suggested code and IF commands and they worked a charm.

Cheers,
Steve.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question