Recently chased back through here looking for a conversation on CMDLINE vs cCommandline and was impressed again by the suggestion Vincent made to allow arguments to be retrieved in any order by matching part of the argument. I've built this into a subclass of cCommandLine, but I see that there is a default cCommandline object already baked into cApplication.
Can I therefore suggest that a Function CommandLineArgumentValue or similar is baked into a future version of cCommandline as that surely has to be the most common way to do this
Dave,
To get a NextArgument working the cCommandLine class would need to keep track of the current or last retrieved argument. While that is doable I think it is better to work with the interface present. This is CountOfArgs and Argument N. You can look up a certain argument and when found retrieve the value of the next one. And subclassing in this case is not needed.
Code:
Use Windows.pkg
Use cHtmlHelp.pkg
Use cApplication.pkg
Use cConnection.pkg
Object oHtmlHelp is a cHtmlHelp
End_Object
Object oApplication is a cApplication
Object oConnection is a cConnection
Use LoginEncryption.pkg
Use DatabaseLoginDialog.dg
End_Object
Object oDavesCommandLine is a cCommandLine
Set phoCommandLine to Self
Function CommandLineArgumentValue String sKeyWord Returns String
Handle hoCommandLine
Integer iArguments iArgument
String sArgumentValue
Get phoCommandLine of ghoApplication to hoCommandLine
Get CountOfArgs of hoCommandLine to iArguments
For iArgument from 1 to iArguments
Get Argument of hoCommandLine iArgument to sArgumentValue
If (Uppercase (sArgumentValue) = Uppercase (sKeyWord)) Begin
Increment iArgument
If (iArgument <= iArguments) Begin
Get Argument of hoCommandLine iArgument to sArgumentValue
Function_Return sArgumentValue
End
End
Loop
Function_Return ""
End_Function
End_Object
End_Object
Procedure TestIt Global
Handle hoCommandLine
String sUserName sPassword
Get phoCommandLine of ghoApplication to hoCommandLine
Get CommandLineArgumentValue of hoCommandLine "UID" to sUserName
Get CommandLineArgumentValue of hoCommandLine "PWD" to sPassword
Send Info_box (SFormat ("UID: %1\nPWD: %2", sUserName, sPassword))
End_Procedure
Send TestIt
please? I'll be good...