|
-
Jul 29th, 2005, 09:51 AM
#1
Thread Starter
Lively Member
writing a simple scripting langauge
ok this may sound a trifle odd.
a project i'm currently working will be vastly more user friendly if for example a user can enter into a date box 'today' instead of a date. this has resulted ina little bit of a script language being written, *very* crude.
to date there are a handful of functions, eg a 'today' function that is converted to todays date etc. pretty simple stuff.
i have (essentially) two strings, one for input and one for output (eventually the output will be written to a file).
the string is examined via a basic tokeniser, all commands are wrapped in '{$' & '$}' e.g. {$today$}, plain text between the commans is treated as a single token no matter how long.
this bit works.
then there is a parsing function that actually reads it, does a bit of a lookup in a command array to execute commands, with the capacity to pass each one any paramters *and a code fragment* thus a 'command' can have a closing marker, indicating what bit of the string it should affect, with parameters to tell it *how*
thus we get
{$foreach parameters $} some text to play with{$next$}
which will result in the 'foreach' function being called with 'parameters' and being given thr text shown to play with.
this works
it even handles nested commands well enough for me.
the problem is coding some of the commands, specifically actually writing a 'for' and 'if' function. having got this far i'm wondering if theres anyone whos coded anything similar... either vba or plain old vb (i'm limited to vba here at the mo, but vb will be good for ideas).
basically it works as long as the string/script input requires no loops or flow control, both of which will be very useful.
btw. there are two aims for this, the first is writing SQL from a more friednly language (e.g. no requirement for the user to know about the data structures) the other is in creating html reports from templates.
reckon tis around 20% completed, well the core structure is, but until i've got conditionas & loops i'm not adding more commands yet.
any info?
-
Jul 29th, 2005, 07:30 PM
#2
Lively Member
Re: writing a simple scripting langauge
I am really not sure what all your project entails, but if you need a simple input box for a user to type in a date, and that automatically comes up with todays date as default, try this:
VB Code:
Option Explicit
Sub TestInputBox()
Dim szDate As String
Reval:
szDate = InputBox("Type in a date", "DateBox", Format(Now, "mm/dd/yy"))
If IsDate(szDate) Then
ActiveCell.Value = szDate
Else
MsgBox "Not a valid Date", 64
GoTo Reval
End If
End Sub
It only puts the date into the activecell on an Excel spreadsheet, but it may help get you started:
-
Aug 1st, 2005, 02:38 AM
#3
Thread Starter
Lively Member
Re: writing a simple scripting langauge
oh i've had that sort of thing working, its more for turning out a very simple report ala..
todays date is: {$today$}
yesterday was {$today-1$}
in effect both of these dates will fire into a query, but tis not just dates i'm doing this with.
the thing is driven via access and is an attempt at getting a reporting tool where pretty much anyone can sort it out.
e.g.
a report to drop out set and vehicle numbers with failure dates (this is for a rail defect system)
date {$failuredate$}, set {$set$}, vehicle {$vehicle$}
its reasonably likely that most of what is in effect a simple script will be thrown out by another program, but that this program will read it, process it, and produce the report.
having said that...
your code for getting input via a simple dialog into excel is *most* useful for another project so biiiig ta for that one :-)
-
Aug 1st, 2005, 10:53 AM
#4
Fanatic Member
Re: writing a simple scripting langauge
Hmmm I'm not sure what your actual question was originally but with what your doing I think I know of one function that could prove usefull to you.
CallByName(object, procedurename, calltype,[arguments()])
You could create a form (that would never be seen by the user) and use
CallByName(FrmName, "today", vbLet)
for example to call
Function today()
today = Date()
End Function
Its been a while since I used it but if you played with it and mastered it, would knock out a lot of the information you have to store and make it easier to just add whatever functions you want.
-
Aug 2nd, 2005, 02:00 AM
#5
Thread Starter
Lively Member
Re: writing a simple scripting langauge
yup! got 'callbyname' working away.. i've actually created a class, and put the parser, tokeniser etc in there. dropping the actual 'command' functiones in there got round the 'you can't call functions in modues' bit since they now have a parent object. tis then just a amatter of defining standard arguments for the functions. which wasn't that hard.
essentially the thing works, in a simple way. I'm just currently trying to add a 'for' loop and an 'if' statement. the whole thing being basically re-entrant. (i.e.) various functions call the parser again on substrings etc.
i'm trying a similar project in vb.net to this access vba based one. (i have access but not vb.net here, and vb.net but not access at home). its a bit of head scratching but i'm getting there.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|