XojoScript and Dates

I have a case where the end user is writing some XojoScript that then gets executed. Before the app executes the user’s script, it prepends DIM statements for some context variables that it pulls from a database, so the final XojoScript “source” property looks like this:

Dim foo as Integer = 42 // inserted from the database
Dim bar as Integer = 73 // ditto
[user-entered script statements that use foo and bar here]
. . .

This all works like a charm, but now I need to deal with dates. The LR says that dates (and objects in general) are not supported in XojoScript. Sigh.

I’ve thought about representing dates as strings in the XojoScript, and then writing a bunch of context functions that deal with them (by turning them into dates, doing whatever, and then back into strings for use in the script). But this seems like a messy hack.

So, any thoughts about the best way to deal with this? Thanks!

Write a function that uses Input () would be one way. Good to see a fellow Vermonter…I’m from Rutland originally. What platform are you using to develop with?

I think perhaps I haven’t phrased my question clearly. I’m not having any problems getting input from the user; I’m having a problem instantiating and using “forbidden” Date classes in the middle of some XojoScript source. Maybe I’ve misunderstood your suggestion, but I don’t see how input() would be any help here. Could you elaborate?

Also, sorry, but I’m only a transplanted Vermonter – I’m originally from Ohio (by way of New York, Australia, DC, Maryland, and Virginia). But I love it here, except when shoveling the roof :wink:

Are you using Mac/windows/or linux? I have something that is cross platform for you (once compiled)…but is platform specific during development time :slight_smile:

I’m using Mac and Windows. I dabble in Linux but only for server-side things.

Just for kicks…approximately what are you doing with the dates (just to throw a quick demonstration how it’s done)

That’s pretty much what you have to do. I don’t see it as that messy, though. If you’re getting the dates from the database it should be easy to ensure they come through as a certain string format (I prefer the SQL format of 2014-01-07 as it’s trivial to parse) and you just need a method to convert those.

If you’re dealing with random user input (where the user might put date fields in a strange order), that’s a much more difficult problem (even within a normal app).

If you want something more sophisticated, you can even define your own date object class within the Xojoscript – you just have to remember to convert it to something standard like a SQLDate string before passing it back and forth to/from the context object.

Almost done :slight_smile: