Parsing Named Parameters?

P

(PeteCresswell)

I want to start passing more than one parm to MS Access on the
command line.

Right now, I'm only passing parm: a path to the local directory
where the front end lives - retrieving it simply via Command().

e.g.
START /B /HIGH /MAX "SFIM" MSACCESS.EXE "%AppPathLocal%"
/ini "%IniPath%" /wrkgrp "%SecPath%"
/Excl /Cmd %AppDirLocal%


myLocalDirectory = Command()



Now I guess I'll have to do something like

myCommandLine = Command()

and then parse out the named parms.

I know it's not rocket science, but it looks like a good 4 man
hours to get it working and thoroughly tested.... and it also
sounds like one of those bread-and-butter things that greater
minds than mine have already done many times.... and a lot
better.

Anybody know of a link?
 
T

Tom van Stiphout

On Sat, 09 Aug 2008 20:38:17 -0400, "(PeteCresswell)" <[email protected]>
wrote:

Do you have control over the format of the command line string? If
yes, I might suggest a querystring-like format:
param1=value1&param2=value2&param3=value3...

This is easy to parse using two Splits.
With any command line you have to worry about embedded separator
chars. It would be nice if you could avoid them.

-Tom.
Microsoft Access MVP
 
G

Graham Mandeno

Hi Pete

Here's some code I use that you might find useful:

============= start code =======================
Option Explicit

Private Const cParamDelimiter = ";"
Private Const cValueDelimiter = "="

Private colOptions As Collection

Private Sub LoadCommandOptions()
Dim a() As String, sCommand As String, i As Integer
Dim sKey As String, sValue As String, p As Integer
Set colOptions = New Collection
sCommand = Trim(Command)
If Len(sCommand) = 0 Then Exit Sub
a = Split(sCommand, cParamDelimiter)
For i = 0 To UBound(a)
sKey = Trim(a(i))
If Len(sKey) <> 0 Then
p = InStr(sKey, cValueDelimiter)
If p = 0 Then
sValue = ""
Else
sValue = Trim(Mid(sKey, p + 1))
sKey = Trim(Left(sKey, p - 1))
End If
colOptions.Add sValue, sKey
End If
Next
End Sub

Public Function GetCommandOption(Key As String) As Variant
If colOptions Is Nothing Then LoadCommandOptions
On Error Resume Next
GetCommandOption = colOptions(Key)
If Err Then
GetCommandOption = Null
Err.Clear
End If
End Function

Public Function CommandOptionPresent(Key As String) As Boolean
CommandOptionPresent = Not IsNull(GetCommandOption(Key))
End Function
============== end code ========================

Just change the constants at the top to match the delimiters you wish to
use.
 
P

(PeteCresswell)

Per Graham Mandeno:
Hi Pete

Here's some code I use that you might find useful:

Thanks Graham. That got me going.

Wound up parsing to an array of custom type ("NamedParm" which
has .Name and .Value) instead of a collection - and made it my
usual overly-verbose coding.... But it works....

Just a little shy of 1.5 man-hours....
 
A

a a r o n . k e m p f

SQL Server has a built in scheduler for runnning VB and SQL on a
scheduled basis.

It's called 'SQL Agent' and it's free with MSDE 1.0 or 2.0
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top