0

Using this C# application pick a start and ending date range, that SAP will then use to do its query. I have made an application that passes one argument and it worked like that, but it does not work when doing two. Can anyone help?

C#

        private void button1_Click(object sender, EventArgs e)
        {
            String startDate = dateTimePicker1.Value.ToString("MM/dd/yyyy");
            String finishDate = dateTimePicker2.Value.ToString("MM/dd/yyyy");
            Process processbefore = new Process();
            processbefore.StartInfo.FileName = "C:\\Program Files\\SAP\\FrontEnd\\SAPgui\\saplogon.exe";
            processbefore.Start();
            processbefore.WaitForExit(1000 * 5 * 1);
            Process process = new Process();
            process.StartInfo.FileName = "C:\\Script2.vbs";
            process.StartInfo.Arguments = startDate;
            process.StartInfo.Arguments = finishDate;
            process.StartInfo.ErrorDialog = true;
            process.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
            process.Start();
            process.WaitForExit(1000 * 60 * 10);    // wait up to 5 minutes.
        }
    }
}

Script2.vbs - VBScript (Abbreviated)

startDate = WScript.Arguments.Item(0)
finishDate = WScript.Arguments.Item(1)

I get a subscript out of range for the finishDate = WScript.Arguments.Item(1)

Rest of code after that. I need to know how to add another Argument to pass to the VBScript. I am getting an error if I just add another of the same line.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
tluck234
  • 71
  • 1
  • 3
  • 10
  • Do we really need to see all that code? I suspect that you can reproduce the problem with six lines of code. Which line of code in your listing is failing, and what error message are you getting? – Robert Harvey Jun 19 '12 at 19:39

1 Answers1

0

Instead of:

process.StartInfo.Arguments = startDate;
process.StartInfo.Arguments = finishDate;

You want:

process.StartInfo.Arguments = startDate + " " + finishDate;

This is because arguments are space separated on Windows, and process.StartInfo.Arguments is a single string containing all the arguments.

Note: if one of the arguments has a space in it, you need to place quotes around it or it will be interpreted as multiple arguments. For example:

process.StartInfo.Arguments = "\"" + startDate + "\" \"" + finishDate "\"";
Kendall Frey
  • 43,130
  • 20
  • 110
  • 148