Hi I have a vbs script that works out a checksum, I need to use this checksum in a c# application.
I can echo the checksum using
WScript.Echo(LeftChar & RightChar)
To run this script for test in cmd prompt I am using :- cscript calcWaferIDChkSum1.3.vbs /wafer:178I102120
Where the script accepts the string argument to calculate its checksum
SMultiply=0
dim TMultiply, AMod, LBin, RBin, Bin, LeftChar, RightChar, Idx, CValue
MMod=0
Function DecimalToBinary(DecimalNum)
Dim strBinary, lngNumber1, lngNumber2, strDigit
strBinary = ""
intDecimal = cInt(DecimalNum)
While (intDecimal > 1)
lngNumber1 = intDecimal / 2
lngNumber2 = Fix(lngNumber1)
If (lngNumber1 > lngNumber2) Then
strDigit = "1"
Else
strDigit = "0"
End If
strBinary = strDigit & strBinary
intDecimal = Fix(intDecimal / 2)
Wend
strBinary = "1" & strBinary
DecimalToBinary = strBinary
End Function
Function BinaryToDecimal(Binary)
Dim n
Dim s
For s = 1 To Len(Binary)
n = n + (Mid(Binary, Len(Binary) - s + 1, 1) * (2 ^ (s - 1)))
Next
BinaryToDecimal = n
End Function
Function IsInvalidChar(IStr)
dim flag
flag = "F"
For j=1 To Len(IStr)
if Not(Asc(Mid(IStr,j,1))=45 OR Asc(Mid(IStr,j,1))=46 OR ( Asc(Mid(IStr,j,1)) >= 48 AND Asc(Mid(IStr,j,1)) <= 57 ) OR ( Asc(Mid(IStr,j,1)) >= 65 AND Asc(Mid(IStr,j,1)) <= 90 )) then
flag = "T"
exit for
end if
Next
IsInvalidChar = flag
End Function
Set colArgs = WScript.Arguments.Named
'inputStr = trim(UCase(InputBox("Enter Wafer ID")))
inputStr = colArgs.Item("wafer")
'While (IsInvalidChar(inputStr) = "T")
'inputStr = trim(UCase(InputBox("Invalid character, Enter Wafer ID:")))
'Wend
if len(inputStr) <> 0 then
PreValue = inputStr & "A0"
For i=1 To Len(PreValue)
CValue = Asc(Mid(PreValue,i,1)) - 32
Multiply = CValue * (8^(Len(PreValue)-i))
TMultiply = CCur(TMultiply + Multiply)
Next
AMod = TMultiply - (59 * Int(TMultiply / 59))
MMod = 59 - AMod
Bin = DecimalToBinary(MMod)
IF Len(Bin) <= 3 then
LBin = 0
RBin = Bin
Else
LBin = Mid(Bin,1,len(Bin)-3)
RBin = Right(Bin, 3)
End If
LeftChar = Chr(BinaryToDecimal(LBin)+ 65)
RightChar = BinaryToDecimal(RBin)
'output = "CMD /C echo " & inputStr & LeftChar & RightChar & "| CLIP"
'Set WshShell = CreateObject("WScript.Shell")
'WshShell.Run output, 0, true
'MsgBox("Press Ctrl + v or right click and paste to get result - " & inputStr & LeftChar & RightChar)
wafer = LeftChar & RightChar
WScript.Echo(LeftChar & RightChar)
end if
What I have tried:
In c# I tried this:
string scriptName = @"calcWaferIDChkSumV3.vbs";
var process = new Process();
ProcessStartInfo ps = new ProcessStartInfo();
ps.FileName = "cscript.exe";
ps.Arguments = string.Format("\"{0}\" \"{1}\" ", scriptName, "/wafer:178I1021010");
ps.UseShellExecute = false;
string answer = "";
ps.RedirectStandardOutput = true;
ps.UseShellExecute = false;
process.StartInfo = ps;
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
But How can I obtain the checksum and use it in other functions in c# ?