如何将vbscript和perl脚本转换为c#.net?

编程入门 行业动态 更新时间:2024-10-28 21:29:06
本文介绍了如何将vbscript和perl脚本转换为c#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好。好吧,我遇到了问题。我有一个VBscript脚本和Perl脚本,我需要在C#.NET中进行转换。我是编程的新手,不知道该怎么做?一种传统的方法是在C#中编写相同的方法。但我没有多少时间。有没有转换器或有人只是建议我应该如何快速?只是建议我从哪里开始。 谢谢。这是我的VBscript代码。

示例ASP脚本<%@ Language = VBScript%> <%'从测试中获取参数' testname = Request.form(TestName)得分= Request.form(得分) user = Request.form(name) numQuestions = Request.form(NumQuestions) passingGrade = Request.form(PassingGrade) 'Veridate这实际上来自Lectora测试'如果testname =或得分=或者用户=或者numQuestions =或者通过参数=那么 Response.Write< html> ; Response.Write< head>< title>失败< / title>< / head> Response.Write< body> Response.WriteSTATUS = 500 Response.Write< br> Response.Write由于参数错误,无法解析测试结果。 Response.Write< / body>< / html> else '将结果写入一个名为test''的文件。这可能是一个数据库或任何类型的对象存储,但是''来保存它很简单,我们只使用一个平面文本文件' fileName =c:\& testname& .log '打开结果文件追加' Const ForReading = 1,ForWriting = 2,ForAppending = 8 设置objFSO = CreateObject( Scripting.FileSystemObject) 如果不是objFSO.FileExists(fileName)那么 objFSO.CreateTextFile(fileName)结束如果 设置objInFile = objFSO .OpenTextFile(fileName,ForAppending,True) '写出结果' objInFile.WriteLine(Date&,& Time&,& user& ,&得分 'Lectora生成的旧课程使用零基础索引''(即问题0是第一个问题)''新课程是一个基础(即问题1是第一个问题)''确定它是' Dim startIndex valTemp = Request.form(Question0) if(valTemp) =)然后 startIndex = 1 else startIndex = 0 结束如果 '写下所有问题和答案'代表i = star tIndex 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)下一个 '关闭结果文件' objInFile.Close Set objInFile = Nothing 设置objFSO = Nothing 结束如果%>

这是Perl脚本。

#!perl 使用CGI; $ q =新的CGI; #get传递给脚本的参数 ################### $ name = $ q-> param('名称'); $ testName = $ q-> param('TestName'); $ numQuestions = $ q-> param('NumQuestions'); $ passingGrade = $ q-> param('PassingGrade'); $ score = $ q-> param('Score'); if($ testName eq|| $ numQuestions eq) { printContent-type:text / html\\\\ n; print< html>; print< head>< title> Failure< / title>< / head>; print< body>; 打印STATUS = 500; print< br>; print由于参数错误,无法解析测试结果。; print< / body>< / html>; 退出0; } ##################### #get当前时间 ####### ############## ($ sec,$ min,$ hour,$ mday,$ mon,$ year,$ wday,$ yday,$ isdst) =当地时间(时间); $ 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)或死亡; print TESTDATA$ currtime $ name $ numQuestions $ passingGrade $ score\\\; ##################### #旧课程由程序生成的问题使用零基指数(即问题0是第一个问题)'#较新的课程是一个基础(即问题1是第一个问题)' #define它是' ##################### $ startindex = 0; $ temp = $ q-> param(' Question0'); if($ temp eq ) { $ startindex = 1; } $ index = $ startindex; ##################### #写出所有问题和答案 ##################### while($ index<($ startindex + $ numQuestions)){ $ qst = 问题$指数; $ ans =回答$ index; $ qval = $ q-> param ($ qst); $ aval = $ q-> param($ ans); 打印TESTDATA$ qst:$ qval \ n; 打印TESTDATA$ ans:$ aval \ n; $指数+ = 1; }关闭TESTDATA; ##################### #reply它工作 ################ #### print $ q-> header(); 打印STATUS = 200 \\\\ n;

解决方案

q = new CGI; #get传递给脚本的参数 ###################

name = Q-> PARAM( '姓名');

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

解决方案

q = new CGI; #get the parameters passed to the script ###################

name =

q->param('name');

更多推荐

如何将vbscript和perl脚本转换为c#.net?

本文发布于:2023-10-07 15:56:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469834.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   如何将   脚本   perl   vbscript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!