public static Cmd Debug(ScriptControl scriptcontrol, bool stepMode = true) {
     if (stepMode){
         Logger.ConsoleOut.WriteLine("Debug mode: type n for the next execution.");
     } else {
         Logger.ConsoleOut.WriteLine("VisualBasic Script Host Console\nPreface with '?' for an evaluation.");
     }
     try {
         scriptcontrol.WScript.OnEcho += Logger.ConsoleOut.WriteLine;
         StringBuilder buffer = new StringBuilder();
         while (true) {
             Logger.ConsoleOut.Write('>');
             buffer.Length = 0;
             while (true) {
                 string line = Logger.ConsoleIn.ReadLine();
                 if (line == null)
                     break;
                 if (line.Equals("n"))
                     return Cmd.Next;
                 if (string.IsNullOrEmpty(line))
                     break;
                 buffer.AppendLine(line);
                 if ((Control.ModifierKeys & Keys.Shift) == 0)
                     break;
                 Logger.ConsoleOut.Write(' ');
             }
             if (buffer.Length != 0) {
                 string command = buffer.ToString().Trim();
                 if (command.StartsWith("?")) {
                     object result;
                     if (scriptcontrol.Eval(command.Substring(1), out result)) {
                         if(result is string){
                             string txt = "\"" + ((string)result).Replace("\"", "\"\"") + "\"";
                             Logger.ConsoleOut.WriteLine(txt);
                         } else {
                             Logger.ConsoleOut.WriteLine(string.Format("{0}", result));
                         }
                     } else {
                         Logger.ConsoleOut.WriteLine(scriptcontrol.Error.Message);
                     }
                 } else {
                     if (!scriptcontrol.Execute(command))
                         Logger.ConsoleOut.WriteLine(scriptcontrol.Error.Message);
                 }
             }
         }
     } finally {
         scriptcontrol.WScript.OnEcho -= Logger.ConsoleOut.WriteLine;
     }
 }
 public static Cmd Debug(ScriptControl scriptcontrol, bool stepMode = true)
 {
     if (stepMode)
     {
         Logger.ConsoleOut.WriteLine("Debug mode: type n for the next execution.");
     }
     else
     {
         Logger.ConsoleOut.WriteLine("VisualBasic Script Host Console\nPreface with '?' for an evaluation.");
     }
     try {
         scriptcontrol.WScript.OnEcho += Logger.ConsoleOut.WriteLine;
         StringBuilder buffer = new StringBuilder();
         while (true)
         {
             Logger.ConsoleOut.Write('>');
             buffer.Length = 0;
             while (true)
             {
                 string line = Logger.ConsoleIn.ReadLine();
                 if (line == null)
                 {
                     break;
                 }
                 if (line.Equals("n"))
                 {
                     return(Cmd.Next);
                 }
                 if (string.IsNullOrEmpty(line))
                 {
                     break;
                 }
                 buffer.AppendLine(line);
                 if ((Control.ModifierKeys & Keys.Shift) == 0)
                 {
                     break;
                 }
                 Logger.ConsoleOut.Write(' ');
             }
             if (buffer.Length != 0)
             {
                 string command = buffer.ToString().Trim();
                 if (command.StartsWith("?"))
                 {
                     object result;
                     if (scriptcontrol.Eval(command.Substring(1), out result))
                     {
                         if (result is string)
                         {
                             string txt = "\"" + ((string)result).Replace("\"", "\"\"") + "\"";
                             Logger.ConsoleOut.WriteLine(txt);
                         }
                         else
                         {
                             Logger.ConsoleOut.WriteLine(string.Format("{0}", result));
                         }
                     }
                     else
                     {
                         Logger.ConsoleOut.WriteLine(scriptcontrol.Error.Message);
                     }
                 }
                 else
                 {
                     if (!scriptcontrol.Execute(command))
                     {
                         Logger.ConsoleOut.WriteLine(scriptcontrol.Error.Message);
                     }
                 }
             }
         }
     } finally {
         scriptcontrol.WScript.OnEcho -= Logger.ConsoleOut.WriteLine;
     }
 }
        private ScriptProcedures ListProcedures(Script script, Regex pattern)
        {
            ScriptProcedures procedures = new ScriptProcedures();

            foreach (IMSScriptModule msc_module in _scriptcontrol.Modules)
            {
                ScriptModule module = new ScriptModule(msc_module);
                foreach (IMSScriptProcedure msc_procedure in msc_module.Procedures)
                {
                    var             proc_name = msc_procedure.Name;
                    ScriptProcedure procedure = new ScriptProcedure(module, proc_name);
                    switch (proc_name.ToLower())
                    {
                    case "initialize": procedures.ProcInitialize = procedure; break;

                    case "terminate": procedures.ProcTerminate = procedure; break;

                    case "setup": procedures.ProcSetup = procedure; break;

                    case "teardown": procedures.ProcTearDown = procedure; break;

                    case "onerror": procedures.ProcOnError = procedure; break;

                    case "iif": break;

                    default:
                        if (msc_procedure.HasReturnValue)
                        {
                            continue;
                        }
                        if (!pattern.IsMatch(proc_name))
                        {
                            continue;
                        }
                        WithParams proc_params_str;
                        if (script.ScriptWithParams.TryGetValue(proc_name, out proc_params_str))
                        {
                            if (!_scriptcontrol.Eval("Array(" + proc_params_str.Params + ')'))
                            {
                                var error = new ScriptError(script, procedure, "Invalide array: " + proc_params_str.Params);
                                error.AddTrace(script, proc_params_str.Line);
                                OnError(error);
                                continue;
                            }
                            var proc_params = (object[])_scriptcontrol.Result;
                            foreach (var proc_param in proc_params)
                            {
                                object[] args = CastToArray(proc_param);
                                if (args.Length == 0)
                                {
                                    var error = new ScriptError(script, procedure, string.Format(
                                                                    "Procedure {0} requires {1} argument(s). {2} provied.",
                                                                    proc_name, msc_procedure.NumArgs, args.Length));
                                    error.AddTrace(script, script.TextFormated.GetLineNumber("(Sub|Function).\b" + proc_name + "\b"));
                                    OnError(error);
                                    break;
                                }
                                procedure = new ScriptProcedure(module, proc_name, args);
                                procedures.Add(procedure);
                            }
                        }
                        else if (msc_procedure.NumArgs == 0)
                        {
                            procedures.Add(procedure);
                        }
                        break;
                    }
                }
            }
            return(procedures);
        }