Hello. Well I am stuck into a problem. I have one VBscript script and Perl script which I need to convert in C#.NET. I am new into programming, not having much idea of how to do it? One traditional way is to write the same in C#. But I have little less time. is there any converter Or someone just suggest me how should I make it fast? Just suggest me from where I should start.
Thank you. Here is my VBscript Code.
Sample ASP Script
<%@ Language=VBScript %>
<%
'Get the parameters posted from the test'
testname=Request.form("TestName")
score=Request.form("Score")
user=Request.form("name")
numQuestions=Request.form("NumQuestions")
passingGrade=Request.form("PassingGrade")
'Validate that this is actually from a Lectora test'
if testname="" Or score="" Or user="" Or numQuestions="" Or passingGrade="" then
Response.Write "<html>"
Response.Write "<head><title>Failure</title></head>"
Response.Write "<body>"
Response.Write "STATUS=500"
Response.Write "<br>"
Response.Write "Could not parse test results due to a parameter error."
Response.Write "</body></html>"
else
'Write the results to a file named the same as the test'
'This could be a database or any kind of object store, but'
'to keep it simple, we will just use a flat text file'
fileName = "c:\" & testname & ".log"
'Open the results file for append'
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
if not objFSO.FileExists(fileName) then
objFSO.CreateTextFile(fileName)
end if
Set objInFile = objFSO.OpenTextFile( fileName, ForAppending, True )
'Write the results'
objInFile.WriteLine( Date & ", " & Time & ", " & user & ", " & score )
'Older courses produced by Lectora used a zero based index for the questions '
'(i.e. Question0 is the first question)'
'Newer courses are one based (i.e. Question1 is the first question)'
'determine which one it is'
Dim startIndex
valTemp = Request.form("Question0")
if( valTemp="" ) then
startIndex=1
else
startIndex=0
end if
'Write all of the questions and answers'
for i = startIndex to cint(startIndex + numQuestions-1)
nameQ = "Question" + CStr(i)
nameA = "Answer" + CStr(i)
valQ = Request.form(nameQ)
valA = Request.form(nameA)
objInFile.WriteLine( nameQ & ": " & valQ )
objInFile.WriteLine( nameA & ": " & valA )
Next
'Close results file'
objInFile.Close
Set objInFile = Nothing
Set objFSO = Nothing
end if
%>
Here is Perl script.
#!perl
use CGI;
$q = new CGI;
#get the parameters passed to the script
###################
$name = $q->param('name');
$testName = $q->param('TestName');
$numQuestions = $q->param('NumQuestions');
$passingGrade = $q->param('PassingGrade');
$score = $q->param('Score');
if( $testName eq "" || $numQuestions eq "" )
{
print "Content-type: text/html\n\n";
print "<html>";
print "<head><title>Failure</title></head>";
print "<body>";
print "STATUS=500";
print "<br>";
print "Could not parse test results due to a parameter error.";
print "</body></html>";
exit 0;
}
#####################
#get the current time
#####################
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
= localtime(time);
$year = $year + 1900;
$mon = $mon + 1;
$currtime = "$year-$mon-$mday $hour:$min:$sec";#####################
#opens test data file for append and write the data
##################### $testName .= ".log";
open( TESTDATA,">>c:\\$testName" ) or die;
print TESTDATA "$currtime $name $numQuestions $passingGrade $score\n";#####################
# Older courses produced by the program used a zero based index for the
questions (i.e. Question0 is the first question)' # Newer courses are one
based (i.e. Question1 is the first question)'
# determine which one it is'
#####################
$startindex = 0;
$temp = $q->param('
Question0'); if( $temp eq
"" )
{
$startindex = 1;
}
$index = $startindex;#####################
#Write out all of the questions and answers
#####################
while( $index < ($startindex + $numQuestions) ) {
$qst = "Question$index"; $ans = "Answer$index"; $qval = $q->param
( $qst ); $aval = $q->param( $ans );
print TESTDATA "$qst: $qval\n";
print TESTDATA "$ans: $aval\n";
$index += 1;
}close TESTDATA;
##################### #reply that it worked
#################### print $q->header();
print "STATUS=200\r\n";