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.
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 "\"";