<del id="d4fwx"><form id="d4fwx"></form></del>
      <del id="d4fwx"><form id="d4fwx"></form></del><del id="d4fwx"><form id="d4fwx"></form></del>

            <code id="d4fwx"><abbr id="d4fwx"></abbr></code>
          • vb.net腳本 vbnet web編程

            VB.NET可以編寫VBS腳本嗎

            ”VBS腳本“可以用任何純

            創(chuàng)新互聯(lián)建站專業(yè)為企業(yè)提供恒山網(wǎng)站建設(shè)、恒山做網(wǎng)站、恒山網(wǎng)站設(shè)計、恒山網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、恒山企業(yè)網(wǎng)站模板建站服務(wù),十年恒山做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。

            文本編輯

            工具編寫,包括系統(tǒng)自帶的”記事本“。VB.NET當(dāng)然也可以。

            如果你是需要語法提示之類的,VB.NET可以提供絕大部分的語法提示。畢竟

            VBS

            VB

            的子集。

            unity3D可以用VB.NET來寫游戲腳本嗎?

            u3d支持c#和js兩種腳本,而且c#是最普遍的,咱們看unity用的編譯器,是c#的跨平臺開源編譯器mono,而且是unity更改過得mono,這個編譯器是基于c#.net2.0的語法的,但是由于unity的更改,使得它也支持了一些.net3.5的語法,比如匿名函數(shù)lambda表.

            vb.net是腳本語言嗎?

            非也,乃微軟新一代面向?qū)ο罂梢暬幊陶Z言。另外,vb.net和vb6.0及以前版本都有很大差別。屬.net平臺。.net framework現(xiàn)在最新的版本是3.5,建議你學(xué)習(xí)2.0版本即可,有機(jī)會再看看3.5。

            如何在.NET中實現(xiàn)腳本引擎

            NET本身提供了強(qiáng)大的腳本引擎,可以直接使用.NETCLR的任何編程語言作為腳本語言,如VB.NET、C#、JScript,J#等等。使用腳本引擎,我們可以動態(tài)生成任意表達(dá)式、或動態(tài)導(dǎo)入任意腳本文件,并在任意時候執(zhí)行。經(jīng)實踐發(fā)現(xiàn),我們可以使用至少兩種不同的方式在.NET中使用腳本引擎:VsaEngine和CodeDom。其實,CodeDom不能算是真正的腳本引擎,它實際上是編譯器。但是我們完全可以利用CodeDom來模擬腳本引擎。使用Emit方法也能達(dá)到動態(tài)生成可執(zhí)行代碼的目的,而且Emit生成的代碼不需要編譯,因此速度更快。但是Emit插入的實際上是匯編代碼,不能算是腳本語言。本文介紹如何以CodeDom方式來動態(tài)生成可執(zhí)行代碼。如何在.NET中實現(xiàn)腳本引擎(CodeDom篇)沐楓網(wǎng)志1.構(gòu)造一個編譯器設(shè)置編譯參數(shù)編譯參數(shù)需要在CompilerParameters設(shè)置:CompilerOptions用于設(shè)置編譯器命令行參數(shù)IncludeDebugInformation用于指示是否在內(nèi)存在生成AssemblyGenerateInMemory用于指示是否在內(nèi)存在生成AssemblyGenerateExecutable用于指示生成的Assembly類型是exe還是dllOutputAssembly用于指示生成的程序文件名(僅在GenerateInMemory為false的情況)ReferencedAssemblies用于添加引用Assembly例如:theParameters.ReferencedAssemblies.Add("System.dll");創(chuàng)建指定語言的編譯器編譯需要由指定語言的CodeDomProvider生成。這里列舉一些.NET的CodeDomProvider:vb.netMicrosoft.VisualBasic.VBCodeProviderC#Microsoft.CSharp.CSharpCodeProviderjscriptMicrosoft.JScript.JScriptCodeProviderJ#Microsoft.VJSharp.VJSharpCodeProvider以C#為例,要創(chuàng)建C#編譯器,代碼如下://.NET1.1/1.0ICodeCompilercompiler=newMicrosoft.CSharp.CSharpCodeProvider().CreateCompiler();//.NET2.0ICodeCompilercompiler=(ICodeCompiler)newMicrosoft.CSharp.CSharpCodeProvider();下面是完整的創(chuàng)建編譯器的例子://////創(chuàng)建相應(yīng)腳本語言的編譯器///privatevoidcreateCompiler(stringstrLanguage,booldebugMode,stringstrAssemblyFileName){this.theParameters=newCompilerParameters();this.theParameters.OutputAssembly=System.IO.Path.Combine(System.IO.Path.GetTempPath(),strAssemblyFileName+".dll");this.theParameters.GenerateExecutable=false;this.theParameters.GenerateInMemory=true;if(debugMode){this.theParameters.IncludeDebugInformation=true;this.theParameters.CompilerOptions+="/define:TRACE=1/define:DEBUG=1";}else{this.theParameters.IncludeDebugInformation=false;this.theParameters.CompilerOptions+="/define:TRACE=1";}AddReference("System.dll");AddReference("System.Data.dll");AddReference("System.Xml.dll");strLanguage=strLanguage.ToLower();CodeDomProvidertheProvider;if("visualbasic"==strLanguage||"vb"==strLanguage){theProvider=newMicrosoft.VisualBasic.VBCodeProvider();if(debugMode)theParameters.CompilerOptions+="/debug:full/optimize-/optionexplicit+/optionstrict+/optioncompare:text/imports:Microsoft.VisualBasic,System,System.Collections,System.Diagnostics";elsetheParameters.CompilerOptions+="/optimize/optionexplicit+/optionstrict+/optioncompare:text/imports:Microsoft.VisualBasic,System,System.Collections,System.Diagnostics";AddReference("Microsoft.VisualBasic.dll");}elseif("jscript"==strLanguage||"js"==strLanguage){theProvider=newMicrosoft.JScript.JScriptCodeProvider();AddReference("Microsoft.JScript.dll");}elseif("csharp"==strLanguage||"cs"==strLanguage||"c#"==strLanguage){theProvider=newMicrosoft.CSharp.CSharpCodeProvider();if(!debugMode)theParameters.CompilerOptions+="/optimize";}//elseif("jsharp"==strLanguage||"vj"==strLanguage||"j#"==strLanguage)//{//theProvider=newMicrosoft.VJSharp.VJSharpCodeProvider();//if(!debugMode)//theParameters.CompilerOptions+="/optimize";//}elsethrownewSystem.Exception("指定的腳本語言不被支持。");this.theCompiler=theProvider.CreateCompiler();}//////添加引用對象。//////引用的文件名publicvoidAddReference(string__strAssemblyName){theParameters.ReferencedAssemblies.Add(__strAssemblyName);}注:在.NETFramework2.0中,由于CreateCompiler方法被標(biāo)記作廢。為避免產(chǎn)生編譯警告,可直接返回CodeDomProvider作為編譯器:this.theCompiler=(ICodeCompiler)theProvider;2.編譯源代碼編譯源代碼相當(dāng)簡單,只需一條語句就搞定了:CompilerResultscompilerResults=compiler.CompileAssemblyFromSource(this.theParameters,this.SourceText);執(zhí)行后,可以從compilerResults取得以下內(nèi)容:NativeCompilerReturnValue編譯結(jié)果,用于檢查是否成功Errors編譯時產(chǎn)生的錯誤和警告信息CompiledAssembly如果編譯成功,則返回編譯生成的Assembly示例函數(shù)://////編譯腳本。編譯前將清空以前的編譯信息。///CompilerInfo將包含編譯時產(chǎn)生的錯誤信息。//////成功時返回True。不成功為False。publicboolCompile(){this.theCompilerInfo="";this.isCompiled=false;this.theCompiledAssembly=null;this.theCompilerResults=this.theCompiler.CompileAssemblyFromSource(this.theParameters,this.SourceText);if(this.theCompilerResults.NativeCompilerReturnValue==0){this.isCompiled=true;this.theCompiledAssembly=this.theCompilerResults.CompiledAssembly;}System.Text.StringBuildercompilerInfo=newSystem.Text.StringBuilder();foreach(CompilerErrorerrinthis.theCompilerResults.Errors){compilerInfo.Append(err.ToString());compilerInfo.Append("/r/n");}theCompilerInfo=compilerInfo.ToString();returnisCompiled;}3.執(zhí)行代碼使用Reflection機(jī)制就可以很方便的執(zhí)行Assembly中的代碼。我們假設(shè)編譯時使用的腳本代碼this.SourceText內(nèi)容如下:namespacetest{publicclassscript{staticpublicvoidMain(){MessageBox.Show("Hello");}}}則相應(yīng)的執(zhí)行代碼為:scriptEngine.Invoke("test.script","Main",null);Invoke函數(shù)內(nèi)容://////執(zhí)行指定的腳本函數(shù)(Method)。///如果指定的類或模塊名,以及函數(shù)(Method)、或參數(shù)不正確,將會產(chǎn)生VsaException/VshException例外。//////類或模塊名///要執(zhí)行的函數(shù)(Method)名字///參數(shù)(數(shù)組)///返回執(zhí)行的結(jié)果publicobjectInvoke(string__strModule,string__strMethod,object[]__Arguments){if(!this.IsCompiled||this.theCompiledAssembly==null)thrownewSystem.Exception("腳本還沒有成功編譯");Type__ModuleType=this.theCompiledAssembly.GetType(__strModule);if(null==__ModuleType)thrownewSystem.Exception(string.Format("指定的類或模塊({0})未定義。",__strModule));MethodInfo__MethodInfo=__ModuleType.GetMethod(__strMethod);if(null==__MethodInfo)thrownewSystem.Exception(string.Format("指定的方法({0}::{1})未定義。",__strModule,__strMethod));try{return__MethodInfo.Invoke(null,__Arguments);}catch(TargetParameterCountException){thrownewSystem.Exception(string.Format("指定的方法({0}:{1})參數(shù)錯誤。",__strModule,__strMethod));}catch(System.Exceptione){System.Diagnostics.Trace.WriteLine(string.Format("執(zhí)行({0}:{1})錯誤:{2}",__strModule,__strMethod,e.ToString()));returnnull;}}總結(jié):CodeDom可以很方便的隨時編譯源代碼,并動態(tài)執(zhí)行。雖然作為腳本引擎,它沒有VsaEngine正規(guī)和方便,但作為一般應(yīng)用,也夠用了。并且結(jié)合Reflection機(jī)制,它的功能比VsaEngine更強(qiáng)大:它可以編譯任何提供CompilerProvider的CLR語言(目前.NET自帶的語言中都有)。當(dāng)然,它也有一些缺點:它生成的Assembly不能動態(tài)卸載。這在一般情況下不成問題,因為一個源代碼只需編譯一次,并載入執(zhí)行,并不需要動態(tài)卸載。假如你需要做腳本編輯器時,就要考慮這個問題,因為有可能一個腳本會因為修修改改而不停的重新編譯,從而造成不停的產(chǎn)生新的Assembly,最后將導(dǎo)致內(nèi)存被大量占用。要解決這個問題,需要將編譯器加載到獨立的AppDomain中,通過卸載AppDomain達(dá)到卸載所需的Assembly的目的。

            分享題目:vb.net腳本 vbnet web編程
            網(wǎng)頁地址:http://www.jbt999.com/article14/hppige.html

            成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、營銷型網(wǎng)站建設(shè)、網(wǎng)站收錄、網(wǎng)站內(nèi)鏈、軟件開發(fā)建站公司

            廣告

            聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:[email protected]。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

            h5響應(yīng)式網(wǎng)站建設(shè)

              <del id="d4fwx"><form id="d4fwx"></form></del>
              <del id="d4fwx"><form id="d4fwx"></form></del><del id="d4fwx"><form id="d4fwx"></form></del>

                    <code id="d4fwx"><abbr id="d4fwx"></abbr></code>
                  • 欧美黄色做爱视频 | 免费成人大片 | 欧美A区| 最新成人免费黄色视频 | 操屄一级片 |