0

I am trying to build an easy to use command system (I am not going into detail on it). I have an array like this:

Array1 = Array(Array("help", "List all commands", Function()
             ' Code for help
         End Function,
         Array("write", "Write a note: /write <title> <description>", Function(p1, p2)
             ' Code for write
         End Function))
Array2 = Array("This is a title", "This is a description")

I want to call the first array's 3rd value like this: Array1(3)(Array2) without adding code to the command in Array1's function. Is this possible? If so please tell me how I can achieve this.

1
  • 1
    VBScript doesn't support anonymous functions, so what you describe in your question is not possible. There may still be ways to implement what you actually want the code to do in VBScript, though. You may get better answers if you described that instead of what you perceive as the solution. Also, There seems to be a closing parenthesis missing in the Array1 = ... statement. Commented Feb 4, 2017 at 10:54

1 Answer 1

2

No, it is not possible. This is not allowed by the VBScript syntax.

The nearer syntax to your approach you can use is

Function cmdHelp( arguments )
    WScript.Echo "HELP [" & arguments(0) & ":" & arguments(1) & "]"
End Function

Array1 = Array("help", "list all commands", GetRef("cmdHelp"))
Array2 = Array("first", "second")

Array1(2)( Array2 )

That is, place inside your array the reference to the code that will handle the action.

But note that in VBScript the subroutines and functions have a defined set of arguments. When you execute the call to the referenced procedure the number of arguments must match function/sub definition.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.